云计算 SRE 运维 —— 第三周

yum私有仓库

下载工具包

[root@test01 ~]# yum install -y createrepo yum-utils

制作私有yum源

# 安装httpd
[root@test01 ~]# yum install -y httpd

# 列出当前yum源列表
[root@test01 ~]# yum repolist 
repo id                                            repo name
AppStream                                          AppStream
BaseOS                                             BaseOS
epel                                               epel
extras                                             extras

# 下载镜像源到本地
[root@test01 ~]# yum reposync --repoid=extras --download-metadata -p /var/www/html/mirros/
[root@test01 ~]# yum reposync --repoid=BaseOS --download-metadata -p /var/www/html/mirros/
[root@test01 ~]# yum reposync --repoid=epel --download-metadata -p /var/www/html/mirros/

# 移除其他yum源文件
[root@test01 ~]# mkdir /opt/repo; mv /etc/yum.repos.d/* /opt/repo/

# 创建yum源文件
[root@test01 ~]# cat > /etc/yum.repos.d/test.repo << EOF
> [test]
> name=test
> baseurl=http://10.0.0.11/mirros/extras
> gpgcheck=0
> enable=1
> EOF

# 启动httpd服务
[root@test01 ~]# systemctl enable --now httpd

# 列出当前yum源列表
[root@test01 ~]# yum repolist
repo id                                             repo name
test                                                test

图解TCP

三次握手

image.png

TCP建立连接(3次握手)

  1. 客户端向服务器发送同步请求报文

  2. 服务器收到报文,发送同步确认报文

  3. 客户端收到报文,发送确认报文

四次挥手

image.png

TCP释放连接(4次挥手)

  1. 客户端发送释放连接请求报文

  2. 服务器收到报文,发送确认报文

  3. 服务器发送释放连接请求报文

  4. 客户端接收报文,发送确认报文

配置静态IP

CentOS & Rocky

# 修改网卡配置文件
[root@test01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
BOOTPROTO=static		# 静态IP
NAME=eth0
DEVICE=eth0
ONBOOT=yes				# 开机自启
IPADDR=10.0.0.11		# 静态IP
PREFIX=24				# 子网掩码长度
GATEWAY=10.0.0.2		# 网关
DNS1=10.0.0.2			# DNS
DNS2=180.76.76.76

# 生效
[root@test01 ~]# nmcli connection reload 
[root@test01 ~]# nmcli connection up eth0

Ubuntu

[root@ubuntu ~]# cd /etc/netplan/
[root@ubuntu netplan]# cat eth0.yaml 
# This is the network config written by 'subiquity'
network:
  version: 2
  renderer: networkd
  ethernets: 					# 网卡名称
    eth0:
      addresses:  
      - 10.0.0.20/24			# 静态IP
      gateway4: 10.0.0.2		# 网关
      nameservers: 
        addresses: 
        - 10.0.0.2				# DNS
        
# 使配置生效
[root@ubuntu netplan]# netplan apply 

expect登陆远程主机

#!/bin/bash
# **********************************************************
#
# * Author        : 彤彤爱吃薯条
# * Create time   : 2022-10-18 12:33
# * Filename      : test.sh
# * Description   : 
#
# **********************************************************

MYIP=`ip address show eth0 | sed -n 3p | awk -F '[ /]+' '{print $3}'`
PASS=000000


. /etc/os-release


function color  {
    RES_COL=60
    MOVE_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_COL
    echo -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 -n $"  WARNING  "
    fi
    ${SETCOLOR_NORMAL}
    echo -n "]"
    echo
}


function ssh_login {
    if [ $ID = "centos" -o $ID = "rocky" ]; then
        yum install -y sshpass
    else
        apt update
        apt install -y sshpass
    fi

    if [ $? -eq 0 ]; then
        color "sshpass安装成功" 0
    else
        color "sshpass安装失败,请检查网络配置" 1
        exit
    fi


    rm -rf /root/.ssh/* &> /dev/null
    ssh-keygen -P "" -f /root/.ssh/id_rsa -t rsa
    sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no root@$MYIP

    while (true); do
        read -p "请输入接收秘钥的主机IP(输入exit退出): " IP1
        if [ $IP1 = "exit" ]; then
            break
        else
            sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh/* root@$IP1:/root/.ssh/
        fi
    done

    echo -e "\n"

    read -p "请输入需要远程登录的IP(输入exit退出): " IP2
        if [ $IP2 = "exit" ]; then
            exit
        else
            ssh root@$IP2
        fi
}


function install_httpd {
    if [ $ID = "centos" -o $ID = "rocky" ]; then
        rpm -q httpd || yum install -y httpd
    else
        apt update
        dpkg -s httpd || apt install -y httpd
    fi

    if [ $? -eq 0 ]; then
        color "HTTPD安装成功" 0
    else
        color "HTTPD安装失败,请检查网络配置" 1
        exit
    fi
}

function install_mysql {
    if [ $ID = "centos" -o $ID = "rocky" ]; then
        yum install -y mysql-server mysql
    else
        apt update
        apt install -y mysql-server mysql
    fi

    if [ $? -eq 0 ]; then
        color "MySQL安装成功" 0
    else
        color "MySQL安装失败,请检查网络配置" 1
        exit
    fi
}


PS3="请选择要执行的操作: "

select MENU in 免秘钥登录主机 安装HTTPD 安装MySQL 退出; do
    case $REPLY in
        1)
            ssh_login
            ;;
        2)
            install_httpd
            ;;
        3)
            install_mysql
            ;;
        4)
            echo "程序退出!"
            break
            ;;
        *)
            echo "别乱来!"
            ;;
    esac
done

posted @ 2022-11-24 03:20  C-FIKT  阅读(42)  评论(0)    收藏  举报