第十二周运维作业

1、配置chrony服务,实现服务器时间自动同步

答:服务端centos7.6   客户端centos7.0  

服务端配置 

[root@centos7 ~]# vim /etc/chrony.conf    修改chrony.conf 配置文件

[root@centos7 ~]# systemctl restart chronyd   重启服务

[root@centos7 ~]# systemctl enable chronyd   开机自动启动

 修改客户端  vim /etc/chrony.conf

 验证

[root@centos7 ~]# date
Mon Sep 7 14:40:33 CST 2020

[root@centos7 ~]# date -s "1 day"
Tue Sep 8 14:40:24 CST 2020

[root@centos7 ~]# systemctl restart chronyd   执行重启服务

[root@centos7 ~]# date
Mon Sep 7 14:40:33 CST 2020

2、实现cobbler+pxe自动化装机

pxe 自动化安装 

设置yum源和epel源,并通过yum安装dhcp、tftp、httpd、syslinux服务

关闭selinux 和 关闭防火墙  

虚拟机配置  修改网络内容 vmnet8 nat模式,取消DHCP自动分配IP

[root@centos7 ~]# yum repolist 

[root@centos7 ~]#yum  install dhcp  tftp httpd -y

[root@centos7 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

 cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y  是否覆盖

编辑dhcpd.conf  

[root@centos7 ~]# vim /etc/dhcp/dhcpd.conf   修改配置文件 dhcp

# option definitions common to all supported networks...
option domain-name "sun.com";     #定义选项
#option domain-name-servers ns1.example.org, ns2.example.org;
option domain-name-servers 180.76.76.76;    #dhcp服务器地址
default-lease-time 86400;     #租约期限
max-lease-time 86400;           #最长租约期限

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

subnet 192.168.47.0 netmask 255.255.255.0 {
range 192.168.47.50 192.168.47.100;     #指定IP地址范围
option routers 192.168.47.254;      #指定网关
next-server 192.168.47.70;         
filename "pxelinux.0";
}

注意:其他未作修改

[root@centos7 ~]# systemctl start dhcpd

[root@centos7 ~]# mkdir -pv /var/www/html/centos7/x86_64  创建目录

[root@centos7 ~]# mount -r /dev/sr0  /var/www/html/centos/7/x86_64  挂载光盘

[root@centos7 ~]# systemctl start httpd

[root@centos7 ~]#systemctl  enable httpd

[root@centos7 ~]# mkdir /var/www/html/ksdir/ 创建ks目录

[root@centos7 ~]# cp anaconda-ks.cfg /var/www/html/ksdir/ks7_mini.cfg

[root@centos7 ~]# vim /var/www/html/ksdir/ks7_mini.cfg  编辑ks应答文件

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=ftp://192.168.31.7/pub/centos7/
# Use graphical install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate
network --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$0U7I.uZWqQ4DZrp1$T/L3volXctFcFO8h7s9d/J/fXl2jjdIOUf6qaFYUarwiC2.yBD79rYFWTVZ5s2SIsIIr7lkroxs7deZNO6znn/
# System services
services --disabled="chronyd"
selinux --disabled
firewall --disabled
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
zerombr
eula --agreed
reboot
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=3072
part / --fstype="xfs" --ondisk=sda --size=51200
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /data --fstype="xfs" --ondisk=sda --size=30720

%packages
@core
autofs
%end
%post
systemctl enable autofs
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd/
gpgcheck=0
EOF

useradd zhangsan
echo magedu |passwd --stdin zhangsan

mkdir /root/.ssh
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSV0vkgeRJPikUdZ6V/RV6sLwGfw1LfapEFh8wxgYcS4tY9txVzpzJzTWuCmqMLZDK3AQt4AHOK7H39OAgIECr79wmzh1kHDj/i6asSw9Z9Nf+R4QlLhwWEfWV1nuk/SgxTLgQlqFh/9NGjG+gyihhCqfq2xHWcOyuf/pLH/IsfRP26MdP2o0YC4copRJVBPf/eO0lR+VbthDsm2yoYXuCYXur9423MNd5zV0hO+EcEiasDXsA3xPz8NwUVWumekYyIttnTRoCYsDuZPA6B0hp3Uh0krwgbGXqnc+uW7tbOveFDpkC9gXHUitt8MqemSx7i+DX3orO3J6f6b4C5gM7 root@centos7.localdomain' > /root/.ssh/authorized_keys
echo 'alias cdnet="cd /etc/sysconfig/network-scripts"' >> /root/.bashrc

%end

[root@centos7 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/  #拷贝文件

[root@centos7 tftpboot]# cp /misc/cd/images/pxeboot/{initrd.img,vmlinuz} .

[root@centos7 tftpboot]# cp /usr/share/syslinux/menu.c32 .

[root@centos7 tftpboot]# mkdir pxelinux.cfg  #创建引导配置文件

[root@centos7 tftpboot]# cd pxelinux.cfg

[root@centos7 pxelinux.cfg]# vim default   

default menu.c32
timeout 600
LABEL linux_autoinst #自动安装选项
MENU LABEL Install CentOS 7 ^Mini
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://192.168.47.70/7/os/x86_64

LABEL linux
MENU LABEL Install CentOS 7 x86_64
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://192.168.47.70/7/os/x86_64

客户端安装

 cobbler 自动化安装

 安装cobbler、dhcp服务  创建yum仓库是epel源 必须连接网络

[root@centos7 data]# yum install cobbler dhcp

 [root@centos7 data]# systemctl start cobbler

  [root@centos7 data]# systemctl  enable cobbler

 [root@centos7 data]# systemctl start httpd

  [root@centos7 data]# vim /etc/cobbler/settings  编辑cobbler配置文件

更改cobbler服务器地址 192.168.47.154

 

更改tftp服务器地址:192.168.47.154

 

[root@centos7 ~]# openssl passwd -1

更改加密口令:$1$wRfZiqnW$jhuvd98T7Fj3a1RiiOZZS.   口令是centos7

 自动生成dhcp文件

 更改完成后保存退出

[root@centos7 ~]# systemctl restart cobblerd

[root@centos7 ~]# cobbler get-loaders

[root@centos7 data]# vim /etc/cobbler/dhcp.template 

[root@centos7 ~]# cobbler sync

[root@centos7 ~]# cat /etc/dhcp/dhcpd.conf

 [root@centos7 ~]# systemctl restart dhcpd

导入光盘生成一个centos7的应答文件

[root@centos7 data]# cobbler import --path=/mnt --name=centos7.6_x86_64 --arch=x86_64

[root@centos7 ~]# cd /var/www/cobbler/ks_mirror/   已生成应答文件
[root@centos7 ks_mirror]# ls
centos7.6_x86_64-x86_64 config

[root@centos7 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)
MENU DEFAULT
LOCALBOOT -1

LABEL centos7.6-x86_64
kernel /images/centos7.6-x86_64/vmlinuz
MENU LABEL centos7.6-x86_64
append initrd=/images/centos7.6-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.47.154/cblr/svc/op/ks/profile/centos7.6-x86_64
ipappend 2

MENU end

测试机启动 

 

原文地址:https://www.cnblogs.com/jing-yun/p/13626122.html