美文网首页
马哥Linux第十二周

马哥Linux第十二周

作者: Liang_JC | 来源:发表于2020-05-10 17:18 被阅读0次

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

#服务端
[root@centos7 ~]# vim /etc/chrony.conf
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.37.0/24
local stratum 10
logdir /var/log/chrony
[root@centos7 ~]# systemctl restart chronyd

#客户端
#centos6
[root@centos6 ~]$ vim /etc/ntp.conf
server 192.168.37.7 iburst
[root@centos6 ~]$ service ntpd restart
[root@centos6 ~]$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.37.7    120.25.115.20    3 u    9   64    1    0.296    0.610   0.484

#centos7
[root@centos7-2 ~]# vim /etc/chrony.conf
server 192.168.37.7 iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony
[root@centos7-2 ~]# systemctl restart chronyd
[root@centos7-2 ~]# chronyc -n sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.37.7                  3   6    77    16    +35us[ +974us] +/- 5644us

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

#环境:#两台主机
#一台DHCP,HTTPD,TFTP服务器(一个网卡,仅主机),一台测试机(一个网卡,仅主机)
#关闭仅主机的vmware中dhcp服务

1、安装cobbler
[root@cobbler ~]# yum install cobbler dhcp httpd -y         #需要EPL源
[root@cobbler ~]# systemctl start httpd cobblerd tftp.socket

2、检查并修改配置文件
[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.
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.

[root@cobbler ~]# nmcli connection modify eth1 ipv4.addresses 172.16.44.27/24 ipv4.method manual 
[root@cobbler ~]# nmcli connection up eth1
[root@cobbler ~]# vim /etc/cobbler/settings
server: 172.16.44.27                    #本机ip
next-server: 172.16.44.27           #tftp-server
default_password_crypted: ""        #openssl passwd -1 生成密码
manage_dhcp: 1
[root@cobbler ~]# cobbler get-loaders                   #自动配置菜单文件(需要联网)
task started: 2020-03-24_145101_get_loaders
task started (id=Download Bootloader Content, time=Tue Mar 24 14:51:01 2020)
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 ***
[root@cobbler ~]# vim /etc/cobbler/dhcp.template                #修改模板文件
subnet 172.16.44.0 netmask 255.255.255.0 {
     option routers             172.16.44.2;
     option domain-name-servers 172.16.44.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        172.16.44.100 172.16.44.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";
          }
     }
}

3、同步文件
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync
task started: 2020-05-10_162628_sync
task started (id=Sync, time=Sun May 10 16:26:28 2020)
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 ***

4、导入光盘文件
[root@cobbler ~]# mount /dev/sr0 /mnt           #挂载centos7光盘
[root@cobbler ~]# cobbler import --path=/mnt --name=Centos7.6-x86_64 --arch=x86_64
task started: 2020-05-10_163011_import
task started (id=Media import, time=Sun May 10 16:30:11 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos7.6-x86_64:
creating new distro: Centos7.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos7.6-x86_64 -> /var/www/cobbler/links/Centos7.6-x86_64
creating new profile: Centos7.6-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos7.6-x86_64 for Centos7.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos7.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos7.6-x86_64
looking for /var/www/cobbler/ks_mirror/Centos7.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos7.6-x86_64/repodata
*** TASK COMPLETE ***

[root@cobbler ~]# umount /dev/sr0
[root@cobbler ~]# mount /dev/sr1 /mnt           #挂载centos6光盘
[root@cobbler ~]# cobbler import --path=/mnt --name=Centos6.10-x86_64 --arch=x86_64
task started: 2020-05-10_163450_import
task started (id=Media import, time=Sun May 10 16:34:50 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos6.10-x86_64:
creating new distro: Centos6.10-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos6.10-x86_64 -> /var/www/cobbler/links/Centos6.10-x86_64
creating new profile: Centos6.10-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos6.10-x86_64 for Centos6.10-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos6.10-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos6.10-x86_64
looking for /var/www/cobbler/ks_mirror/Centos6.10-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos6.10-x86_64/repodata
*** TASK COMPLETE ***

5、关联自定义ks文件
[root@cobbler ~]# cobbler profile remove --name Centos6.10-x86_64
[root@cobbler ~]# cobbler profile remove --name Centos7.6-x86_64
[root@cobbler ~]# cd /var/lib/cobbler/kickstarts
[root@cobbler kickstarts]# cat ks6_mini.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password default:centos
rootpw --iscrypted $1$JmO.k3YO$aE.aDZUW/6QQTeIXi0Phn0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
#graphical
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=102400
part /data --fstype="ext4" --size=51200
part swap --fstype="swap" --size=4096

%packages
@core
%end

[root@cobbler kickstarts]# cat ks7_mini.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig  --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$46GvT151$zirNpc/cWEBEADLx/hw5V.
# Use network installation
url --url=$tree
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# System services
services --enabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --size=102400
part /data --fstype="xfs" --size=5120
part swap --fstype="swap" --size=4096

%packages
@core
%end

[root@cobbler kickstarts]# cat ks6_desktop.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password default:centos
rootpw --iscrypted $1$iDhaegPv$emFtFFmLkKBNXq6GgGZ/j.
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Partition clearing information
clearpart --all  
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=102400
part /data --fstype="ext4" --size=51200
part swap --fstype="swap" --size=4096

%packages
@base
@basic-desktop
@core
@debugging
@desktop-debugging
@desktop-platform
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@kde-desktop
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@workstation-policy
@x11
abrt-gui
certmonger
device-mapper-persistent-data
genisoimage
krb5-workstation
libXmu
mtools
oddjob
pam_krb5
pax
python-dmidecode
qt-mysql
rdesktop
samba-winbind
sgpio
wodim
xorg-x11-xdm
xsettings-kde
xterm
%end

[root@cobbler kickstarts]# cat ks7_desktop.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig  --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$kBKcOyBL$3DtOLufV3y.oQTjv1fQgd1
# Use network installation
url --url=$tree
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# System services
services --enabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --size=102400
part /data --fstype="xfs" --size=5120
part swap --fstype="swap" --size=4096

%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
wodim
-firefox
-icedtea-web
%end


[root@cobbler ~]# cobbler profile add --name Centos6.10-x86_64_mini --distro=Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg
[root@cobbler ~]# cobbler profile add --name Centos6.10-x86_64_Desktop --distro=Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_desktop.cfg
[root@cobbler ~]# cobbler profile add --name Centos7.6-x86_64_mini --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
[root@cobbler ~]# cobbler profile add --name Centos7.6-x86_64_Desktop --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_desktop.cfg
[root@cobbler ~]# cobbler profile list
   Centos6.10-x86_64_Desktop
   Centos6.10-x86_64_mini
   Centos7.6-x86_64_Desktop
   Centos7.6-x86_64_mini

#引导菜单已自动生成
[root@cobbler kickstarts]# 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 Centos6.10-x86_64_Desktop
        kernel /images/Centos6.10-x86_64/vmlinuz
        MENU LABEL Centos6.10-x86_64_Desktop
        append initrd=/images/Centos6.10-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.16.44.27/cblr/svc/op/ks/profile/Centos6.10-x86_64_Desktop
        ipappend 2

LABEL Centos6.10-x86_64_mini
        kernel /images/Centos6.10-x86_64/vmlinuz
        MENU LABEL Centos6.10-x86_64_mini
        append initrd=/images/Centos6.10-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.16.44.27/cblr/svc/op/ks/profile/Centos6.10-x86_64_mini
        ipappend 2

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

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

6、重新启动服务
[root@cobbler ~]# systemctl restart cobblerd dhcpd tftp.socket httpd

客户端测试:

  1. 新建虚拟机测试:网卡改为vmnet5、点击开启

    image.png
  2. 选择网卡启动,选择centos6.10_mini测试安装

    image.png
  3. centos6安装状态

    image.png
  4. 安装完毕进入系统,默认密码为centos

    image.png
  5. centos7.6_mini安装测试(注意:内存2G才能安装)

    image.png
  6. centos7安装状态

    image.png
  7. 安装完毕进入系统,默认密码为centos

image.png

相关文章

  • 马哥Linux第十二周

    Q1、配置chrony服务,实现服务器时间自动同步 Q2、实现cobbler+pxe自动化装机 客户端测试: 新建...

  • 文件系统常用命令:cd命令

    为方便马哥学员的理解和使用,马哥linux运维团队特别做了《马哥Linux命令大全锦集》,命令是集合了马哥教育学员...

  • 马哥linux第二周

    Q1、描述Linux发行版的系统目录名称命名规则以及用途。 命名规则: 文件名最长255个字节 包括路径在内文件名...

  • 马哥Linux第五周

    Q1、查找/etc目录下大于1M且类型为普通文件的所有文件 Q2、打包/etc/目录下面所有conf结尾的文件,压...

  • 马哥Linux第七周

    Q1、简述osi七层模型和TCP/IP五层模型 OSI七层模型7、应用层网络进程访问应用层:为应用程序进程提供网络...

  • 马哥Linux第九周

    Q1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建maged...

  • Linux开发被大数据云计算带火啦让我门一起学习Linux教程大

    视频下载地址 Linux运维 马哥教程Liunx新 马哥2016linux就业班+架构班+运维班全套新 dubbo...

  • 马哥Linux第十五周

    Q1、编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份。 Q2、配置Mysql主从...

  • 马哥Linux第十七周

    Q1、部署分离的LAMP,部署到二台服务器上,php加载xcache模块 环境:2台主机 server-A 192...

  • 马哥Linux第十九周

    Q1、简述lvs四种集群特点及使用场景 lvs-nat:修改请求报文的目标IP,多目标IP的DNAT本质是多目标I...

网友评论

      本文标题:马哥Linux第十二周

      本文链接:https://www.haomeiwen.com/subject/dtwjnhtx.html