目录
4. 实现免密登陆脚本, expect登陆远程主机,将生成的密钥写入到目标主机, expect测试远程登陆。
1. yum私有仓库的实现及博客输出
答:
1.1先安装httpd软件,设置开机自启并现在启动,下载epel仓库和源数据
yum -y install httpd
systemctl enable --now httpd
dnf reposync --repoid=epel --download-metadata -p /var/www/html
1.2可以在登录自己的主机IP/epel看到epel仓库的内容
1.3重新开一台Centos 8.5虚拟机,在/etc/yum,repos.d/test.repo中配置私有epel仓库
1.4利用私有仓库下载GeoIP软件
[15:23:56 root@Rocky ~]#cd /etc/yum.repos.d
[22:09:20 root@Rocky yum.repos.d]#ll
总用量 12
drwxr-xr-x 2 root root 4096 10月 30 17:50 backup
-rw-r--r-- 1 root root 2177 10月 30 20:25 base.repo.bak
-rw-r--r-- 1 root root 901 11月 1 20:32 test.repo
[22:09:21 root@Rocky yum.repos.d]#vi test.repo
[22:11:55 root@Rocky yum.repos.d]#yum install GeoIP
EPEL 259 MB/s | 12 MB 00:00
BaseOS 3.8 MB/s | 3.9 kB 00:00
AppStream 4.2 MB/s | 4.3 kB 00:00
依赖关系解决。
=======================================================================================
软件包 架构 版本 仓库 大小
=======================================================================================
安装:
GeoIP x86_64 1.6.12-7.el8 epel 124 k
安装依赖关系:
GeoIP-GeoLite-data noarch 2018.06-5.el8 epel 552 k
事务概要
=======================================================================================
安装 2 软件包
总下载:676 k
安装大小:1.6 M
确定吗?[y/N]: y
下载软件包:
(1/2): GeoIP-1.6.12-7.el8.x86_64.rpm 9.2 MB/s | 124 kB 00:00
(2/2): GeoIP-GeoLite-data-2018.06-5.el8.noarch.rpm 34 MB/s | 552 kB 00:00
---------------------------------------------------------------------------------------
总计 38 MB/s | 676 kB 00:00
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : GeoIP-GeoLite-data-2018.06-5.el8.noarch 1/2
安装 : GeoIP-1.6.12-7.el8.x86_64 2/2
运行脚本: GeoIP-GeoLite-data-2018.06-5.el8.noarch 2/2
运行脚本: GeoIP-1.6.12-7.el8.x86_64 2/2
/sbin/ldconfig: /etc/ld.so.conf.d/kernel-lt-5.4.215-1.el8.elrepo.x86_64.conf:6: hwcap directive ignored
验证 : GeoIP-1.6.12-7.el8.x86_64 1/2
验证 : GeoIP-GeoLite-data-2018.06-5.el8.noarch 2/2
已安装:
GeoIP-1.6.12-7.el8.x86_64 GeoIP-GeoLite-data-2018.06-5.el8.noarch
完毕!
2. 画图 TCP协议和三次握手及四次挥手
2.1三次握手
2.2四次挥手
3. 静态配置网卡IP,centos/ubuntu实现
3.1centos 8 配置静态网卡IP
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.7
DNS1=10.0.0.2
DNS2=180.76.76.76
ONBOOT=yes
#保存
nmcli connection reload
nmcli connection up eth0
ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:96:8a:a2 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.128/8 brd 10.255.255.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe96:8aa2/64 scope link
valid_lft forever preferred_lft forever
3.2Ubuntu 22.04配置静态IP
root@ubuntu2204:~# vi /etc/netplan/eth1.yaml
network:
renderer: networkd
version: 2
ethernets:
eth1:
addresses:
- 10.0.0.136/24
gateway4: 10.0.0.2
nameservers:
search: [magedu.com, magedu.org]
addresses: [10.0.0.2, 180.76.76.76]
routes:
- to: 192.168.0.0/16
via: 10.0.0.254
root@ubuntu2204:~# netplan apply
root@ubuntu2204:~# ip a
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:e6:4b:a0 brd ff:ff:ff:ff:ff:ff
altname enp2s6
altname ens38
inet 10.0.0.136/24 brd 10.0.0.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fee6:4ba0/64 scope link
valid_lft forever preferred_lft forever
4. 实现免密登陆脚本, expect登陆远程主机,将生成的密钥写入到目标主机, expect测试远程登陆。
#!/usr/bin/bash
#
#*************************************************************
#Author: gao
#QQ: 604555934
#Date: 2022-11-11
#FileName: test1.sh
#Description: The test script
#Copyright (C): 2022 All rights reserved
#*************************************************************
nopass_login () {
NET=10.0.0
user=root
password=808356
declare -a num
num=({1..200})
while ((i<=${#num[*]}));do
#for i in ${num[*]};do
#num[$i]=({1..200})
ip=$NET.$i
read -p "是否继续登录$ip,继续输入y,不继续登录请输入exit" y
[[ $y =~ y ]] && ssh $ip || contiue;
[[ $y =~ exit ]] && break;
expect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
expect "#" { send "exit\n" }
expect eof
EOF
let i++
done
}
install_mysql () {
yum -y install mysql
}
install_apache () {
yum -y install httpd
}
PS3"请输入实现的功能(1-3)"
select MENU in 安装mysql 安装apache 免密钥登录主机 选择结束 ;do
case $REPLY in
1)
echo 正在$MENU
install_mysql
;;
2)
echo 正在$MENU
install_apache
;;
3) echo 正在$MENU
nopass_login
;;
4) echo "选择结束,退出"
break
;;
*) echo "点错了,请重新选择功能"
;;
esac
done
echo "你选择的功能已实现"
}
menu