cobbler自动安装
基础环境:centos7.2
本地IP地址:192.168.56.12
网络环境:桥接模式
● 生产一个随机密码,这个用来作为新装机器的root登录密码
# openssl passwd -1 -salt 'salt' 'wurui321'
$1$salt$TorSa7kl86QCOPZX0FEjE1
注意: 需要复制这个到cobbler的setting里面
● 修改配置文件,有几个地方需要修改
# vim /etc/cobbler/settings
101gg切换到这行:上面随机生成的密码
101 default_password_crypted: "$1$salt$TorSa7kl86QCOPZX0FEjE1"
242gg :让cobbler来管理DHCP,默认是0关闭的
242 manage_dhcp: 1
272gg:设置TFTP地址
272 next_server: 192.168.56.12
384gg:设置cobbler地址
384 server: 192.168.56.12
● 修改DHCP分配IP文件
# vim /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
option routers 192.168.56.2;
option domain-name-servers 192.168.56.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.56.100 192.168.56.254;
● 修改/etc/xinetd.d/tftp将disable 改为no
# vim /etc/xinetd.d/tftp
disable = no
三、启动服务
● 启动cobbler服务
# systemctl start cobblerd.service
# systemctl enable cobblerd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
# systemctl status cobblerd.service
● 启动HTTP服务
# systemctl start httpd
# systemctl enable httpd
● 启动xinetd服务
# systemctl start xinetd
# systemctl enable xinetd
● 启动rsyncd服务
# systemctl start rsyncd
# systemctl enable rsyncd
● 从官网下载bootloader
cobbler get-loaders
● 检查是否都完成
# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
# cobbler sync
● 挂载CentOS7的系统镜像
[root@linux-node2 ~]# mount /dev/cdrom /mnt
● 导入镜像 >首先,查看帮助
# cobbler import -h
Usage: cobbler [options]
Options:
-h, --help show this help message and exit
--arch=ARCH OS architecture being imported 指定安装源是多少位
--breed=BREED the breed being imported
--os-version=OS_VERSION
the version being imported
--path=PATH local path or rsync location 镜像路径
--name=NAME name, ex 'RHEL-5' 为安装源定义一个名字
--available-as=AVAILABLE_AS
tree is here, don't mirror
--kickstart=KICKSTART_FILE
assign this kickstart file
--rsync-flags=RSYNC_FLAGS
pass additional flags to rsync
注意:安装源的唯一标识就是根据name参数来定义的。 我们来导入7的镜像。
# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
task started: 2016-05-28_163256_import
task started (id=Media import, time=Sat May 28 16:32:56 2016)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7-x86_64:
skipping import, as distro name already exists: CentOS-7-x86_64
No distros imported, bailing out
!!! TASK FAILED !!!
提示已经存在,这是正常的,因为存在就回报错,不信我们查看镜像.
#cobbler profile list
CentOS-7-x86_64
● 接着我们导入6的镜像,首先卸载,然后导入,查看
# umount /mnt
# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
cobbler import --path=/mnt/ --name=CentOS-6-x86_64 --arch=x86_64
# cobbler profile list
CentOS-6-x86_64
CentOS-7-x86_64
● 导入cfg文件 >进入cobbler的ks..cfg文件的存放位置
# cd /var/lib/cobbler/kickstarts/
上传cfg文件,6跟7的.(见附录1,2)
[root@linux-node2 kickstarts]# ll
total 60
-rw-r--r-- 1 root root 3704 May 28 11:59 CentOS-6-x86_64.cfg
-rw-r--r-- 1 root root 1355 May 28 11:58 CentOS-7-x86_64.cfg
# cobbler profile report
Name : CentOS-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
Name : CentOS-6-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-6-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
上面的2个kickstart是需要修改的,修改为我们上传的ks文件名,还有就是CentOS7的网卡信息也需要修改为eth0,操作如下:
# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
# cobbler profile edit --name=CentOS-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6-x86_64.cfg
# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
选择一个系统进行安装。
关于系统的重装问题(这里的操作在需要重新装机的服务器中进行操作)
第一:安装epel源
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
第二:安装软件
yum install koan -y
出现下面报错
# yum install koan -y
Loaded plugins: fastestmirror, security
Setting up Install Process
base | 3.7 kB 00:00
base/primary_db | 4.7 MB 00:07
epel/metalink | 5.4 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 4.1 MB 00:06
Error: xz compression not available
原因就是我系统是6的系统,安装了7的epel源,解决办法就是卸载这个7的epel源,然后重新安装6的epel源
# yum remove epel-release
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm
安装服务 故障依旧,原因就是缓存没有清除。
# rm -rf /var/cache/yum/x86_64/6/epel/
再次执行
yum install koan -y
查看cobbler端可用镜像
# koan -s 192.168.56.12 -l profiles
- looking for Cobbler at http://192.168.56.12:80/cobbler_api
CentOS-7-x86_64
CentOS-6-x86_64
重新安装为7的系统
koan -r -s 192.168.56.12 -p CentOS-7-x86_64
重启系统
reboot
使用cobbler同步openstack源
首先上地址:http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ 这个为openstack需要使用到的源,我们用cobbler来同步,这样创建的虚拟机默认就有了源,就不需要自己一个一个安装了。
执行下面操作:
#添加repo
cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum
#同步repo
cobbler reposync
时间有点长,耐心等待
#添加repo到CentOS7的profile文件
cobbler profile edit --name=CentOS-7-x86_64 --repos="openstack-mitaka"
#修改ks.cfg文件
在结尾添加,红色字体即可。
%post
systemctl disable postfix.service
$yum_config_stanza
%end
#加入到定时任务,每天同步
[root@linux-node2 kickstarts]# crontab -l
#add by jwurui321 at 2016-5-29
0 0 * * * /usr/bin/cobbler reposync
同步完镜像的文件在这里
[root@linux-node2 repo_mirror]# pwd
/var/www/cobbler/repo_mirror
[root@linux-node2 repo_mirror]# ls
openstack-mitaka
[root@linux-node2 repo_mirror]# du -sh
502M .
新开一台虚拟机,安装以后再次查看其源,如下所示: 有了源cobbler-config.repo,这样可以直接安装openstack了
[root@bogon yum.repos.d]# cd /etc/yum.repos.d/
[root@bogon yum.repos.d]# more cobbler-config.repo
[core-0]
name=core-0
baseurl=http://192.168.56.12/cobbler/ks_mirror/CentOS-7-x86_64
enabled=1
gpgcheck=0
priority=1
[openstack-mitaka]
name=openstack-mitaka
baseurl=http://192.168.56.12/cobbler/repo_mirror/openstack-mitaka
enabled=1
priority=99
gpgcheck=0
附录1:centos6.5的ks.cfg文件
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS6
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%post
%end
附录2:centos7.2的ks.cfg文件