chrony服务与Cobbler自动化部署

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

~]# yum install chrony -y

# 修改时钟服务器
~]# vi /etc/chrony.conf 
...
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
...

# 启动 chronyd
~]# systemctl start chronyd.service
~]# systemctl enable chronyd.service

# 查看时间同步源
~]# chronyc sources -v   
210 Number of sources = 4

  .-- 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               
===============================================================================
^* 203.107.6.88                  2   6   177    61    +27us[ +181us] +/-   14ms
^- h199-182-204-197.ip4.unm>     2   6   177    60    +47ms[  +47ms] +/-  146ms
^? ntp8.flashdance.cx            2   6     3    59   +274us[ +274us] +/-  213ms
^- a.chl.la                      2   6   207    51    -20ms[  -20ms] +/-  130ms

# 查看时间同步源状态
~]# chronyc sourcestats -v    
210 Number of sources = 4
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
203.107.6.88               11   6   460     +0.222     10.719    +14us  1079us
h199-182-204-197.ip4.unm>  11   6   464    +14.785     56.248    +45ms  6491us
ntp8.flashdance.cx          6   3   325    +30.213    217.331  +8413us  7201us
a.chl.la                    8   5   465    -20.530    233.250    -37ms    14ms

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

准备环境

准备一台 CentOS 7 虚拟机,分配两块虚拟网卡,一个桥接模式(ens33:可以联网安装软件),一个仅主机模式(ens37:配置一个固定IP,关掉vmvare仅主机模式网络的DHCP服务)

~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.58.149  netmask 255.255.255.0  broadcast 192.168.58.255
        inet6 fe80::e179:f714:a156:7d37  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:da:e9:ef  txqueuelen 1000  (Ethernet)
        RX packets 180  bytes 19350 (18.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 51  bytes 8075 (7.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.146.10  netmask 255.255.255.0  broadcast 192.168.146.255
        inet6 fe80::20c:29ff:feda:e9f9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:da:e9:f9  txqueuelen 1000  (Ethernet)
        RX packets 141  bytes 13512 (13.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10  bytes 776 (776.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4  bytes 348 (348.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 348 (348.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

image-20200229121041618.png

PXE

安装配置DHCP

~]# yum install dhcp -y

# 查看 dhcpd.conf 的帮助文档
~]# man dhcpd.conf

# 查看 dhcp 安装的文件列表
~]# rpm -ql dhcp

~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
option domain-name "localhost";
option domain-name-servers 192.168.146.10, 8.8.8.8;

default-lease-time 600;
max-lease-time 7200;

log-facility local7;

subnet 192.168.146.0 netmask 255.255.255.0 {
  range  192.168.146.100 192.168.146.200;
  option routers 192.168.146.10;
}

next-server 192.168.146.10;
filename "pxelinux.0";

~]# systemctl enable dhcpd.service
~]# systemctl start dhcpd.service

安装配置PXE

# 挂载光盘镜像
~]# ll /dev/cdrom 
lrwxrwxrwx. 1 root root 3 Feb 29 21:10 /dev/cdrom -> sr0
~]# mkdir /media/cdrom
~]# mount -r -t iso9660 /dev/cdrom /media/cdrom
~]# ll /media/cdrom/
total 108
-rw-rw-r--. 1 root root    14 Nov 26  2018 CentOS_BuildTag
drwxr-xr-x. 3 root root  2048 Nov 26  2018 EFI
-rw-rw-r--. 1 root root   227 Aug 30  2017 EULA
-rw-rw-r--. 1 root root 18009 Dec 10  2015 GPL
drwxr-xr-x. 3 root root  2048 Nov 26  2018 images
drwxr-xr-x. 2 root root  2048 Nov 26  2018 isolinux
drwxr-xr-x. 2 root root  2048 Nov 26  2018 LiveOS
drwxrwxr-x. 2 root root 71680 Nov 26  2018 Packages
drwxr-xr-x. 2 root root  4096 Nov 26  2018 repodata
-rw-rw-r--. 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root  2883 Nov 26  2018 TRANS.TBL

# 配置 YUM 源服务
~]# yum install httpd -y
~]# ln -s /media/cdrom /var/www/html/centos7
~]# systemctl start httpd.service

# 生产 kickstart 配置文件
~]# yum install system-config-kickstart -y

# 使用 system-config-kickstart 工具生成 kickstart 配置文件
~]# system-config-kickstart centos7.cfg
~]# cp centos7.cfg /var/www/html/

# 安装PXE
~]# yum -y install syslinux tftp-server xinetd

# 复制PXE引导文件
~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
~]# cp /usr/share/syslinux/{chain.c32,mboot.c32,menu.c32,memdisk} /var/lib/tftpboot/
~]# cp /media/cdrom/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/

~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
  prompt 5
  timeout 30
  MENU TITLE CentOS 7 PXE Menu

  LABEL linux
  MENU LABEL Install CentOS 7 x86_64
  KERNEL vmlinuz
  APPEND initrd=initrd.img inst.repo=http://192.168.146.10/centos7 ks=http://192.168.146.10/centos7.cfg
  
~]# systemctl start tftp.socket
~]# systemctl start tftp.service
~]# systemctl start xinetd.service

测试

注意客户机最小内存2G

pxe-01.png
pxe-02.png

Cobbler

安装配置Cobbler

~]# yum install epel-release -y

~]# yum install cobbler cobbler-web pykickstart httpd dhcp rsync xinetd -y

~]# systemctl enable httpd.service
~]# systemctl start httpd.service


# 配置 HDCP
~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
option domain-name "localhost";
option domain-name-servers 192.168.146.10, 8.8.8.8;

default-lease-time 600;
max-lease-time 7200;

log-facility local7;

subnet 192.168.146.0 netmask 255.255.255.0 {
  range  192.168.146.100 192.168.146.200;
  option routers 192.168.146.10;
}

next-server 192.168.146.10;
filename "pxelinux.0";

~]# systemctl start dhcpd.service
~]# systemctl enable dhcpd.service

# 配置 Cobbler
~]# systemctl enable cobblerd.service
~]# systemctl start cobblerd.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 : 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
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
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.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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
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.

~]# systemctl start xinetd.service
~]# systemctl enable xinetd.service
~]# systemctl start rsyncd.service 
~]# systemctl enable rsyncd.service
~]# cobbler get-loaders
~]# cobbler sync
~]# systemctl restart cobblerd.service

管理 distro

# 挂载光盘
~]# mkdir /media/cdrom
~]# mount -r -t iso9660 /dev/cdrom /media/cdrom
~]# cobbler import --name=centos7-x86_64-1810 --path=/media/cdrom
task started: 2020-03-02_004519_import
task started (id=Media import, time=Mon Mar  2 00:45:19 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-x86_64-1810:
creating new distro: centos7-1810-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7-x86_64-1810 -> /var/www/cobbler/links/centos7-1810-x86_64
creating new profile: centos7-1810-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-x86_64-1810 for centos7-1810-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7-x86_64-1810
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-x86_64-1810
looking for /var/www/cobbler/ks_mirror/centos7-x86_64-1810/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-x86_64-1810/repodata
*** TASK COMPLETE ***

~]# cobbler list       
distros:
   centos7-1810-x86_64

profiles:
   centos7-1810-x86_64


# 自定义 ks 配置文件   
~]# cp centos7-x86_64-1810-mini.cfg  /var/lib/cobbler/kickstarts/

~]# cobbler profile edit --name=centos7-1810-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-x86_64-1810-mini.cfg

~]# cobbler profile report
Name                           : centos7-1810-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos7-1810-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/centos7-x86_64-1810-mini.cfg
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

~]# cobbler sync

测试

注意客户机最小内存2G

image-20200301172140548.png
image-20200301172244609.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容