前幾天機房上架180台服務器,太多了,使用了cobbler批量安裝,具體的看我上代碼,我把配置cobbler的命令給堆積起來,也算是個腳本吧,歡迎拍磚指正,下面我上腳本:
1 #!/bin/bash 2 3 # 關閉selinux 4 setenforce 0 5 # 關閉firewalld防火牆 6 systemctl stop firewalld 7 # 下載阿里雲鏡像源 8 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 9 # 安裝cobbler 10 yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server -y 11 # 啟動httpd、cobblerd 12 systemctl start httpd 13 systemctl start cobblerd 14 # 檢查cobbler配置存在的問題,逐一解決 15 cobbler check 16 # 修改/etc/cobbler/settings文件中的server參數的值為提供cobbler服務的主機相應的IP地址或主機名,如server: 192.168.222.129 17 # 備份原文件 18 cp /etc/cobbler/settings{,.ori} 19 sed -i 's/server: 127.0.0.1/server: 192.168.222.129/' /etc/cobbler/settings 20 # 修改/etc/cobbler/settings文件中的next_server參數的值為提供PXE服務的主機相應的IP地址,如next_server: 192.168.222.129 21 sed -i 's/next_server: 127.0.0.1/next_server: 192.168.222.129/' /etc/cobbler/settings 22 23 # 修改/etc/xinetd.d/tftp文件中的disable參數修改為 disable = no 24 # 備份源文件 25 cp /etc/xinetd.d/tftp{,.ori} 26 sed -i 's/disable.*= yes/disable = no/g' /etc/xinetd.d/tftp 27 # 執行 cobbler get-loaders 命令即可;否則,需要安裝syslinux程序包,而后復制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中 28 cobbler get-loaders 29 # 修改rsync配置文件 30 sed -i s/"disable.*= yes"/"disable = no"/g /etc/xinetd.d/rsync 31 # 開啟rsync的服務開機自啟動 32 systemctl enable rsyncd 33 # 開啟rsync的服務 34 systemctl start rsyncd 35 # 生成密碼來取代默認的密碼,更安全 36 openssl passwd -1 -salt 'renjunjie' '123456' 37 sed -i s/'default_password_crypted:.*'/'default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP\/"'/g /etc/cobbler/settings 38 # 安裝cman fence-agents 39 yum install -y cman fence-agents 40 # 其他一些沒有提示報錯的小修改 41 sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings 42 sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings 43 systemctl restart cobblerd.service 44 cobbler check 45 # 配置dhcp 46 cat > /etc/dhcp/dhcpd.conf <<EOF 47 subnet 192.168.222.0 netmask 255.255.255.0 { 48 option domain-name-servers 223.5.5.5; 49 option routers 192.168.222.1; 50 range dynamic-bootp 192.168.222.100 192.168.222.250; 51 option subnet-mask 255.255.255.0; 52 next-server $next_server; 53 default-lease-time 43200; 54 max-lease-time 86400; 55 } 56 EOF 57 # 同步cobbler的配置,可以看到同步干了哪些事 58 cobbler sync 59 # 設置開機自啟動 60 systemctl enable dhcpd.service 61 systemctl enable rsyncd.service 62 systemctl enable tftp.service 63 systemctl enable httpd.service 64 systemctl enable cobblerd.service 65 66 systemctl restart dhcpd.service 67 systemctl restart rsyncd.service 68 systemctl restart tftp.service 69 systemctl restart httpd.service 70 systemctl restart cobblerd.service 71 72 # 掛在鏡像 73 mount /dev/cdrom /mnt 74 # 導入鏡像 75 cobbler import --path=/mnt/ --name=CentOS-7.0-x86_64 --arch=x86_64 76 # 查看鏡像列表 77 cobbler distro list 78 # 鏡像存放目錄,cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-6.6-x86_64目錄下。因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間 79 cd /var/www/cobbler/ks_mirror/ 80 # 配置ks.cfg(使用centos7的鏡像的時候,注意下方的ks.cfg要在安裝包那里刪除掉@server-policy,這玩意在7沒有的 81 cd /var/lib/cobbler/kickstarts/ 82 mkdir CentOS-7.0-x86_64.cfg 83 cat CentOS-7.0-x86_64.cfg <<EOF 84 # kickstart template for Fedora 8 and later. 85 # (includes %end blocks) 86 # do not use with earlier distros 87 88 #platform=x86, AMD64, or Intel EM64T 89 # System authorization information 90 #auth --useshadow --enablemd5 91 authconfig --enableshadow --passalgo=sha512 92 # System bootloader configuration 93 bootloader --location=mbr --driveorder=sda --append="nomodeset crashkernel=auto rhgb quiet" 94 # Partition clearing information 95 clearpart --all --initlabel 96 # Use text mode install 97 text 98 # Firewall configuration 99 firewall --disabled 100 # Run the Setup Agent on first boot 101 firstboot --disable 102 # System keyboard 103 keyboard us 104 # System language 105 lang en_US 106 # Use network installation 107 url --url=$tree 108 # If any cobbler repo definitions were referenced in the kickstart profile, include them here. 109 $yum_repo_stanza 110 # Network information 111 $SNIPPET('network_config') 112 # Reboot after installation 113 reboot 114 logging --level=info 115 116 #Root password 117 rootpw --iscrypted $default_password_crypted 118 # SELinux configuration 119 selinux --disabled 120 # Do not configure the X Window System 121 skipx 122 # System timezone 123 timezone Asia/Shanghai 124 # Install OS instead of upgrade 125 install 126 # Clear the Master Boot Record 127 zerombr 128 # Allow anaconda to partition the system as needed 129 #autopart 130 part /boot --fstype=ext4 --asprimary --size=200 131 part swap --asprimary --size=1024 132 part / --fstype=ext4 --grow --asprimary --size=200 133 134 %pre 135 $SNIPPET('log_ks_pre') 136 $SNIPPET('kickstart_start') 137 $SNIPPET('pre_install_network_config') 138 # Enable installation monitoring 139 $SNIPPET('pre_anamon') 140 %end 141 142 %packages 143 @base 144 @compat-libraries 145 @core 146 @debugging 147 @development 148 @dial-up 149 @hardware-monitoring 150 @performance 151 sgpio 152 device-mapper-persistent-data 153 systemtap-client 154 tree 155 lrzsz 156 telnet 157 nmap 158 dos2unix 159 %end 160 161 %post --nochroot 162 $SNIPPET('log_ks_post_nochroot') 163 %end 164 165 %post 166 $SNIPPET('log_ks_post') 167 # Start yum configuration 168 $yum_config_stanza 169 # End yum configuration 170 $SNIPPET('post_install_kernel_options') 171 $SNIPPET('post_install_network_config') 172 $SNIPPET('func_register_if_enabled') 173 $SNIPPET('download_config_files') 174 $SNIPPET('koan_environment') 175 $SNIPPET('redhat_register') 176 $SNIPPET('cobbler_register') 177 # Enable post-install boot notification 178 $SNIPPET('post_anamon') 179 # Start final steps 180 $SNIPPET('kickstart_done') 181 # End final steps 182 %end 183 EOF 184 # 編輯profile,修改關聯的ks文件 185 cobbler profile edit --name=CentOS-7.0-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.0-x86_64.cfg 186 187 # 同步下cobbler數據,每次修改完都要鏡像同步 188 cobbler sync 189 # 定制化安裝 190 cobbler system add --name=ren --mac=00:0C:29:2E:FD:0E --profile=CentOS-7.0-x86_64 --ip-address=192.168.222.120 --subnet=255.255.255.0 --gateway=192.168.222.1 --interface=eno16777736 --static=1 --hostname=linux_node --name-servers="223.5.5.5" 191 cobbler system list 192 cobbler sync
