1、配置chrony服务,实现服务器时间自动同步
配置同步服务器
#安装chrony
[root@laowei05 ~]#yum install chrony.x86_64
#修改chrony配置文件
[root@laowei05 ~]#vim /etc/chrony.conf
server ntp.aliyun.com iburst #设置同步服务器
allow 192.168.0.0/21 #允许此网段主机向本机同步
[root@laowei05 ~]#systemctl enable chronyd #开机自启动
[root@laowei05 ~]#systemctl start chronyd #启动服务
#查看服务器端和互联网同步情况
[root@laowei05 ~]#chronyc sources
210 Number of sources = 4
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 377 48 +1523us[+2204us] +/- 35ms
出现"*"表示同步成功
客户端配置
#同样安装chronyd包并启动
[root@laowei04 ~]#vim /etc/chrony.conf
server 192.168.7.15 iburst #将同步服务器修改为上面的主机IP
[root@laowei05 ~]#systemctl restart chronyd #重启同步服务
#查看同服务器端同步情况
[root@laowei04 ~]#chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.7.15 0 7 0 - +0ns[ +0ns] +/- 0ns
#故意修改时间测试
[root@laowei04 ~]#date -s '-1 week'
Wed Apr 22 10:43:23 CST 2020
#再查看时间,时间恢复正常
[root@laowei04 ~]#date
Wed Apr 29 10:51:44 CST 2020
2、实现cobbler+pxe自动化装机
#安装必备软件包
[root@wei ~]#yum install httpd tftp-server dhcp syslinux system-config-kickstart
#新建光盘挂载目录
[root@wei ~]#mkdir /var/www/html/centos/7/os/x86_64 -pv
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
#新建tftp服务所需目录
[root@wei ~]#mkdir /var/lib/tftpboot/centos7
[root@wei ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 10G 0 rom
#挂载光盘源
[root@wei ~]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@wei ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 10G 0 rom /var/www/html/centos/7/os/x86_64
#新建kickstart文件放置目录
[root@wei ~]#mkdir /var/www/html/ksdir
[root@wei ~]#cd /var/www/html/ksdir/
[root@wei ksdir]#rz
#根据情况修改配置文件
[root@wei ksdir]#vim ks7_02.cfg
#启动httpd服务
[root@wei ksdir]#systemctl start httpd
#启动tftp服务
[root@wei kddir]#systemctl start tftp.socket
[root@wei ksdir]#mv ks7_02.cfg ks7.cfg
#拷贝dhcpd配置模板文件
[root@wei ksdir]#cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf -b
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
#修改dhcp服务配置文件
[root@wei ksdir]#vim /etc/dhcp/dhcpd.conf
option domain-name "laoweia.org";
option domain-name-servers 180.76.76.76;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
#配置子网,掩码,网段范围,服务端等
subnet 192.168.44.0 netmask 255.255.255.0 {
range 192.168.44.102 192.168.44.200;
option routers 192.168.44.2;
next-server 192.168.44.72;
filename "pxelinux.0";
}
#启动dhcp服务
[root@wei ksdir]#systemctl start dhcpd
#准备相关文档
[root@wei ksdir]#cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz /var/lib/tftpboot/centos7/
[root@wei ksdir]#cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img /var/lib/tftpboot/centos7/
[root@wei tftpboot]#cp /usr/share/syslinux/pxelinux.0 .
[root@wei tftpboot]#cp /usr/share/syslinux/menu.c32 .
[root@wei tftpboot]#mkdir pxelinux.cfg
[root@wei tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg pxelinux.cfg/
[root@wei tftpboot]#cd pxelinux.cfg/
[root@wei pxelinux.cfg]#ll
total 4
-rw-r--r-- 1 root root 3032 Mar 31 10:22 isolinux.cfg
[root@wei pxelinux.cfg]#mv isolinux.cfg default.cfg
#配置default启动菜单文件
[root@wei pxelinux.cfg]#vim default.cfg
default menu.c32
timeout 600
menu title CentOS 7
label linux7
menu label ^Install CentOS 7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.44.72/ksdir/ks7.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
#修改后缀名
[root@wei pxelinux.cfg]#mv default.cfg default
#新建一个虚拟机(光盘选项不勾选连接)
#直接启动虚拟机,选择界面内选项,等待安装完成