1争占、實(shí)現(xiàn)sshd免密登錄
(1)生成密鑰對(duì)
[root@centos6 ~/.ssh]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
cd:4f:01:bb:bd:70:67:77:e1:a7:1e:07:62:b6:ca:92 root@centos6.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| o |
| . . . |
| o o .. .|
| S = B +.+|
| B * +o|
| . + o .|
| E. . . o |
| .o . |
+-----------------+
(2)將公鑰發(fā)給服務(wù)器端
[root@centos6 ~/.ssh]#ssh-copy-id 192.168.34.17
The authenticity of host '192.168.34.17 (192.168.34.17)' can't be established.
RSA key fingerprint is d0:ee:06:df:8e:0f:a7:5e:70:ea:b5:e8:76:c0:da:9b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.34.17' (RSA) to the list of known hosts.
root@192.168.34.17's password:
Now try logging into the machine, with "ssh '192.168.34.17'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
(3)測(cè)試使用key登錄
[root@centos6 ~/.ssh]#ssh 192.168.34.17
Last login: Thu Oct 31 16:43:38 2019 from 192.168.34.1
2窥突、編譯安裝dropbear實(shí)現(xiàn)SSH登錄
wget https://matt.ucc.asn.au/dropbear/dropbear-2019.78.tar.bz2
tar xvf dropbear-2019.78.tar.bz2
[root@centos17 dropbear-2019.78]# ./configure
[root@centos17 dropbear-2019.78]# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
[root@centos17 dropbear-2019.78]# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
[root@centos17 ~]# PATH=/usr/local/sbin/:/usr/local/bin/:$PATH
[root@centos17 ~]# mkdir /etc/dropbear
[root@centos17 ~]# dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
[root@centos17 ~]# dropbear -p 2222
3、實(shí)現(xiàn)單個(gè)用戶及用戶組使用sudo執(zhí)行所有命令
[root@centos17 ~]# vim /etc/sudoers.d/test
wang ALL=(ALL) ALL
%mage ALL=(ALL) ALL
4、簡(jiǎn)述rsync用于那些場(chǎng)景,并對(duì)比scp有什么優(yōu)點(diǎn)浓若?
rsync用于在不同的主機(jī)之間同步數(shù)據(jù)渺杉。對(duì)比scp蛇数,它支持增量復(fù)制,而不用全部復(fù)制是越。
5耳舅、搭建DHCP服務(wù),實(shí)現(xiàn)自動(dòng)獲取ip地址
yum -y install dhcp.x86_64
vim /etc/dhcp/dhcpd.conf
default-lease-time 259200;
max-lease-time 518400;
subnet 192.168.34.0 netmask 255.255.255.0 {
range 192.168.34.20 192.168.34.25;
}
systemctl enable dhcpd
systemctl start dhcpd
6倚评、搭建PXE實(shí)現(xiàn)自動(dòng)化安裝系統(tǒng)
(1)安裝要用到的軟件包
yum -y install dhcp.x86_64 tftp-server.x86_64 syslinux system-config-kickstart.noarch httpd
(2)開啟httpd服務(wù)浦徊,并將光盤掛載至相應(yīng)目錄
systemctl start httpd
mkdir -pv centos/{6,7}/os/x86_64/
UUID=2018-05-03-20-55-23-00 /var/www/html/centos/7/os/x86_64 iso9660 defaults 0 0
UUID=2018-06-29-11-20-20-00 /var/www/html/centos/6/os/x86_64 iso9660 defaults 0 0
mount -a
(3)生成應(yīng)答文件,并放到http工作目錄中
可通過圖形工具system-config-kickstart來生成,也可復(fù)制在安裝好的系統(tǒng)/root下的anaconda-ks.cfg天梧,再做適當(dāng)修改
cp anaconda-ks.cfg /var/www/html/kickfile/ks6.cfg
主要做以下修改
#cdrom
url --url="http://192.168.34.17/centos/6/os/x86_64"
text
firewall --disabled
selinux --disabled
clearpart --all --initlabel
zerombr
reboot
part / --fstype="ext4" --size=10240
part /boot --fstype="ext4" --size=512
part /home --fstype="ext4" --size=20480
part swap --fstype="swap" --size=1024
(4)在tftp工作目錄/var/lib/tftpboot/里添加PXE相關(guān)文件
[root@centos6 /var/lib/tftpboot]#tree
.
├── boot.msg
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── pxelinux.0
├── pxelinux.cfg
│ └── default
├── splash.jpg
└── vesamenu.c32
文件夾均需要手動(dòng)創(chuàng)建盔性,
pxelinux.0可通過rpm -ql syslinux來找到并復(fù)制(centos6 是通過rpm -ql syslinux-nonlinux)
其他文件在光盤文件里查找(/misc/cd/isolinux/)
default可復(fù)制光盤文件里的isolinux.cfg,再進(jìn)行相應(yīng)修改:
[root@centos6 /var/lib/tftpboot]#cat pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to PXE install CentOS !
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label CentOS6
menu label ^Install CentOS 6 system
menu default
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://192.168.34.17/kickfile/ks6.cfg
label CentOS7
menu label ^Install CentOS 7 system
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.34.17/kickfile/ks7.cfg
label local
menu label Boot from ^local drive
localboot 0xffff
(5)配置DHCP服務(wù)呢岗,在服務(wù)里指定PXE文件
cat /etc/dhcp/dhcpd.conf
default-lease-time 259200;
max-lease-time 518400;
subnet 192.168.34.0 netmask 255.255.255.0 {
range 192.168.34.20 192.168.34.25;
next-server 192.168.34.6;
filename "pxelinux.0";
}
systemctl restart dhcp
7冕香、搭建Cobbler實(shí)現(xiàn)自動(dòng)化安裝系統(tǒng)
(1)安裝軟件
yum -y install cobbler dhcp
可能會(huì)報(bào)python-pygments相關(guān)的錯(cuò)誤,需要自己去下載安裝后后豫,再重新安裝cobbler
yum -y install python-imaging
wget http://www.rpmfind.net/linux/centos/7.7.1908/os/x86_64/Packages/python-pygments-1.4-10.el7.noarch.rpm
rpm -ivh python-pygments-1.4-10.el7.noarch.rpm
(2)配置/etc/cobbler/settings
可通過cobbler check命令查看需要修改的內(nèi)容悉尾,如需使用cobbler來配置dhcp需要在此文件里添加一條記錄manage_dhcp: 1
default_password_crypted: "$1$3BMeiH.s$mtrUL/wNANnV7z1QUduwU0"
server: 192.168.34.17
next_server: 192.168.34.17
manage_dhcp: 1
(3)從互聯(lián)網(wǎng)自動(dòng)下載相關(guān)文件
cobbler get-loaders
(4)配置dhcp
vim /etc/cobbler/dhcp.template
subnet 192.168.34.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.34.100 192.168.34.254;
}
(5)同步相關(guān)配置
systemctl restart cobblerd
cobbler sync
(6)導(dǎo)入OS
cobbler import --path=/misc/cd/ --name=Centos-7.5-x86_64 --arch=x86_64
(7)導(dǎo)入ks文件
cp ks7_mini.cfg /var/lib/cobbler/kickstarts/
vim /var/lib/cobbler/kickstarts/ks7_mini.cfg
url --url=$tree
(8)將KS和OS關(guān)聯(lián),生成啟動(dòng)新的菜單
cobbler profile add --name=centos-7.5-x86_64_mini --distro=Centos-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7-mini.cfg