08-无人值守自动批量安装系统(下)

这会用到的工具叫做 cobbler 。

其原理就是pxe kickstart;cobbler其实就是对kickstart的所有组件的封装。操作可以采用web界面点击的方式完成

环境准备

[root@cobbler ~]# uname -i
x86_64
[root@cobbler ~]# uname -r
3.10.0-862.el7.x86_64
[root@cobbler ~]# uname -n
cobbler
内网IP:172.16.1.111
外网IP:10.0.0.111

安装cobbler

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd python-django

启动服务

[root@cobbler ~]# systemctl start httpd.service 
[root@cobbler ~]# systemctl start cobblerd.service

报错

[root@cobbler ~]# cobbler check
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 251, in check_setup
    s.ping()
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1591, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1321, in single_request
    response.msg,
ProtocolError: <ProtocolError for 127.0.0.1:80/cobbler_api: 404 Not Found>

启动服务顺序弄错,要先启动cobbler在启动httpd

[root@cobbler ~]# systemctl stop cobblerd.service
[root@cobbler ~]# systemctl stop httpd.service 

[root@cobbler ~]# systemctl start cobblerd.service
[root@cobbler ~]# systemctl start httpd.service 

cobbler接管服务:

[root@cobbler ~]# vim /etc/cobbler/settings
manage_dhcp: 1


#0不管理
#1管理

编辑dhcp模板文件

[root@cobbler ~]# vim /etc/cobbler/dhcp.template 
subnet 172.16.1.0 netmask 255.255.255.0 {
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.1.100 192.168.1.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
#将subnet改为自己想要的网段信息即可

 

然后执行 cobbler check;根据提示操作

[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.

#修改/etc/cobbler/settings   'server' 这个字段

    384 server: 172.16.1.111



2
: For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
#修改/etc/cobbler/settings    'next_server' 这个字段

    272 next_server: 172.16.1.111


3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux
将SELinux 的状态更改


4 : change 'disable' to 'no' in /etc/xinetd.d/tftp

#修改
/etc/xinetd.d/tftp 把disable = yes 改为
disable = no

5 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
#运行
cobbler get-loaders 获取所需文件




6 : enable and start rsyncd.service with systemctl

#启动
rsyncd.service

[root@cobbler ~]# systemctl start rsyncd.service

[root@cobbler ~]# systemctl enable rsyncd.service


7 : debmirror package is not installed, it will be required to manage debian deployments and repositories

#与diban相关的内容不需要管

8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
#
/将etc/cobbler/settings的password改称新密码;可以使用openssl passwd -1 获取加密密码

[root@cobbler ~]# openssl passwd -1
Password:
Verifying - Password:
$1$4iejMn/H$al6ZFzFpcrTusQsTD3q9b0   #这是得到的加密密文密码

将 101 default_password_crypted: "$1$4iejMn/H$al6ZFzFpcrTusQsTD3q9b0"  改为你得到的内容

#注意一定要一字不差;这里设置的就是我们系统被自动安装之后的初始密码

 



9 : 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 同步一下

重启服务

#重启服务
[root@cobbler ~]# systemctl restart cobblerd.service




#更新
[root@cobbler ~]# cobbler sync



#重新检查
[root@cobbler ~]# cobbler check

把所有用到的服务启动起来

[root@cobbler ~]# systemctl restart cobblerd httpd tftp rsyncd

这里不用启动dhcpd是因为已经被cobbler接管了

 

访问测试 https://IP/cobbler_web 报错

500 nternal Server Error

检查

[root@localhost ~]# tail -f  /var/log/httpd/ssl_error_log 
[Wed Aug 14 21:49:53.984939 2019] [:error] [pid 5496] [remote 10.0.0.1:4]     self._setup(name)
[Wed Aug 14 21:49:53.984943 2019] [:error] [pid 5496] [remote 10.0.0.1:4]   File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
[Wed Aug 14 21:49:53.984948 2019] [:error] [pid 5496] [remote 10.0.0.1:4]     self._wrapped = Settings(settings_module)
[Wed Aug 14 21:49:53.984952 2019] [:error] [pid 5496] [remote 10.0.0.1:4]   File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
[Wed Aug 14 21:49:53.984957 2019] [:error] [pid 5496] [remote 10.0.0.1:4]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Aug 14 21:49:53.984961 2019] [:error] [pid 5496] [remote 10.0.0.1:4]   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Wed Aug 14 21:49:53.984968 2019] [:error] [pid 5496] [remote 10.0.0.1:4]     __import__(name)
[Wed Aug 14 21:49:53.984972 2019] [:error] [pid 5496] [remote 10.0.0.1:4]   File "/usr/share/cobbler/web/settings.py", line 89, in <module>
[Wed Aug 14 21:49:53.984978 2019] [:error] [pid 5496] [remote 10.0.0.1:4]     from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
[Wed Aug 14 21:49:53.984988 2019] [:error] [pid 5496] [remote 10.0.0.1:4] ImportError: cannot import name TEMPLATE_CONTEXT_PROCESSORS

猜测python-django版本有问题:https://github.com/cobbler/cobbler/issues/1959

[root@localhost ~]# yum -y install python2-pip
[root@localhost ~]#  pip install --upgrade pip
[root@localhost ~]# pip install Django==1.9.13
#用pip安装指定版本的Django

 

重启httpd服务

再次访问测试https://10.0.0.111/cobbler_web

 

 这次访问正常

输入账户密码即可登录,默认账户cobler;密码cobbler

然后就可以利用这个web界面进行操作

首先导入镜像

这里就是把/mnt目录下的文件导入到/var/www/cobbler/ks_mirror/centos7.4-x86_64/目录下 ;这个就是版本补齐,前面的centos7.4就是我们取得名字

点击run提示2019-08-14_221957_import : 1565792397.67 :: failed;这是因为没有把光盘镜像挂载上去

[root@localhost ks_mirror]# rm -r centos7.4-x86_64/
rm: remove directory ‘centos7.4-x86_64/’? y

按照上面的dvd importer重新再来操作一次

显示

Task Enqueued
A background task has been created for the action you have initiated. Pop-up notifications will alert you to status updates regarding this and other tasks. You can also browse the Task Log.

然后在events里就会有信息

导入完成会显示complete

如果还要导入其他的镜像可以再次导入

 其实到这里就可以开始自动化安装了,因为cobbler内置的定义都已经操作好了;ks.cfg也有好多默认配置

如果想要自定义一下,可以随意选取一个模板修改一下即可

 这里就以/var/lib/cobbler/kickstarts/sample.ks为例来进行

为了更方便记忆,我这里就新建一个名为centos7.ks.cfg

内容就是把sample.ks里的复制进去,最后可以看到这个文件的路径就是/var/lib/cobbler/kickstarts/centos7.ks.cfg

然后将这个ks指向为我们安装时的默认配置即可

接下去配置 Systems

如果想要安装完成后就定义好了主机名,IP等信息配置 Systems

然后点击sync同步信息

到了这里如果提示: operating system not found

那是因为default的菜单文件默认选择了local,所以需要编辑 /var/lib/tftpboot/pxelinux.cfg/default 

[root@localhost ks_mirror]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        LOCALBOOT -1

LABEL centos7.4-x86_64
        MENU DEFAULT  #将LABEL local的MENU DEFAULT放到LABEL centos7.4-x86_64就可以了
    kernel /images/centos7.4-x86_64/vmlinuz
        MENU LABEL centos7.4-x86_64
        append initrd=/images/centos7.4-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.16.1.111/cblr/svc/op/ks/profile/centos7.4-x86_64
        ipappend 2



MENU end

 

 

为了防止误重装系统:sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

posted @ 2019-08-14 15:26  25℃  阅读(429)  评论(0编辑  收藏  举报