1.Cobbler Install
安装前准备  /*注:Cobbler需安装在CentOS7机器上面,建议安装Cobbler机器的CentOS7 everything版本*/
关闭SELinux

cat /etc/redhat-release
setenforce 0
getenforce //得到的结果需要是:Permissive
如果不是,执行两步:
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
setenforce
reboot

关闭防火墙:

systemctl stop firewalld

开机不启用防火墙:

systemctl disable firewalld
安装wget
yum -y install wget
添加一个epel源:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd
启动:
systemctl start httpd
systemctl start cobblerd
设置cobbler和httpd为开机自启动:
systemctl enable httpd
systemctl enable cobblerd
查看cobblerd的启动状态:
netstat -lntup //查看已经启动的端口
检查:
cobbler check
对报错进行修复:
vim /etc/cobbler/settings
修改 【384行 server: 127.0.0.1为384 server: 本机的ip地址】【272行 next_server: 127.0.0.1为272 next_server: 本机的ip地址】

对应的修改命令为:

sed -i "s#server: 127.0.0.1#server: `ip addr|grep inet|grep brd|awk '{ print $2 }'|awk -F/ '{ print $1 }'`#g" /etc/cobbler/settings

 

2.编辑/etc/xinetd.d/tftp
vim /etc/xinetd.d/tftp
 
修改“    disable                 = yes"为"    disable                 = no" 用sed工具修改:
sed -i '14s/^.*$/    disable            = no/'  /etc/xinetd.d/tftp
 
3.执行一条命令:
cobbler get-loaders
4.启动rsyncd服务并添加为开机启动项:
systemctl start rsyncd.service
systemctl enable rsyncd.service
查看启动状态:
systemctl status rsyncd.service
systemctl restart xinetd
systemctl enable xinetd
5.设置密码:
openssl passwd - -salt 'cobbler' 'cobbler'
执行结果:$1$cobbler$M6SE55xZodWc9.vAKLJs6.
 
复制此结果到: /etc/cobbler/settings 中
 
 
vim /etc/cobbler/settings:
101行 替换
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
default_password_crypted: "$1$cobbler$M6SE55xZodWc9.vAKLJs6."
 
sed实现:
sed -i 's#default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."#default_password_crypted: "$1$cobbler$M6SE55xZodWc9.vAKLJs6."#g' /etc/cobbler/settings
安装其它两个模块:
yum -y install fence-agents debmirror
6.重启cobbler服务:
systemctl restart cobblerd
7.用cobbler sync同步一下
cobbler sync
 
 
 
 
再次执行:
cobbler check
 
vim /etc/debmirror.conf
 
修改@dists="sid";为#@dists="sid"; //*其实就是注释掉这一行
修改@arches="i386";为#@arches="i386";//*其实就是注释掉这一行
sed -i 's/@dists=\"sid\";/#@dists=\"sid\";/g' /etc/debmirror.conf
sed -i 's/@arches=\"i386\";/#@arches=\"i386\";/g' /etc/debmirror.conf

reboot

systemctl restart cobblerd

systemctl restart httpd

cobbler check
 
管理dhcp服务:
vim /etc/cobbler/settings
 
修改:242 manage_dhcp: 0为242manage_dhcp: 1
sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings
 
cobbler自带dhcp配置文件:
/etc/cobbler/modules.conf
 
查看dhcp的模板文件:
vim /etc/cobbler/dhcp.template
 
修改部分:
subnet 192.168.2.0 netmask 255.255.255.0 {

     option routers             192.168.2.1;

     option domain-name-servers 8.8.8.8;

     option subnet-mask         255.255.255.0;

     range dynamic-bootp        192.168.2.100 192.168.2.254;

     default-lease-time         ;

     max-lease-time             ;

     next-server                $next_server;
 
systemctl restart cobblerd
 
cobbler sync
到此为止:cobbler装完了也配置好了;
 
distro发行版:centos6/7
1.挂载CentOS7系统ISO光盘
mount /dev/cdrom /mnt/
 
2.import导入系统镜像
cobbler import --path=/mnt/ --name=CentOS--x86- --arch=x86_64
 
--path 镜像路径
--name 安装源定义名称
--arch 制动操作系统平台是32/64位
镜像存放目录,cobbler会将所有的安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirrors
 
cobbler profile edit --name=CentOS-7-64-x86_64 --kopts='net.ifnames=0 biosdevname=0'
 
vim /var/lib/cobbler/kickstarts/centos7-x86-.cfg
 
lang en_US
keyboard us
timezone Asia/Shanghai
rootpw --iscrypted $default_password_crypted
text
install
url --url=$tree
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype xfs --size --ondisk sda
part swap --size --ondisk sda
part / --fstype xfs --size --grow --ondisk sda
auth --useshadow --enablemd5
$SNIPPET('network_config')
reboot
firewall --disabled
selinux --disabled
skipx %pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%end %packages
@base
@core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
tree
nmap
screen
%end %post
systemctl disable postfix.service
%end
 
cobbler profile edit --name=CentOS---x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-x86-.cfg
cobbler profile report
 
挂上配置文件
cobbler profile edit --name=CentOS---x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-x86-.cfg
 
再挂载一块Centos6的ISO映像文件
先解除CentOS7的挂载:
umount /dev/cdrom
挂载Centos6镜像文件
mount /dev/cdrom /mnt/
 
import导入系统镜像
cobbler import --path=/mnt/ --name=CentOS--x86_64 --arch=x86_64

vim /var/lib/cobbler/kickstarts/centos6-x86_64.cfg
 
auth --useshadow --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
part /boot --fstype ext4 --size --ondisk sda
part swap --size --grow --ondisk sda
part / --fstype ext4 --size --grow --ondisk sda
text
firewall --disable
firstboot --disable
keyboard us
lang en_US
url --url=$tree
$yum_repo_stanza
$SNIPPET('network_config')
reboot
rootpw --iscrypted $default_password_crypted
selinux --disabled
skipx
timezone Asia/Shanghai
install zerombr
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%post
%end
 
先查看:
cobbler profile list
 查看到的结果

CentOS---x86_64
CentOS---x86_64

所以下面的--name=后面应该写入CentOS-6-64-x86_64

 
cobbler profile edit --name=CentOS---x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6-x86_64.cfg
systemctl restart dhcpd
systemctl enable dhcpd
添加epel源:
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache
Cobbler自定义重装
yum -y install koan
指定重装的系统[先在cobbler服务端用Cobbler profile list查看一下]
koan --server=192.168.2.13 --profile=CentOS---x86_64 --display
koan --server=192.168.2.13 --profile=CentOS---x86_64 --r //koan写入,只有写入后重启才会生效
 
Cobbler自定义仓库:
 
1.添加repo:
cobbler repo add --name=zabbix3. --mirror=https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/ --arch=x86_64 --breed=yum
cobbler repo add --name=openstack-n-centos7 --mirror=https://mirrors.aliyun.com/centos/7.5.1804/cloud/x86_64/openstack-ocata/ --arch=x86_64 --breed=yum
2.同步repo:
cobbler reposync
[删除repo源]
cobbler repo remove --name=zabbix3.
cobbler repo list


[更改repo名称]

cobbler repo rename --name=openstack-n --newname=openstack-n-centos7
3.添加repo到对应的profile:
cobbler profile edit --name=CentOS---x86_64 --repos=openstack-n-centos7
查看是否添加成功:
cobbler profile report --name=CentOS---x86_64
修改配置文件内容:
vim /var/lib/cobbler/kickstarts/centos7-x86-.cfg
在systemctl disable postfix.service和%end中间添加一条:
$yum_config_stanza
添加定时任务,定期同步repo:
echo "00 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root
或者
echo "00 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail >> /soft/scripts/log/cobbler_rsync.log">> /var/spool/cron/root
 
替换系统选择界面:
vim /etc/cobbler/pxe/pxedefault.template
修改第三行:
MENU TITLE Cobbler | http://cobbler.github.io/i[修改为你自己想要的内容]
 
 
同步一下:
cobbler sync
Cobbler自定义安装:
唯一身份标识符:身份证
服务器标识符:MAC地址
 
MAC地址标识符-->固定IP地址 掩码 网关 dns 主机名
 
 
查看系统里面的profile:

[root@localhost ~]# cobbler profile list
  CentOS-6-64-x86_64
  CentOS-7-64-x86_64
 
 
自定义安装命令:
cobbler system add --name=linux-node2.com --mac=:0C:::: --profile=CentOS---x86_64 --ip-address=192.168.2.110 --subnet=255.255.255.0 --gateway=192.168.2.1 --interface=eth0 --static= --hostname=linux-node2.com --name-servers="8.8.8.8"
同步:
cobbler sync
查看创建情况:
cobbler system report
05-02 16:26