1.安装kickstart
1.1安装dhcp
yum -y install dhcp
hostnamectl set-hostname oldboyedu-kickstart
1.1.1.配置DHCP
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet 172.16.1.0 netmask 255.255.255.0 {
range 172.16.1.100 172.16.1.199; # 可分配的起始IP-结束IP
option subnet-mask 255.255.255.0; # 设定netmask
default-lease-time 21600; # 设置默认的IP租用期限
max-lease-time 43200; # 设置最大的IP租用期限
next-server 172.16.1.201; # 告知客户端TFTP服务器的ip
filename "/pxelinux.0"; # 告知客户端从TFTP根目录下载pxelinux.0文件
}
EOF
1.1.2.启动dhcp查看日志
[root@kickstart ~]# systemctl start dhcpd
[root@kickstart ~]# systemctl status dhcpd
tailf /var/log/messages
Mar 19 21:53:36 oldboyedu-7 systemd: Started Session 2 of user root.
Mar 19 21:53:36 oldboyedu-7 systemd-logind: New session 2 of user root.
Mar 19 21:53:36 oldboyedu-7 systemd: Starting Session 2 of user root.
Mar 19 22:01:01 oldboyedu-7 systemd: Started Session 3 of user root.
Mar 19 22:01:01 oldboyedu-7 systemd: Starting Session 3 of user root.
Mar 19 22:06:32 oldboyedu-7 systemd: Starting Cleanup of Temporary Directories...
Mar 19 22:06:32 oldboyedu-7 systemd: Started Cleanup of Temporary Directories.
Mar 19 22:06:48 oldboyedu-7 systemd: Starting DHCPv4 Server Daemon...
Mar 19 22:06:48 oldboyedu-7 dhcpd: Internet Systems Consortium DHCP Server 4.2.5
Mar 19 22:06:48 oldboyedu-7 dhcpd: Copyright 2004-2013 Internet Systems Consortium.
Mar 19 22:06:48 oldboyedu-7 dhcpd: All rights reserved.
Mar 19 22:06:48 oldboyedu-7 dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Mar 19 22:06:48 oldboyedu-7 dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Mar 19 22:06:48 oldboyedu-7 dhcpd: Wrote 0 leases to leases file.
Mar 19 22:06:48 oldboyedu-7 dhcpd: Listening on LPF/eth1/00:0c:29:ac:2c:40/172.16.1.0/24
Mar 19 22:06:48 oldboyedu-7 dhcpd: Sending on LPF/eth1/00:0c:29:ac:2c:40/172.16.1.0/24
Mar 19 22:06:48 oldboyedu-7 dhcpd:
Mar 19 22:06:48 oldboyedu-7 dhcpd: No subnet declaration for eth0 (10.0.0.201).
Mar 19 22:06:48 oldboyedu-7 dhcpd: ** Ignoring requests on eth0. If this is not what
Mar 19 22:06:48 oldboyedu-7 dhcpd: you want, please write a subnet declaration
Mar 19 22:06:48 oldboyedu-7 dhcpd: in your dhcpd.conf file for the network segment
Mar 19 22:06:48 oldboyedu-7 dhcpd: to which interface eth0 is attached. **
Mar 19 22:06:48 oldboyedu-7 dhcpd:
Mar 19 22:06:48 oldboyedu-7 dhcpd: Sending on Socket/fallback/fallback-net
Mar 19 22:06:48 oldboyedu-7 systemd: Started DHCPv4 Server Daemon
新建一个虚拟机查看日志
下面是内存不给2G 的报错信息
1.1.3.通过抓包查看DHCP过程
yum install wireshark -y
tshark -ni eth1
也可把抓到的数据包写到文件中,然后放到windows中,使用wireshark打开
tshark -ni eth1 -w kickstart.pcap
1.2.安装tftp
安装
yum -y install tftp-server
启动
systemctl start tftp.socket
逐步观看,逐步处理
问题1:
处理方法:
上面报错是在TFTP服务的根目录找不到启动文件
pxelinux.0
[root@kickstart ~]# cd /var/lib/tftpboot/ # TFTP服务的根目录
[root@kickstart tftpboot]# ls
[root@kickstart tftpboot]#
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
问题2:
首先排除最简单故障原因:selinux是否关闭,防火墙是否关闭
查看tftp服务器日志/var/log/messages
处理方法:
上面的错误是因为pxelinux.0这个小系统的配置文件(default)不存在,或者文件名不对
如何找到这个配置文件
第一步:挂载镜像
mkdir -p /var/www/html/CentOS7
mount /dev/cdrom /var/www/html/CentOS7
第二步:从镜像中找到相关的配置文件
cp -a /var/www/html/CentOS7/isolinux/* /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp /var/www/html/CentOS7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
配置完成
#systemctl is-active tftp.service
active
tree -F /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot.cat
├── boot.msg
├── grub.conf
├── initrd.img
├── isolinux.bin
├── isolinux.cfg
├── memtest
├── pxelinux.0
├── pxelinux.cfg/
│ └── default
├── splash.png
├── TRANS.TBL
├── vesamenu.c32
└── vmlinuz*
1.3.安装httpd
上面操作完成,已经进入到安装界面了,但是还不会安装成功
作用1:提供自动应答文件下载
作用2:提供安装系统所需的所有rpm包下载
yum -y install httpd
systemctl start httpd.service
检查步骤
http://10.0.0.201/CentOS7/
curl http://172.16.1.201/CentOS7/
1.4.手动网络安装系统
1.5.自动安装操作系统
1.5.1编写KS文件(包含安装的所有步骤)
方法1:新装CentOS系统/root/anaconda-ks.cfg
方法2:图形CentOS系统提供的图形工具
方法3:了解ks文件语法,编写ks文件。(推荐)
官网参考https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/installation_guide/chap-kickstart-installations
1.5.2ks文件语法
1.1 ks文件组成
命令段
包组段 以%packages开头,以%end结束
脚本段 以%post开头,以%end结束,在安装完系统之后执行的相关Linux命令、脚本
以%pre开头,以%end结束,在安装完系统之前执行的相关Linux命令、脚本
1.2 kickstart文件语法检查
yum install pykickstart
ksvalidator /var/www/html/ks_config/CentOS-7-ks.cfg
请记住这个验证工具有其局限性。Kickstart 文件可能会很复杂;ksvalidator 可保证其语法正确,且该文件不包含淘汰的选项,但它无法保证安装会成功。它也不会尝试验证 Kickstart 文件的 %pre、%post 和 %packages 部分。
1.3 root加密密码生成
python -c 'import crypt; print(crypt.crypt("密码"))'
[root@oldboyedu-kickstart html]# python -c 'import crypt; print(crypt.crypt("123456"))'
6hRuAIrnx3Zd9m85S$sl5ypJdTV.iGaTtxxaBcBZObWSmrTbyRToMK7AMMGSI535k3Ukx2FNauyZiiDw9hU6bwMNBPm.BmInhoqVlgk/
1.4配置文件
[root@oldboyedu-kickstart ks_config]# cat /var/lib/tftpboot/pxelinux.cfg/default
default ks
prompt 0
label ks
kernel vmlinuz
append initrd=initrd.img ks=http://172.16.1.201/ks_config/CentOS7-ks.cfg net.ifnames=0 biosdevname=0 ksdevice=eth1
[root@oldboyedu-kickstart ks_config]#
把网卡名修改为了eth0
[root@oldboyedu-kickstart ks_config]# pwd
/var/www/html/ks_config
[root@oldboyedu-kickstart ks_config]# cat CentOS7-ks.cfg
# Kickstart Configurator for CentOS 7 by yao zhang
lang en_US.UTF-8
keyboard us
timezone --utc Asia/Shanghai
rootpw --iscrypted $6$hRuAIrnx3Zd9m85S$sl5ypJdTV.iGaTtxxaBcBZObWSmrTbyRToMK7AMMGSI535k3Ukx2FNauyZiiDw9hU6bwMNBPm.BmInhoqVlgk/
text
install
url --url="http://172.16.1.201/CentOS7/"
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
zerombr
clearpart --all --initlabel
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow
authconfig --enableshadow --passalgo=sha512
#network --bootproto=static --device=eth0 --gateway=10.0.0.254 --ip=10.0.0.202 --nameserver=223.5.5.5 --netmask=255.255.255.0 --activate
#network --bootproto=static --device=eth1 --ip=172.16.1.202 --netmask=255.255.255.0 --activate
network --hostname=ks
network --bootproto=dhcp --device=eth1 --onboot=yes --noipv6
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%packages
@^minimal
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
wget
vim
bash-completion
%end
%post
systemctl disable postfix.service
%end
[root@oldboyedu-kickstart ks_config]#
由于没有配置eth0,直接跳过
下面就是自动安装过程
2.cobbler安装
2.1安装软件包
官网:
https://cobbler.github.io/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
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
systemctl start cobblerd.service
systemctl start httpd.service
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.
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.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : 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
8 : 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.
2.2配置文件
vim /etc/cobbler/settings
manage_dhcp: 1
vim /etc/cobbler/dhcp.template
subnet 172.16.1.0 netmask 255.255.255.0 {
########这里删除了两行内容,把192.168改为了172.16
option subnet-mask 255.255.255.0;
range dynamic-bootp 172.16.1.100 172.16.1.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else if option pxe-system-type = 00:09 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
2.3按照提示逐步修改配置
1-2.[root@oldboyedu-cobbler cobbler]#
vim /etc/cobbler/settings
server: 172.16.1.202
next_server: 172.16.1.202
3.[root@oldboyedu-cobbler cobbler]#
cat /etc/xinetd.d/tftp
service tftp
{
disable = no
}
4.[root@oldboyedu-cobbler cobbler]#
cobbler get-loaders
task started: 2019-03-20_124007_get_loaders
task started (id=Download Bootloader Content, time=Wed Mar 20 12:40:07 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.[root@oldboyedu-cobbler cobbler]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
7.[root@oldboyedu-cobbler cobbler]# systemctl start rsyncd
8.[root@oldboyedu-cobbler cobbler]# openssl passwd -1
#######密码为oldboy
Password:
Verifying - Password:
$1$6WwCiMKJ$LhxbCiM2TtW9p5uYKL8DR.
[root@oldboyedu-cobbler cobbler]#
[root@oldboyedu-cobbler cobbler]# vim /etc/cobbler/settings
default_password_crypted: "$1$6WwCiMKJ$LhxbCiM2TtW9p5uYKL8DR."
9.[root@oldboyedu-cobbler cobbler]# systemctl restart cobblerd.service
[root@oldboyedu-cobbler cobbler]# cobbler sync
task started: 2019-03-20_125124_sync
task started (id=Sync, time=Wed Mar 20 12:51:24 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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 ***
[root@oldboyedu-cobbler cobbler]# 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.
[root@oldboyedu-cobbler cobbler]#
[root@oldboyedu-cobbler cobbler]# systemctl restart cobblerd.service httpd.service tftp.socket rsyncd.service
[root@oldboyedu-cobbler cobbler]# systemctl is-active rsyncd.service httpd.service tftp.socket rsyncd.service
active
active
active
active
2.4报错处理
https://10.0.0.202/cobbler_web
账号密码默认均为cobbler
[root@oldboyedu-cobbler ~]# cat /var/log/httpd/ssl_error_log
Traceback (most recent call last):
File "/usr/share/cobbler/web/cobbler.wsgi", line 26, in application
_application = get_wsgi_application()
File "/usr/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/share/cobbler/web/settings.py", line 89, in <module>
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
ImportError: cannot import name TEMPLATE_CONTEXT_PROCESSORS
解决办法
搜索
cannot import name TEMPLATE_CONTEXT_PROCESSORS
找到下面
https://github.com/cobbler/cobbler/issues/1717
原因是本地dango版本为1.11,上面的依赖包在django1.10就被移除了。所以找不到次依赖包,暂时就降低django版本
#下载pip.py
wget https://bootstrap.pypa.io/get-pip.py
#调用本地python运行pip.py脚本
python get-pip.py
#安装django
会移除现有版本,安装指定版本
pip install Django==1.8.9
#查看版本
python -c "import django; print(django.get_version())"
#重启httpd
systemctl restart httpd
2.5导入镜像
[root@oldboyedu-cobbler ~]# mount /dev/cdrom /mnt