Chinaunix首页 | 论坛 | 博客
  • 博客访问: 341762
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-27 14:21
个人简介

知道自己该干嘛,知道自己能干嘛

文章分类

全部博文(52)

文章存档

2019年(1)

2018年(8)

2017年(2)

2016年(11)

2015年(3)

2014年(10)

2013年(17)

我的朋友

分类: 系统运维

2014-02-11 17:50:52


                   紧接上文, 我们利用 cobbler 来安装操作系统. cobbler 有三个概念 distro profile system, 我先用我的理解讲述一下这三个概念的含义.
    
                   distro : 发行版, 就是我们安装什么版本的linux操作系统的名称 一会我们会导入一个 distro.
                   profile : 类似于一个 配置文件,类似于你的 bash_profile, 里面包含你可以添加 kernel 参数,对应的kickstart 文件 以及 此profile 对应的 distro 等等.
                   system : 就像是一个配置好安装信息的实例 , system 有对应的 profile , hostanme,dns-server,mac 地址 , 定制ip地址 等等,一会我们会配置一个 system并用于安装.

                   step 2 :  使用 cobbler 部署操作系统 
   
  1.                 mount -o loop /home/cailu/CentOS-6.4-x86_64-bin-DVD1.iso  /CentOS_6.4    // 挂载镜像
  2.                 cobbler import --path=/CentOS6.4 --name=CentOS6.4 --arch=x86_64    // 导入distro
  3.           
  4.                 使用 cobbler distro report 来查看刚才导入 distro
  5.                 [root@localhost ~]# cobbler distro report --name=CentOS6.4-x86_64
                    Name                           : CentOS6.4-x86_64
                    Architecture                   : x86_64
                    TFTP Boot Files                : {}
                    Breed                          : redhat
                    Comment                        : 
                    Fetchable Files                : {}
                    Initrd                         : /var/www/cobbler/ks_mirror/CentOS6.4-x86_64/images/pxeboot/initrd.img
                    Kernel                         : /var/www/cobbler/ks_mirror/CentOS6.4-x86_64/images/pxeboot/vmlinuz
                    Kernel Options                 : {}
                    Kernel Options (Post Install)  : {}
                    Kickstart Metadata             : {'tree': ''}
                    Management Classes             : []
                    OS Version                     : rhel6
                    Owners                         : ['admin']
                    Red Hat Management Key         : <>
                    Red Hat Management Server      : <>
                    Template Files                 : {}

                    cobbler profile add --name=centos6.4 --distro=CentOS6.4-x86_64 \
  6.                           --kickstart=/var/lib/cobbler/kickstarts/CentOS_6.4.ks 
  7.                 添加一个profile文件,并使用CentOS6.4-x86_64这个distro,并指定相应的ks文件,ks文件是事先准备好的.
                  
                 vim /etc/cobbler/pxe/pxedefault.template    // 编辑pxe模板
                 ONTIMEOUT centos6.4    // 修改默认安装的profile为centos6.4,也就是说当你没有选择,超时操作后自动安装此profile
  1.            
  2.                [root@localhost ~]# cobbler profile report --name=centos6.4
                   Name                           : centos6.4
                   TFTP Boot Files                : {}
                   Comment                        : 
                   DHCP Tag                       : default
                   Distribution                   : CentOS6.4-x86_64
                   Enable gPXE?                   : 0
                   Enable PXE Menu?               : 1
                   Fetchable Files                : {}
                   Kernel Options                 : {'biosdevname': '0'}
                   Kernel Options (Post Install)  : {}
                   Kickstart                      : /var/lib/cobbler/kickstarts/CentOS_6.4.ks
                   Kickstart Metadata             : {}
                   Management Classes             : []
                   Management Parameters          : <>
                   Name Servers                   : []
                   Name Servers Search Path       : []
                   Owners                         : ['admin']
                   Parent Profile                 : 
                   Proxy                          : 
                   Red Hat Management Key         : <>
                   Red Hat Management Server      : <>
                   Repos                          : []
                   Server Override                : <>
                   Template Files                 : {}
                   Virt Auto Boot                 : 1
                   Virt Bridge                    : xenbr0
                   Virt CPUs                      : 1
                   Virt Disk Driver Type          : raw
                   Virt File Size(GB)             : 5
                   Virt Path                      : 
                   Virt RAM (MB)                  : 512
                   Virt Type                      : xenpv
                
  3.                [root@localhost ~]# cat /var/lib/cobbler/kickstarts/CentOS_6.4.ks
                   install
                   auth --useshadow --enablemd5
                   key --skip
                   bootloader --location=mbr
                   text
                   firewall --disabled
                   keyboard us
                   lang en_US
                   url --url=$tree
                   reboot
                   rootpw --iscrypted $1$XPr0sv0o$1.XsUW0h36ZdWetQOefR21
                   selinux --disabled
                   timezone --isUtc Asia/Shanghai
                   $SNIPPET('disk-setup')    // 磁盘分区格式
                   %packages
                   $SNIPPET('package')    // 安装软件包或软件包组的名称
                   %post
                   $SNIPPET('log_ks_post')    // 记录安装过程中的日志输出
                   $SNIPPET('post_install_network_config')    // 配置网络参数
                   $SNIPPET('post_command')    // 安装一些我们经常使用的基础工具和salt-minion,epelrepo,以及防火墙,文件描述符,sshd等服务器的一些基本设置
                   $SNIPPET('post_adduser')    // 添加用户公钥
                   $SNIPPET('post_zabbix_install')    // 安装zabbix-agent客户端
  4.           
  5.                SNIPPET 我理解是一种 kickstart template 的编写的一种模板语言, 用于编写 kickstart template ,cobbler 本身就附带很多SNIPPET
  6.                SNIPPET 的路径在 /var/lib/cobbler/snippets , ks 文件中提到的SNIPPET 都会去这个路径下寻找.
  7.           
  8.                [root@localhost snippets]# pwd
                   /var/lib/cobbler/snippets
                   [root@localhost snippets]# cat disk-setup 
                   zerombr
                   clearpart --all --initlabel
                   part /boot --fstype ext4 --size=100 
                   part pv.01 --size=1 --grow 
                   volgroup VolGroup00 pv.01
                   logvol / --fstype ext4 --name=LogVol00 --vgname=VolGroup00 --size=10240
                   logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=2048 
             
  9.                [root@localhost snippets]# cat package 
                   @Base
                   @Core
                   @development
                   @emacs
                   @network-tools
                   @system-admin-tools
                   @system-management
                   gettext-devel
                   net-snmp
                   openssl-devel
                   python-devel
                   setuptool
                   sysstat
                   tcl
                   tcl-devel
                   tk
                   tk-devel
                   zlib-devel
  10.           
  11.                [root@localhost snippets]# cat post_command
  12.                echo "*/5 * * * * /usr/sbin/ntpdate cn.pool.ntp.org" >> /var/spool/cron/root    // 添加时钟同步的计划任务
  13.                echo "/usr/sbin/ntpdate cn.pool.ntp.org" >> /etc/rc.local    // 开机启动后就进行时钟同步,避免由于时间不同步导致的各种安全隐患
  14.                echo "*filter" >> /etc/sysconfig/iptables
  15.                echo "xxxx----xxx" >> /etc/sysconfig/iptables // 设置你定义的防火墙规则
  16.                echo "COMMIT" >> /etc/sysconfig/iptables
  17.                cat >> /etc/sysctl.conf <    // 更改一些常规的内核参数
                   net.ipv4.tcp_fin_timeout = 30
                   net.ipv4.tcp_keepalive_time = 1200
                   net.ipv4.tcp_syncookies = 0
                   net.ipv4.tcp_tw_reuse = 1
                   net.ipv4.tcp_tw_recycle = 1
                   net.ipv4.ip_local_port_range = 1024    65000
                   net.ipv4.tcp_max_syn_backlog = 8192
                   net.ipv4.tcp_max_tw_buckets = 5000
                   fs.file-max=655360
                   END
  18.                cat >>/etc/security/limits.conf <    // 加大用户使用fd数量
                   * soft nofile 655350
                   * hard nofile 655350
                   EOF

                   rpm -Uvh     // 安装epelrepo
                   yum install iotop iftop sysstat salt-minion -y    // 安装一些我们日常使用的常规工具
                   chkconfig --level 345 salt-minion on    // 设置服务开机启动
  19.                chkconfig --level 345 zabbix_agentd on    // ditto
                 
                 然后我们如何设置才能让服务器在dhcp分配的IP的能使用网络呢,通过网络才可以从epelrepo中安装我们需要的软件
                 之前我们在配置dhcp信息的时候,已经把192.168.137.123设置为dhcp服务器的网关,我们只需要在 iptables 做相应的设置就好
   
                 iptables -t nat -A POSTROUTING -s 192.168.137.0/24 -j MASQUERADE    // 添加SNAT设置
                 iptables -A INPUT -p tcp --dport 443 -j ACCEPT    //  开放cobbler所使用的端口
                 iptables -A INPUT -p tcp --dport 80 -j ACCEPT
                 iptables -A INPUT -p tcp --dport 25151 -j ACCEPT
                 iptables -A INPUT -p udp --dport 69 -j ACCEPT
                
                 vim /etc/sysctl.conf 
                 net.ipv4.ip_forward = 1    // 开启包转发功能

                 [root@localhost pxe]# cobbler check
                 The following are potential configuration items that you may want to fix:
                 1 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
                 Restart cobblerd and then run 'cobbler sync' to apply changes.     // 出现这个结果是正常的,我们已经在防火墙打开所需端口
              
                 [root@localhost pxe]# cobbler sync     // 查看一下是否有报错,有"*** TASK COMPLETE ***"即可

                 定制一个system,收集mac地址
                 cobbler system add --name=cobbler-one --mac=00:50:56:2E:B7:27 --ip-address=114.111.164.182 --subnet=255.255.255.0 --gateway=114.111.164.181 \
                                       --interface=eth0 --static=1 --profile=centos6.4 --hostname=cobbler-test --netboot-enabled=true --name-servers="202.106.0.20"
                 cobbler system edit --name=cobbler-one --mac=00:50:56:30:7C:78 --ip-address=172.16.23.100 --subnet=255.255.255.0 --interface=eth1 --static=1
                 cobbler sync    //刷新配置 
 
                 --name : system 实例的名称
                 --mac : 与实例对应的mac地址
                 --ip-address : 实例所使用的网络接口的ip地址
                 --subnet : 对应的网络掩码
                 --gateway : 网关地址
                 --interface : 网络接口的名称
                 --static=1 : 使用静态ip也就是我们之前设置ip地址
                 --hostname : 定义主机名
                 
--name-servers : 定义dns
                 --netboot-enabled=true :  cobbler 可以设置成一个新服务器的安装过后,第二次PXE启动的时候 能自动选择跳过(避免重复安装) \
                                                    但如果需要强制安装 ,就需要用到这个参数:--netboot-enabled=true

              开启服务器,自动会进入安装界面,然后自动安装我们预先设置的操作系统以及相关设置 
              经过5分钟后,服务器安装完毕我们来检查一下是否是我们预想配置的主机信息

             [root@cobbler-test ~]# ifconfig | grep -oP '(?<=inet addr:)(\d+.){3}.\d+'    // 可以看出ip地址配置正确,主机名配置正确
              114.111.164.182
              172.16.23.100
             
             [root@cobbler-test ~]# rpm -qa | grep -E '(iotop|iftop|salt-minion)'    // 相应的rpm软件安装完毕
              salt-minion-0.17.5-1.el6.noarch
              iftop-1.0-0.7.pre4.el6.x86_64
              iotop-0.3.2-7.el6.noarch

             [root@cobbler-test ~]# ll /usr/local/zabbix/sbin/zabbix_agentd    // zabbix-agentd 服务编译安装完毕,已开启服务,并自动注册到zabbix-server 
              -rwxr-xr-x. 1 zabbix zabbix 743600 Feb 18 02:27 /usr/local/zabbix/sbin/zabbix_agentd    // 关于如何自动注册zabbix-server,请参考我的 zabbix Auto registration文章
              [root@cobbler-test ~]# ll /etc/init.d/zabbix_agentd 
              -rwxr-xr-x. 1 root root 2177 Feb 18 02:27 /etc/init.d/zabbix_agentd
  
             [root@cobbler-test ~]# ping   // 网络连通性正常,说明我们的网络配置也 OK
              PING (61.135.169.105) 56(84) bytes of data.
              64 bytes from 61.135.169.105: icmp_seq=1 ttl=57 time=5.86 ms
              64 bytes from 61.135.169.105: icmp_seq=2 ttl=57 time=7.95 ms
              64 bytes from 61.135.169.105: icmp_seq=3 ttl=57 time=77.6 ms

             好,到此为止,我们使用cobbler的目的就达到了
             
             1 . 定制化安装系统,配置系统初期基本信息      [ok]
             2.  在dhcp环境下,自动安装我们经常使用的一些基本软件和小工具     [ok]
             3.  服务器第一次启动后,自动注册 zabbix-server,添加基础模板并开启监控      [ok]


             通过对软件的学习与使用,让我们的运维工作,更模块化,流程化,更清晰,透明



                                                                                                                                                            emar_Cail

             参考资料 : 
                             
                             

              
              

                
  1.           
 

                   
阅读(3912) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~