admin 管理员组

文章数量: 887007

马哥第三周作业

画图 TCP协议和三次握手及四次挥手,可以参考别人的,但是需要自己画一次

三次握手

 四次挥手

 4. 静态配置网卡IP,centos/ubuntu实现

#Centos系列
ifcf-XXX
DEVICE=eth0
NAME=eth0
BOOTROTO=static|dhcp
IPADDR=IP地址
PREFIX=24	||	NETMASK=255.255.255.0
IPADDR=
GATEWAY=
DNS1=
DNS2=
ONBOOT=yes(不写默认为yes)
#centos6生效
service network restart 
#centos7生效
sysemctl restart network
#centos8生效 
[root@localhost ~]# nmcli connection reload                                
[root@localhost ~]# nmcli connection up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)[root@root:/etc/netplan]pwd/etc/netplan/xxx.yaml
#Ubuntu
动态
# This is the network config written by 'subiquity'
network:ethernets:ens33:dhcp4: trueversion: 2静态
# This is the network config written by 'subiquity'
network:version: 2renderer: networkdethernets:ens33:addresses:	#地址- 192.168.230.244/24gateway4: 192.168.230.154	#网关nameservers:			#dns下面的addresses是dnssearch: [baidu]	#域后缀敲www自动补baiduaddresses: [8.8.8.8, 114.114.114.114]netplan apply

5. 实现免密登陆脚本, expect登陆远程主机,将生成的密钥写入到目标主机, expect测试远程登陆。
1)通过shift读取脚本参数
2)通过select来选择功能.例如功能有
- 安装mysql
- 安装apache
- 免密钥登陆主机
当前我们只实现免密钥登陆主机
3)通过函数封装每个功能
4)将免密钥登陆的过程可以重复进行, while 循环实现重复,需要有退出过程。当用户输入exit时,退出免密钥功能。
5)支持输入一批主机免密钥,使用数组 实现

#!/bin//bash
PS3="请选择你需要的操作:(1-4)"
HOST=243
color () {RES_COL=60MOVE_TO_COL="echo -en \\033[${RES_COL}G"SETCOLOR_SUCCESS="echo -en \\033[1;32m"SETCOLOR_FAILURE="echo -en \\033[1;31m"SETCOLOR_WARNING="echo -en \\033[1;33m"SETCOLOR_NORMAL="echo -en \e[0m"echo -n "$1" && $MOVE_TO_COLecho -n "["if [ $2 = "success" -o $2 = "0" ];then ${SETCOLOR_SUCCESS}echo -n $"  OK  "elif [ $2 = "failure" -o $2 = "1" ];then ${SETCOLOR_FAILURE}echo -n $"FAILED"else${SETCOLOR_WARNING}echo $"WARNING"fi${SETCOLOR_NORMAL}echo -n "]"echo 
}
touch_public () {ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa  > /dev/null
}yum_apache () {yum -y install apache
}yum_mysql () {yum -y install mariadb-server
}ssh_host () {ssh 192.168.230.${HOST}
}rpm -q expect &> /dev/null || yum -y install expect &> /dev/null
touch_public
expect << EOF
spawn ssh-copy-id 192.168.230.${HOST}
expect {"yes/no" { send "yes\n";exp_continue }"password:" { send "123\n" }
}
expect eof
EOFssh_host () {ssh 192.168.230.${HOST}
}select service in 安装mysql 安装apache 免密钥登入主机 退出选择; do
case $REPLY in 
1)yum_mysqlcolor mysql  0;;
2)yum_apachecolor apache 0;;
3)ssh_hostcolor 免密登入 0;;
4)echo "成功退出"break;;
*)echo "未知选择,请重新选择";;
esac	
done


 

本文标签: 马哥第三周作业