Cobbler安装配置简单使用

安装Cobbler

 1 [root@linux-node3 ~]# yum -y install epel-release 
 2 [root@linux-node3 ~]# yum -y install cobbler cobbler-web dhcp httpd xinetd pykickstart fence-agents    # 如果你的报错请用163源
 3 [root@linux-node3 ~]# chkconfig cobblerd on
 4 [root@linux-node3 ~]# chkconfig httpd on
 5 [root@linux-node3 ~]# chkconfig dhcpd on
 6 [root@linux-node3 ~]# chkconfig xinetd on
 7 [root@linux-node3 ~]# chkconfig rsyncd on
 8 [root@linux-node3 ~]# sed -i -e 's/\=\ yes/\=\ no/g' /etc/xinetd.d/tftp
 9 [root@linux-node3 ~]# openssl passwd -1 -salt "cobbler" "centos"    # centos为你之后所装所有机器的root密码,cobbler是对centos进行加密时用到的加密文(可以去看下salt加密相关),参数是数字1不是字母l
10 [root@linux-node3 ~]# cat/etc/cobbler/settings 11 next_server: 192.168.145.11 # 提供pxe的主机,你的本机ip 12 server: 192.168.145.11 # 提供cobbler的主机,还是你的本机ip 13 manage_dhcp:1 14 manage_rsync: 1 15 default_password_crypted: "$1$cobbler$DWL2fHTHaRTa2hj5VEuZk." # 刚才使用加密后得到的密文,注意最后有个. 16 pxe_just_once: 1 # 防止循环装系统,很重要! 17 18 [root@linux-node3 ~]# cat /etc/cobbler/dhcp.template # 更改第一段就好,其实就是dhcp的配置 20 subnet 192.168.56.0 netmask 255.255.255.0 { 21 option routers 192.168.56.2; 22 option domain-name-servers 8.8.8.8; 23 option subnet-mask 255.255.255.0; 24 range dynamic-bootp 192.168.56.100 192.168.56.254; 25 default-lease-time 21600; 26 max-lease-time 43200; 27 next-server $next_server; 28 class "pxeclients" { 29 match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; 30 if option pxe-system-type = 00:02 { 31 filename "ia64/elilo.efi"; 32 } else if option pxe-system-type = 00:06 { 33 filename "grub/grub-x86.efi"; 34 } else if option pxe-system-type = 00:07 { 35 filename "grub/grub-x86_64.efi"; 36 } else if option pxe-system-type = 00:09 { 37 filename "grub/grub-x86_64.efi"; 38 } else { 39 filename "pxelinux.0"; 40 } 41 } 42 43 } 44 45 [root@linux-node3 ~]# systemctl start xinetd 46 [root@linux-node3 ~]# systemctl start dhcpd 47 [root@linux-node3 ~]# systemctl start httpd 48 [root@linux-node3 ~]# systemctl start rsyncd 49 [root@linux-node3 ~]# systemctl start cobblerd 50 [root@linux-node3 ~]# cobbler get-loaders # 去git下载cobbler相关包,下载慢的话可以把dns换成114.114.114.114 51 [root@linux-node3 ~]# cobbler sync # 每次有修改过文件后都要执行哦 52 [root@linux-node3 ~]# cobbler check # cobbler自带的检测命令,出了问题就可以使用下,可以快速帮助你检测出问题的所在点,centos7会出debmirror错误,这是安装debian系统相关的,不会影响到使用 54 [root@linux-node3 ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler # 设置cobbler_web页面的访问密码 55 访问https://192.168.145.11/cobbler_web # 用户名为cobbler,密码刚才设置的,注意是https

56 [root@linux-node3 ~]# cat /etc/cobbler/pxe/pxedefault.template 57 DEFAULT menu 58 PROMPT 0 59 MENU TITLE Cobbler | http://www.cnblogs.com/bfmq/ 60 TIMEOUT 50 # 装系统时的等待时间,默认20秒 61 TOTALTIMEOUT 6000 62 ONTIMEOUT centos7.2-x86_64 # 这个需要改成你自己的cobbler profile list出现的,之后默认不选择系统引导后就会自动选择这个 63 64 LABEL local 65 MENU LABEL (local) 66 MENU DEFAULT 67 LOCALBOOT -1 68 $pxe_menu_items 69 70 MENU end

使用Cobbler

 1 [root@linux-node3 ~]# mount /dev/sr0 /mnt                # /dev/sr0是centos7.2的iso源镜像
 2 [root@linux-node3 ~]# cobbler import --path=/mnt/ --name=centos7.2        # 需要一些时间,导入的镜像会放在/var/www/cobbler/ks_mirror内,以name指定的为目录名
 3 [root@linux-node3 ~]# cd /var/lib/cobbler/kickstarts
 4 
 5 [root@linux-node3 ~]# cat centos7.2-x86_64.cfg        # 里面不可以有中文,so,不注释含义了,都很好理解
 6 # kickstart template for Fedora 8 and later.
 7 # (includes %end blocks)
 8 # do not use with earlier distros
 9 
10 #platform=x86, AMD64, or Intel EM64T
11 # System authorization information
12 auth --useshadow --enablemd5
13 # System bootloader configuration
14 bootloader --location=mbr
15 # Partition clearing information
16 clearpart --all --initlabel
17 # Use text mode install
18 text
19 # Firewall configuration
20 firewall --disabled
21 # Run the Setup Agent on first boot
22 firstboot --disable
23 # System keyboard
24 keyboard us
25 # System language
26 lang en_US
27 # Use network installation
28 url --url=$tree
29 # If any cobbler repo definitions were referenced in the kickstart profile, include them here.
30 $yum_repo_stanza
31 # Network information
32 $SNIPPET('network_config')
33 # Reboot after installation
34 reboot
35 
36 #Root password
37 rootpw --iscrypted $default_password_crypted
38 # SELinux configuration
39 selinux --disabled
40 # Do not configure the X Window System
41 skipx
42 # System timezone
43 timezone Asia/Shanghai
44 # Install OS instead of upgrade
45 install
46 # Clear the Master Boot Record
47 zerombr
48 # Allow anaconda to partition the system as needed
49 autopart
50 #clearpart --all --initlabel
51 #part / --fstype xfs --size 1 --grow --asprimary --onbiosdisk=8052 #part swap --maxsize=2048 --asprimary --size=2048 --onbiosdisk=8053 #part /boot --fstype=xfs --grow --asprimary --size=600 --onbiosdisk=80
54 
55 %packages
56 @^minimal
57 @base
58 @core
59 @development61 lftp
62 openssh-clients
63 tree
64 lrzsz
65 telnet
66 nc
67 sysstat
68 gcc
69 gcc-c++
70 %end
71 
72 %post
73 sed -i "s/#UseDNS yes/UseDNS no/g" /etc/ssh/sshd_config
74 echo 'export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "' >> /etc/bashrc
75 echo 'export HISTSIZE=9999' >> /etc/bashrc
76 IP=`ifconfig eth0|grep netmask|awk '{print $2}'`
77 HN=`echo $IP|awk -F. '{print $NF}'`
78 sed -i 's/dhcp/none/g' /etc/sysconfig/network-scripts/ifcfg-eth0
79 echo 'PREFIX=24' >> /etc/sysconfig/network-scripts/ifcfg-eth0
80 echo "IPADDR=$IP" >> /etc/sysconfig/network-scripts/ifcfg-eth0
81 echo 'GATEWAY=192.168.145.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
82 sed -i 's/nameserver *.*.*.*/nameserver 8.8.8.8/g' /etc/resolv.conf
83 systemctl restart network
84 %end
85 
86 %pre
87 $SNIPPET('log_ks_pre')
88 $SNIPPET('kickstart_start')
89 $SNIPPET('pre_install_network_config')
90 # Enable installation monitoring
91 $SNIPPET('pre_anamon')
92 %end
93 
94 [root@linux-node3 ~]# cobbler profile edit --name=centos7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.2-x86_64.cfg
95 [root@linux-node3 ~]# cobbler profile edit --name= centos7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0'        # 装6的系统不需要,这是统一网卡名称用的

96 [root@linux-node3 ~]# cobbler sync

然后你就可以直接开机等待系统自动安装了

 

posted @ 2017-07-05 10:51  北方姆Q  阅读(259)  评论(0编辑  收藏  举报