cobbler无人值守安装centos
需求
公司进了一批服务器,需要重新安装操作系统,所以搞一下自动安装系统,并记录一下。
为啥不用Kickstart?因为安装麻烦!Cobbler可以说是Kickstart的升级版,它集中和简化了通过网络安装操作系统所需要的dhcp,tftp,dns等配置,Cobbler可以通过命令行界面操作,还提供web界面,并且还支持其它配置管理系统,比如puppet,暂时不支持saltstack。
环境准备
操作系统:centos7.5
Cobbler: 2.8.4
Cobbler IP: 10.10.1.13
开始安装
关闭防火墙和selinux,我这是在内部机器别人访问不到,如果机器有可能暴露到公网最好不要关闭防火墙
1
2
3
4sed -i 's/SELINUX=enforcing/SELINUX=disabled' /etc/selinux/config
setenforce 0
systemctl disable firewalld
systemctl stop firewalld安装cobbler相关的软件,并添加开机自启动
1
2
3yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
systemctl enable httpd cobblerd
systemctl start httpd cobblerd检查服务并修改相关的配置
1 | cobbler check |
3.1. 将上面检查出来的问题先解决
先备份在根据提示修改配置文件1
# cp /etc/cobbler/settings{,.bak}
根据提示1,2将127.0.0.1修改为cobbler服务器的ip1
2 sed -i 's/server: 127.0.0.1/server: 10.10.1.13/g' /etc/cobbler/settings
sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.7/' /etc/cobbler/settings
根据提示3修改tftp配置,把yes改为no ,重启服务并添加自启动
1 | cat /etc/xinetd.d/tftp | grep disable |
根据提示4,下载loaders1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 cobbler get-loaders
task started: 2019-07-24_021430_get_loaders
task started (id=Download Bootloader Content, time=Wed Jul 24 02:14:30 2019)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
根据提示5,启动rsyncd并添加自启动
1 | systemctl enable rsyncd |
根据提示6,安装 debmirro,如果用不到可以忽略1
2
3 yum -y install debmirror
sed -i 's|@dists=.*|#@dists=|' /etc/debmirror.conf
sed -i 's|@arches=.*|#@arches=|' /etc/debmirror.conf
根据提示7,设置新装系统的默认root密码123456。random-phrase-here为干扰码,可以自行设定。1
2# openssl passwd -1 -salt 'cobble' '123456'
$1$cobble$K03Q.A2lkupK0pGFt6f46/
提示8,我没有用到是可以直接忽略的,但是见到提示就不爽,还是解决一下吧
1 | # yum -y install fence-agent |
使用cobbler管理dhcp,1为开启,默认为01
# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
防止循环装系统,适用于服务器第一启动项是PXE启动。
该选项作用:
防止机器循环安装配置始终从网络引导
激活此选项,机器回传Cobbler安装完成
Cobbler将系统对象的netboot标志更改为false,强制要求机器从本地磁盘引导。
1 | # sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings |
使用生成的字符串,替换default_password_crypted默认的密码1
2# vim /etc/cobbler/settings
default_password_crypted: "$1$cobble$K03Q.A2lkupK0pGFt6f46/"
重启cobbler然后在检查一下
1 | cobbler check |
3.2 dhcp模板配置,dhcp只需要修改以下内容即可,同步时cobble会自动修改dhcp配置
1 | cp /etc/cobbler/dhcp.template{,.bak} |
3.3 同步cobbler配置,会修改tftp,dhcp等服务的配置并重启,可以仔细看一下下面的输出1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 cobbler sync
task started: 2019-07-24_043113_sync
task started (id=Sync, time=Wed Jul 24 04:31:13 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
- 导入镜像
先自行下载一个centos7镜像,然后挂载到本地,之后导入到cobbler
1 | # mkdir /mnt/centos7.5 |
- –path 镜像路径
- –name 指定安装源的名字
- –arch 指定导入镜像的体系结构
查看镜像列表1
2 cobbler distro list
CentOS-7.5-1804-x86_64
镜像保存在http的目录内1
ls /var/www/cobbler/ks_mirror/
使用cobbler查看,此处的一些变量我们在写kickstarts配置的时候可能会用到,例如tree1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 cobbler distro report
Name : CentOS-7.5-1804-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS-7.5-1804-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS-7.5-1804-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.5-1804-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
- kickstarts文件配置
在传统安装操作系统时,需要大量的交互操作,为了减少交互的过程,kickstart就产生了,我们需要提前定义好这个kickstart的配置文件,并让安装程序知道kickstart配置文件的位置,在安装过程中读取kickstart配置即可实现无人值守的自动化安装操作系统。
默认的kickstarts文件放在/var/lib/cobbler/kickstarts/目录下,默认有一些示例1
2
3 ls /var/lib/cobbler/kickstarts/
default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample.ks sample.seed
esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks sample_esxi4.ks sample_esxi6.ks sample_old.seed
一般centos系统安装完成后会在/root/anaconda-ks.cfg
产生一个ks配置文件,记录安装过程,我们可以根据这个文件修改一下,修改好后放到/var/lib/cobbler/kickstarts目录
1 | cat /var/lib/cobbler/kickstarts/centos7.5.ks |
查看一下profile的配置
1 | cobbler profile report --name=Centos-7.5-1804-x86_64 |
修改指定的kickstart文件
1 | cobbler profile edit --name=Centos-7.5-1804-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.5.ks |
在查看一下,kickstart已经关联到了我们自己的ks文件
1 | cobbler profile report --name=Centos-7.5-1804-x86_64 | grep -i kickstart |
启动菜单,local是默认选项,之后才是我们自己定义的启动项,在下面的模板中可以看出ONTIMEOUT 超时后会以$pxe_timeout_profile这个变量的值来启动
1 | # cat /etc/cobbler/pxe/pxedefault.template |
查看源代码,pxe_timeout_profile是从system中取的,如果没有设置话默认会设置为local
1 |
|
这里在捊一下distro,profile,system三者间的关系
- distro 可以理解为“操作系统”,我们之前导入iso时会生成distro
- profile 我理解的是这里定义的是操作系统安装时的一些参数?(理解可能有误,欢迎指正)
- system 这里就是定义启动时的菜单选项了
根据上面的代码我们需要加一个system的配置
1 | cobbler system add --name=default --profile=CentOS-7.5-1804-x86_64 |
这里的顺序更改一定要注意,要么就是自动化安装操作系统时划分vlan防止有原来的服务器重启将服务器重新安装,或者安装完后将cobbler服务停止。
- 自动安装系统
以上cobbler算是都配置完成了,现在可以愉快的安装操作系统了,新建一台虚拟机,这步略过了没啥可介绍的,虚拟机指定用pxe 网络启动即可,后边都是图片了,我就不上传了,只要ks文件没问题,几乎不会出问题。如果有问题,自行拆招吧。。
可以用以下命令查看安装状态1
2
3 cobbler status
ip |target |start |state
10.10.0.103 |profile:Centos-7.5-1804-x86_64|Thu Jul 25 03:59:58 2019|installing (59m 35s)
- 访问一下cobbler_web界面
访问地址:https://10.10.1.13/cobbler_web,默认账号及密码:cobbler,cobbler
访问的时候报500的错误,
查看httpd的日志,是python导入一个模块的时候报错了,没办法google一下吧1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 cat /var/log/httpd/ssl_error_log
[Wed Jul 24 04:40:38.165085 2019] [ssl:warn] [pid 3734] AH01909: RSA certificate configured for 10.10.1.13:443 does NOT include an ID which matches the server name
[Wed Jul 24 04:44:34.035706 2019] [:error] [pid 3735] [remote 10.10.1.12:0] mod_wsgi (pid=3735): Exception occurred processing WSGI script '/usr/share/cobbler/web/cobbler.wsgi'.
[Wed Jul 24 04:44:34.035806 2019] [:error] [pid 3735] [remote 10.10.1.12:0] Traceback (most recent call last):
[Wed Jul 24 04:44:34.035842 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/share/cobbler/web/cobbler.wsgi", line 26, in application
[Wed Jul 24 04:44:34.035914 2019] [:error] [pid 3735] [remote 10.10.1.12:0] _application = get_wsgi_application()
[Wed Jul 24 04:44:34.035937 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Wed Jul 24 04:44:34.035977 2019] [:error] [pid 3735] [remote 10.10.1.12:0] django.setup(set_prefix=False)
[Wed Jul 24 04:44:34.035997 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
[Wed Jul 24 04:44:34.036077 2019] [:error] [pid 3735] [remote 10.10.1.12:0] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Wed Jul 24 04:44:34.036114 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
[Wed Jul 24 04:44:34.036217 2019] [:error] [pid 3735] [remote 10.10.1.12:0] self._setup(name)
[Wed Jul 24 04:44:34.036235 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
[Wed Jul 24 04:44:34.036262 2019] [:error] [pid 3735] [remote 10.10.1.12:0] self._wrapped = Settings(settings_module)
[Wed Jul 24 04:44:34.036275 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
[Wed Jul 24 04:44:34.036286 2019] [:error] [pid 3735] [remote 10.10.1.12:0] mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Jul 24 04:44:34.036295 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Wed Jul 24 04:44:34.036356 2019] [:error] [pid 3735] [remote 10.10.1.12:0] __import__(name)
[Wed Jul 24 04:44:34.036371 2019] [:error] [pid 3735] [remote 10.10.1.12:0] File "/usr/share/cobbler/web/settings.py", line 89, in <module>
[Wed Jul 24 04:44:34.036425 2019] [:error] [pid 3735] [remote 10.10.1.12:0] from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
[Wed Jul 24 04:44:34.036450 2019] [:error] [pid 3735] [remote 10.10.1.12:0] ImportError: cannot import name TEMPLATE_CONTEXT_PROCESSORS
算是一个bug,原文地址,解决方案也很简单,将python2-django-1.11.21-2.el7删除,然后安装python2-django16在访问就正常了
1 | rpm -e --nodeps python2-django-1.11.21-2.el7 |
安装完页面是英文,反正都是哪里不会点哪里,就不做截图了
本文作者 : WGY
原文链接 : http://geeklive.cn/2019/07/25/cobbler_install/undefined/cobbler_install/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!