第十周作業(yè)

1域滥、總結(jié)ssh常用參數(shù)罚渐、用法
ssh命令是ssh客戶端唇辨,允許實(shí)現(xiàn)對(duì)遠(yuǎn)程系統(tǒng)經(jīng)驗(yàn)證地加密安全訪問(wèn)。ssh客戶端配置文件是:/etc/ssh/ssh_config
ssh命令配合的常見(jiàn)選項(xiàng):
-p port:遠(yuǎn)程服務(wù)器監(jiān)聽(tīng)的端口

 ssh 192.168.1.8 -p 2222

-b 指定連接的源IP

ssh 192.168.1.8 -p 2222 -b 192.168.1.88

-v 調(diào)試模式

ssh 192.168.1.8 -p 2222 -v

-C 壓縮方式
-X 支持x11轉(zhuǎn)發(fā)
支持將遠(yuǎn)程linux主機(jī)上的圖形工具在當(dāng)前設(shè)備使用
-t 強(qiáng)制偽tty分配锉罐,如:ssh -t remoteserver1 ssh -t remoteserver2 ssh
remoteserver3
-o option 如:-o StrictHostKeyChecking=no
-i <file> 指定私鑰文件路徑帆竹,實(shí)現(xiàn)基于key驗(yàn)證,默認(rèn)使用文件: ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, /.ssh/id_ed25519氓鄙,/.ssh/id_rsa等

2馆揉、總結(jié)sshd服務(wù)常用參數(shù)。
服務(wù)器端的配置文件: /etc/ssh/sshd_config
常用參數(shù):

Port                                                                 #端口號(hào)
ListenAddress ipLoginGraceTime 2m            #寬限期
PermitRootLogin yes                     #默認(rèn)ubuntu不允許root遠(yuǎn)程ssh登錄
StrictModes yes                               #檢查.ssh/文件的所有者抖拦,權(quán)限等
MaxAuthTries   6     
MaxSessions  10                                   #同一個(gè)連接最大會(huì)話
PubkeyAuthentication yes                       #基于key驗(yàn)證
PermitEmptyPasswords no                     #空密碼連接
PasswordAuthentication yes                    #基于用戶名和密碼連接
GatewayPorts no
ClientAliveInterval 10                                        #單位:秒
ClientAliveCountMax 3                                     #默認(rèn)3
UseDNS yes                                                         #提高速度可改為no
GSSAPIAuthentication yes                              #提高速度可改為no
MaxStartups                                          #未認(rèn)證連接最大值升酣,默認(rèn)值10
Banner /path/file                     #以下可以限制可登錄用戶的辦法:
AllowUsers user1 user2 user3
DenyUsers
AllowGroups

(科學(xué)上網(wǎng)的方法不要往博客寫(xiě),訪問(wèn)量超過(guò)一萬(wàn)态罪,博客會(huì)被封噩茄。)
3、PAM和google模塊實(shí)現(xiàn)ssh雙因子安全驗(yàn)證复颈。

4绩聘、使用chrony實(shí)現(xiàn)內(nèi)網(wǎng)時(shí)間同步(一臺(tái)node1從外網(wǎng)同步時(shí)間,其余機(jī)器從node1同步時(shí)間)耗啦。
node1:10.0.0.7 node2:10.0.08
node1:
安裝chrony

yum install chrony -y

修改chrony.conf文件凿菩,加入時(shí)間服務(wù)器為 ntp.aliyun.com, 修改允許10.0.0.0網(wǎng)段的主機(jī)同步。

[root@node1 ~]# cat /etc/chrony.conf 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.aliyun.com iburst
......

# Allow NTP client access from local network.
allow 10.0.0.0/24

# Serve time even if not synchronized to a time source.
local stratum 10

重啟服務(wù)

 systemctl restart chronyd
[root@node1 ~]# chronyc 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               
===============================================================================
^* 203.107.6.88                  2   6   377    55   -243us[ -531us] +/-   22ms

node2
安裝chrony

[root@node2 ~]# dnf install chrony -y

修改chrony.conf的同步主機(jī)

pool 10.0.0.7 iburst 
[root@node2 ~]# chronyc 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               
===============================================================================
^* 10.0.0.7                      3   6    17    12  -2982ns[  -38us] +/-  134ms

5帜讲、利用cobbler實(shí)現(xiàn)系統(tǒng)自動(dòng)化安裝衅谷。
環(huán)境準(zhǔn)備
兩臺(tái)主機(jī)
一臺(tái)主機(jī):CentOS 7 充當(dāng) Cobbler,http似将,dhcp获黔,tftp 服務(wù)器,并關(guān)閉防火墻和SELinux
一臺(tái)主機(jī):充當(dāng)測(cè)試機(jī)在验,用于實(shí)現(xiàn)自動(dòng)化安裝Linux系統(tǒng)
安裝相關(guān)包并啟動(dòng)服務(wù)

[root@centos7 ~]#yum install cobbler dhcp -y
[root@centos7 ~]#systemctl enable --now cobblerd httpd tftp dhcpd

** 修改cobbler相關(guān)的配置 **

[root@localhost ~]#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 : ksvalidator was not found, install pykickstart
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.

#默認(rèn)安裝好的系統(tǒng)root密碼為cobbler


#根據(jù)以上提示玷氏,只需要做1,2腋舌,8這三項(xiàng)即可盏触,修改下面四行
[root@centos7 ~]#vim /etc/cobbler/settings
next_server:< tftp服務(wù)器的 IP 地址>
server:<cobbler服務(wù)器的 IP 地址>
manage_dhcp:1  #設(shè)置為1,表示通過(guò)cobbler生成dhcpd.conf配置文件
[root@centos7 ~]#systemctl restart cobblerd

實(shí)現(xiàn)dhcp服務(wù)

#修改dhcp的模版文件下面的行块饺,用來(lái)生成dhcp的配置文件
#vi /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 114.114.114.114;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.200 10.0.0.250;   

[root@localhost ~]#cobbler sync
task started: 2021-08-16_123044_sync
task started (id=Sync, time=Mon Aug 16 12:30:44 2021)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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 ***
[root@localhost ~]#systemctl start dhcpd

下載啟動(dòng)的相關(guān)文件

#cobbler get-loaders

[root@localhost ~]#ll /var/lib/cobbler/loaders
total 0
-rw-r--r-- 1 root root 0 Aug 16 12:33 COPYING.elilo
-rw-r--r-- 1 root root 0 Aug 16 12:36 COPYING.syslinux
-rw-r--r-- 1 root root 0 Aug 16 12:35 COPYING.yaboot
-rw-r--r-- 1 root root 0 Aug 16 12:36 elilo-ia64.efi
-rw-r--r-- 1 root root 0 Aug 16 12:40 grub-x86_64.efi
-rw-r--r-- 1 root root 0 Aug 16 12:40 grub-x86.efi
-rw-r--r-- 1 root root 0 Aug 16 12:39 menu.c32
-rw-r--r-- 1 root root 0 Aug 16 12:39 pxelinux.0
-rw-r--r-- 1 root root 0 Aug 16 12:32 README
-rw-r--r-- 1 root root 0 Aug 16 12:37 yaboot

[root@localhost loaders]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│   └── grub
│       └── menu.lst
├── etc
├── grub
│   ├── efidefault
│   ├── grub-x86_64.efi
│   ├── grub-x86.efi
│   └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│   └── default
├── s390x
│   └── profile_list
└── yaboot

10 directories, 10 files

修改菜單的標(biāo)題信息

[root@localhost loaders]#vim /etc/cobbler/pxe/pxedefault.template

DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://www.magedu.com/    

#cobbler sync

導(dǎo)入CentOS系統(tǒng)的安裝文件赞辩,生成相應(yīng)的YUM源

[root@localhost misc]#mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost misc]#df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  100G  1.4G   99G   2% /
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.8M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-data   50G   33M   50G   1% /data
/dev/sda1               1014M  146M  869M  15% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sr0                 4.3G  4.3G     0 100% /mnt

#cobbler import --name=centos-7.6-x86_64 --path=/mnt --arch=x86_64

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

root@localhost kickstarts]#cat /var/lib/cobbler/kickstarts/centos7.cfg
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=$tree #注意此行必須指定
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network --hostname=centos7-test
rootpw "Centos" 
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@^minimal-environment
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

#將kickstart文件,關(guān)聯(lián)指定的YUM源和生成菜單列表
#cobbler profile add --name=CentOS-7.6_test --distro=CentOS-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg

#刪除默認(rèn)生成的菜單
#cobbler profile remove --name=centos-7.6-x86_64

[root@localhost kickstarts]#cobbler profile list
   CentOS-7.6_test

測(cè)試客戶端基于Cobbler實(shí)現(xiàn)自動(dòng)安裝

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末刨沦,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子膘怕,更是在濱河造成了極大的恐慌想诅,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異来破,居然都是意外死亡篮灼,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)徘禁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)诅诱,“玉大人,你說(shuō)我怎么就攤上這事送朱∧锏矗” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵驶沼,是天一觀的道長(zhǎng)炮沐。 經(jīng)常有香客問(wèn)我,道長(zhǎng)回怜,這世上最難降的妖魔是什么大年? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮玉雾,結(jié)果婚禮上翔试,老公的妹妹穿的比我還像新娘。我一直安慰自己复旬,他們只是感情好垦缅,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著赢底,像睡著了一般失都。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上幸冻,一...
    開(kāi)封第一講書(shū)人閱讀 51,598評(píng)論 1 305
  • 那天粹庞,我揣著相機(jī)與錄音,去河邊找鬼洽损。 笑死庞溜,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的碑定。 我是一名探鬼主播流码,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼延刘!你這毒婦竟也來(lái)了漫试?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤碘赖,失蹤者是張志新(化名)和其女友劉穎驾荣,沒(méi)想到半個(gè)月后外构,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡播掷,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年审编,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片歧匈。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡垒酬,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出件炉,到底是詐尸還是另有隱情勘究,我是刑警寧澤,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布妻率,位于F島的核電站乱顾,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏宫静。R本人自食惡果不足惜走净,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望孤里。 院中可真熱鬧伏伯,春花似錦、人聲如沸捌袜。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)虏等。三九已至弄唧,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間霍衫,已是汗流浹背候引。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留敦跌,地道東北人澄干。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像柠傍,于是被迫代替她去往敵國(guó)和親麸俘。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

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

  • 1惧笛、實(shí)現(xiàn)sshd免密登錄 2从媚、編譯安裝dropbear實(shí)現(xiàn)SSH登錄 3、實(shí)現(xiàn)單個(gè)用戶及用戶組使用sudo執(zhí)行所有...
    ritch閱讀 501評(píng)論 0 0
  • 1患整、PAM和google模塊實(shí)現(xiàn)ssh雙因子安全驗(yàn)證拜效。 在手機(jī)應(yīng)用市場(chǎng)搜索:身份驗(yàn)證器或authenticator...
    阿杜ddq閱讀 376評(píng)論 0 0
  • 1炭懊、簡(jiǎn)述DNS服務(wù),并搭建DNS服務(wù)器拂檩,實(shí)現(xiàn)主從,子域授權(quán)嘲碧。 DNS是“Domain Name System"的縮...
    衛(wèi)清華閱讀 252評(píng)論 0 0
  • 1愈涩、配置chrony服務(wù)望抽,實(shí)現(xiàn)服務(wù)器時(shí)間自動(dòng)同步 chrony介紹 配置文件chrony.conf (1)serv...
    毅_閱讀 983評(píng)論 0 1
  • 全程和就業(yè)1、配置chrony服務(wù)履婉,實(shí)現(xiàn)服務(wù)器時(shí)間自動(dòng)同步 編輯/etc/chrony.conf文件把ntp服務(wù)器...
    letsgoheat_c1dc閱讀 175評(píng)論 0 0