第十五周作業(yè)

1、PAM和google模塊實(shí)現(xiàn)ssh雙因子安全驗(yàn)證陷揪。

  1. 在手機(jī)應(yīng)用市場(chǎng)搜索:身份驗(yàn)證器或authenticator腿准,并安裝APP

  2. 修改/etc/pam.d/sshd文件,將google的PAM模塊加入進(jìn)去實(shí)現(xiàn)

安裝google-authenticator模塊

[root@centos8 ~]# yum -y install epel-release.noarch
[root@centos8 ~]# yum makecache
[root@centos8 ~]# yum install -y google-authenticator.x86_64

初始化驗(yàn)證功能

[root@centos8 ~]# google-authenticator

Do you want authentication tokens to be time-based (y/n) y
Warning: pasting the following URL into your browser exposes the OTP secret to Google:
  https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@centos8%3Fsecret%3DBZVPXXFINW5SMMSPBMVQMB5R54%26issuer%3Dcentos8
Failed to use libqrencode to show QR code visually for scanning.
Consider typing the OTP secret into your app manually.
Your new secret key is: BZVPXXFINW5SMMSPBMVQMB5R54
Enter code from app (-1 to skip): -1 #這里需要輸入用身份驗(yàn)證器掃碼上面給出的地址獲取到的code滓鸠。測(cè)試的時(shí)候跳過(guò)這一步雁乡,直接輸入-1,可以用下面給出的緊急驗(yàn)證碼登錄測(cè)試使用
Code confirmation skipped
Your emergency scratch codes are:
  27273600
  44505367
  78109426
  65720380
  84362481

Do you want me to update your "/root/.google_authenticator" file? (y/n) y

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) y

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y



修改ssh登錄配置并重啟服務(wù)

#/etc/pam.d/sshd文件糜俗,修改或添加下行保存
#auth required pam_google_authenticator.so
[root@centos8 ~]# sed -i '1a\auth required pam_google_authenticator.so' /etc/pam.d/sshd
#編輯/etc/ssh/sshd_config找到下行
#ChallengeResponseAuthentication no
#更改為
#ChallengeResponseAuthentication yes
[root@centos8 ~]# sed -i 's/.*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
#重啟SSH服務(wù)
[root@centos8 ~]# service sshd restart  

驗(yàn)證登錄

[root@1288-9 ~]# ssh 192.168.1.8
Verification code:
Password:
Last login: Wed Jul 14 09:44:57 2021 from 192.168.1.1
[root@centos8 ~]#

2踱稍、使用chrony實(shí)現(xiàn)內(nèi)網(wǎng)時(shí)間同步(一臺(tái)node1從外網(wǎng)同步時(shí)間,其余機(jī)器從node1同步時(shí)間)悠抹。

1珠月、 安裝chrony軟件

yum -y install chrony

2、修改配置文件/etc/chrony.conf

node1 ip 192.168.122.18
server s1b.time.edu.cn iburst
allow 192.168.0.0/16
其他選項(xiàng)默認(rèn)

其他節(jié)點(diǎn)ip在192.168網(wǎng)段內(nèi)
server 192.168.122.18 iburst
其他選項(xiàng)默認(rèn)

3锌钮、啟用chronyd服務(wù),檢查服務(wù)是否可連接

systemctl start chronyd.service
chronyc sources

210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.122.18 6 6 377 24 -802ns[ -44us] +/- 140ms

(如果未生效桥温,請(qǐng)檢查防火墻規(guī)則)


3、利用cobbler實(shí)現(xiàn)系統(tǒng)自動(dòng)化安裝梁丘。

1侵浸、安裝cobbler

[root@centos8 ~]# dnf install epel-releas
[root@centos8 ~]# dnf -y module enable cobbler
[root@centos8 ~]# dnf install cobbler
關(guān)閉selinux 啟動(dòng)httpd和cobbler服務(wù)
setenforce=0
systemctl start cobblerd httpd tftp
systemctl enable cobblerd httpd tftp

2、檢測(cè)cobbler的運(yùn)行環(huán)境,并根據(jù)提示逐步配置cobbler

[root@centos8 ~]# 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 automatic installation 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: 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, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5: reposync is not installed, install yum-utils or dnf-plugins-core
6: yumdownloader is not installed, install yum-utils or dnf-plugins-core
7: debmirror package is not installed, it will be required to manage debian deployments and repositories
8: ksvalidator was not found, install pykickstart
9: 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
10: 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.

    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.

修改/etc/cobbler/settings中的 server 為本機(jī)地址
sed -i.bak s/^server:.*/server:" 192.168.122.18"/ /etc/cobbler/settings

    1. 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.

修改/etc/cobbler/settings中的 next_server 為本機(jī)地址
sed -i.bak s/^next_server:.*/next_server:" 192.168.122.18"/ /etc/cobbler/settings

設(shè)置 SELinux 為disabled,重啟服務(wù)器
sed -i s/^SELINUX=.*/SELINUX=disabled/ /etc/selinux/config

    1. 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, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.

安裝syslinux
[root@centos8 ~]# dnf -y install syslinux
聯(lián)網(wǎng)下載boot引導(dǎo)程序文件
cobbler get-loaders (如果要配置代理在/etc/cobbler/settings文件 proxy_url_ext: 項(xiàng))
如果報(bào)404錯(cuò)誤氛谜,修改/usr/lib/python2.7/site-packages/cobbler/action_dlcontent.py
#content_server = "https://cobbler.github.io/loaders"
content_server = "https://dgoodwin.fedorapeople.org/loaders"
files 列表修改為https://dgoodwin.fedorapeople.org/loaders存在的對(duì)應(yīng)文件列表(README文件可忽略)
cp -a /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot

  • 5 reposync is not installed, install yum-utils or dnf-plugins-core
  • 6 yumdownloader is not installed, install yum-utils or dnf-plugins-core

安裝dnf-plugins-core
[root@centos8 ~]# dnf -y install yum-utils dnf-plugins-core

    1. debmirror package is not installed, it will be required to manage debian deployments and repositories

[root@centos8 ~]# dnf -y install debmirror
安裝后再次執(zhí)行cobbler check會(huì)提示需要在/etc/debmirror.conf 中注釋掉 dists和arches 行
sed -i.bak '/dists\|arches/s/^/#/' /etc/debmirror.conf

    1. ksvalidator was not found, install pykickstar

[root@centos8 ~]# dnf -y install pykickstart

    1. 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

[root@centos8 ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
$1$cobbler$M6SE55xZodWc9.vAKLJs6.
[root@centos8 ~]# sed -i.bak '/default_password_crypted:/s#".*"#"$1$cobbler$M6SE55xZodWc9.vAKLJs6."#' /etc/cobbler/settings

    1. fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

[root@centos8 ~]# dnf -y install fence-agents

  • 重啟服務(wù)器關(guān)閉SELINUX

  • 安裝dhcp服務(wù)

dnf -y install dhcpd
完成后修改修改dhcp配置文 /etc/cobbler/dhcp.template

subnet 192.168.122.0 netmask 255.255.255.0 {
     option routers             192.168.122.1;
     option domain-name-servers 10.98.48.151,10.72.55.103;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.122.100 192.168.122.254;

其他項(xiàng)目默認(rèn)

  • 最后執(zhí)行cobbler sync 掏觉,服務(wù)就搭建完成了

3、導(dǎo)入鏡像進(jìn)行配置

更新/var/lib/cobbler/distro_signatures.json文件
[root@centos8 ~]# cobbler signature update

  • 上傳iso鏡像到服務(wù)器值漫,創(chuàng)建鏡像掛載點(diǎn)

[root@centos8 ~]# mkdir -p /mnt/{7,8,16,18}

  • 鏡像文件掛載到目錄

[root@centos8 ~]# mount /data/CentOS-7-x86_64-Minimal-2009.iso /mnt/7
[root@centos8 ~]# mount /data/ubuntu-16.04.6-server-amd64.iso /mnt/16

執(zhí)行mount -a 掛載命令

  • 把掛載光盤(pán)鏡像的mnt目錄中的內(nèi)容導(dǎo)入到cobbler

[root@centos8 ~]# cobbler import --name=centos7 --path=/mnt/7 --arch=x86_64
[root@centos8 ~]# cobbler import --name=ubuntu16 --path=/mnt/16 --arch=x86_64

[root@centos8 ~]# cobbler distro list
centos7-x86_64
ubuntu16-hwe-x86_64
ubuntu16-x86_64

4澳腹、準(zhǔn)備 kickstart文件,并關(guān)聯(lián)至指定的YUM源

kickstart文件可以安裝一個(gè)模版服務(wù)器,從安裝好的服務(wù)器的/root/anaconda-ks.cfg 復(fù)制后修改

[root@centos8 ~]# cat /var/lib/cobbler/templates/centos7.ks
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
#cdrom
# Use network installation
url --url=$tree     #安裝方式使用cobbler默認(rèn)里的方式
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Use graphical install
graphical       #安裝界面可用圖形或字符 text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=vda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

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

# Root password
rootpw --iscrypted $6$v0W40q80/7HPdeHr$dfHh.SdFzcs8ue.OUl7W5.0ku/xhWPKUXT.qSvYSLdz3C2OImdcRSr2Tde3woAK3qQoh.KWU8F1mYuclBTFIE0
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=wx562635 --password=$6$tGpU7Mbs2bKeqnUu$rqXk6lDnt63cSE5m/LmLiY84HlaGFmgxCfJ27BpAPH2RCsptO6SbwIvaOgQ7W/toOiQvJMvt1qPJS/d47lhrr1 --iscrypted --gecos="wx562635"
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel

%packages
@^minimal
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

# Reboot after installation
reboot

[root@centos8 ~]# cobbler profile remove --name centos7-x86_64
[root@centos8 ~]# cobbler profile add --name=centos7-x86_64 --distro=centos7-x86_64 --template-files=/var/lib/cobbler/templates/centos7.ks --autoinstall=centos7.ks

全部配置完成就可以在服務(wù)器上選擇PXE網(wǎng)絡(luò)啟動(dòng)自動(dòng)安裝系統(tǒng)了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末杨何,一起剝皮案震驚了整個(gè)濱河市酱塔,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌危虱,老刑警劉巖羊娃,帶你破解...
    沈念sama閱讀 211,194評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異埃跷,居然都是意外死亡蕊玷,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,058評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門(mén)弥雹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)垃帅,“玉大人,你說(shuō)我怎么就攤上這事剪勿∶吵希” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,780評(píng)論 0 346
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)酱固。 經(jīng)常有香客問(wèn)我二鳄,道長(zhǎng),這世上最難降的妖魔是什么媒怯? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,388評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮髓窜,結(jié)果婚禮上扇苞,老公的妹妹穿的比我還像新娘。我一直安慰自己寄纵,他們只是感情好鳖敷,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,430評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著程拭,像睡著了一般定踱。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上恃鞋,一...
    開(kāi)封第一講書(shū)人閱讀 49,764評(píng)論 1 290
  • 那天崖媚,我揣著相機(jī)與錄音,去河邊找鬼恤浪。 笑死畅哑,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的水由。 我是一名探鬼主播荠呐,決...
    沈念sama閱讀 38,907評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼砂客!你這毒婦竟也來(lái)了泥张?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,679評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤鞠值,失蹤者是張志新(化名)和其女友劉穎媚创,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體齿诉,經(jīng)...
    沈念sama閱讀 44,122評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡筝野,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,459評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了粤剧。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片歇竟。...
    茶點(diǎn)故事閱讀 38,605評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖抵恋,靈堂內(nèi)的尸體忽然破棺而出焕议,到底是詐尸還是另有隱情,我是刑警寧澤弧关,帶...
    沈念sama閱讀 34,270評(píng)論 4 329
  • 正文 年R本政府宣布盅安,位于F島的核電站唤锉,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏别瞭。R本人自食惡果不足惜窿祥,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,867評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望蝙寨。 院中可真熱鬧晒衩,春花似錦、人聲如沸墙歪。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,734評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)虹菲。三九已至靠胜,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間毕源,已是汗流浹背浪漠。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,961評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留脑豹,地道東北人郑藏。 一個(gè)月前我還...
    沈念sama閱讀 46,297評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像瘩欺,于是被迫代替她去往敵國(guó)和親必盖。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,472評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • 1俱饿、編寫(xiě)腳本歌粥,支持讓用戶自主選擇,使用mysqldump還是xtraback全量備份拍埠。 [root@centos7...
    Gustav_man閱讀 303評(píng)論 0 0
  • ▲就業(yè)班和全程班的小伙伴看這里:(學(xué)習(xí)老王視頻的作業(yè)第29-30節(jié)) 1失驶、編寫(xiě)腳本,支持讓用戶自主選擇枣购,使用mys...
    一心1977閱讀 86評(píng)論 0 0
  • 1嬉探、Nginx+Keepalived實(shí)現(xiàn)站點(diǎn)高可用 Keepalived軟件起初是專為L(zhǎng)VS負(fù)載均衡軟件設(shè)計(jì)的,用...
    N37077ZZ閱讀 329評(píng)論 0 0
  • 系統(tǒng)安裝過(guò)程 MBR:isolinux/boot.cat stage2: isolinux/isolinux.bi...
    毛利卷卷發(fā)閱讀 721評(píng)論 0 1
  • 運(yùn)維自動(dòng)化對(duì)系統(tǒng)管理員十分重要性棉圈,尤其是對(duì)于在服務(wù)器數(shù)量按幾百臺(tái)涩堤、幾千臺(tái)增加的公司而言,單單是裝系統(tǒng)分瘾,如果不通過(guò)自...
    冷漠的辣條閱讀 784評(píng)論 0 0