1.yum私有仓库的实现及博客输出(如何在公司内部搭建一个私有yum源)
1.1以下操作完成后,登录自己主机IP/epel.可以看到repodata文件夹,该文件的路径就是不能上网那台客户端的baseurl。
#安装httpd
[root@Rocky8 ~]#yum -y install httpd
#创建文件夹
[root@Rocky8 ~]#install -d /var/www/html
#启动服务
[root@Rocky8 ~]#systemctl enable --now httpd
#下载软件包
[root@Rocky8 ~]#dnf reposync --repoid=epel --download-metadata -p /var/www/html
2.画图,三次握手和四次挥手
3.yum私有仓库建立和静态配置网卡IP centos/ubuntu实现脚本
#!/bin/bash
#配置颜色提示
set_color () {
RES_COL=60
MOVE_TO_COLOR="echo -en \e[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \e[1;32m [ok]\n"
SETCOLOR_FAILURE="echo -en \e[1;31m [failure]\n"
SETCOLOR_WARNING="echo -en \e[1;33m [worning]\n"
SETCOLOR_NORMAL="echo -en \e[0m"
echo -n "$1" && ${MOVE_TO_COLOR}
if [ $2 = "success" -o $2 = "0" ];then
${SETCOLOR_SUCCESS}
elif [ $2 = "failure" -o $2 = "1" ];then
${SETCOLOR_FAILURE}
else ${SETCOLOR_WARNING}
fi
${SETCOLOR_NORMAL}
}
#选择
set_select () {
if [ $REPLY = "1" ];then
config_store
sleep 1
set_color 创建仓库已完成 0
elif [ $REPLY = "2" ];then
set_NIC
set_color 创建网卡已完成 0
fi
}
#菜单
set_menu () {
PS3="请选择编号:"
select menu in 创建yum私有仓库 静态配置网卡;do
echo "好的亲,请稍后....";sleep 1;break;
done;
}
#创建仓库
config_store () {
cd /etc/yum.repos.d
cat > Rocky-AppStream.repo <<EOF
[appstream]
name=Rocky Linux \$releasever - AppStream
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=\$basearch&repo=AppStream-\$releasever
baseurl=https://mirrors.aliyun.com/rockylinux/8/AppStream/x86_64/os/?spm=a2c6h.25603864.0.0.523a25a4uTEdzJ
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
EOF
cat > Rocky-BaseOS.repo <<EOF
[baseos]
name=Rocky Linux \$releasever - BaseOS
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=\$basearch&repo=BaseOS-\$releasever
baseurl=https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/?spm=a2c6h.25603864.0.0.70932f83AHfBHC
gpgcheck=1
enabled=1
EOF
cat > epel.repo <<EOF
[epel]
name=Rocky Linux \$releasever - Epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch/?spm=a2c6h.25603864.0.0.783227f6FNOisA
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8?spm=a2c6h.25603864.0.0.34275993zdp5wj
EOF
cat > Rocky-Extras.repo <<EOF
[extras]
name=Rocky Linux \$releasever - Extras
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=\$basearch&repo=extras-\$releasever
baseurl=https://mirrors.nju.edu.cn/rocky/8/extras/x86_64/os/
=https://mirrors.aliyun.com/rockylinux/8/extras/x86_64/os/?spm=a2c6h.25603864.0.0.61f21758S1sD3v
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
EOF
}
#配置网卡
set_NIC () {
. /etc/os-release
if [ $ID = "rocky" -o $ID = "centos" ]; then
echo "系统是rocky或centos"
sed -ri '/GRUB_CMDLINE_LINUX/s/"$/ net.ifnames=0"/g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
cd /etc/sysconfig/network-scripts/
rm -f *
read -p "请输入静态ip地址="
IP=$REPLY
read -p "请输入PREFIX="
PREFIX=$REPLY
read -p "请输入GATEWAY="
GATEWAY=$REPLY
cat > ifcfg-eth0 <<EOF
#!/bin/bash
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=$IP
PREFIX=$PREFIX
GATEWAY=$REPLY
EOF
set_color 网卡设置完成,正重启。 0
sleep 1
nmcli con reload
nmcli con up eth0
elif [ $ID = "ubuntu" ]; then
echo "系统是ubuntu"
sed -ri 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0"/g' /etc/default/grub
update-grub
cd /etc/netplan
rm -f *
read -p "请输入网卡名="
NAME=$REPLY
read -p "请输入ip地址[ip/prefix]="
IP=$REPLY
read -p "请输入gateway="
GATEWAY=$REPLY
cat >$NAME.yaml <<EOF
network:
ethernets:
eth0:
addresses:
- $IP
gateway4: $GATEWAY
EOF
set_color 网卡设置完成,正重启。 0
sleep 3
netplan apply
fi
reboot
}
set_menu
set_select
4.免密登录脚本,expect登录远程主机,将生成的秘钥写入到目标主机,expect测试脚本功能
4.1通过shift读取脚本参数
#!/bin/bash
while [ "$1" ];do
COLOR=$1
echo -e "\e[${COLOR}m zhangyongbiao\e[0m"
shift
done
4.2通过select来选择功能及函数封装、免秘钥登录+数组
#!/bin/bash
set_color () {
RES_COL=60
MOVE_TO_COLOR="echo -en \e[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \e[1;32m [ok]\n"
SETCOLOR_FAILURE="echo -en \e[1;31m [failure]\n"
SETCOLOR_WARNING="echo -en \e[1;33m [worning]\n"
SETCOLOR_NORMAL="echo -en \e[0m"
echo -n "$1" && ${MOVE_TO_COLOR}
if [ $2 = "success" -o $2 = "0" ];then
${SETCOLOR_SUCCESS}
elif [ $2 = "failure" -o $2 = "1" ];then
${SETCOLOR_FAILURE}
else ${SETCOLOR_WARNING}
fi
${SETCOLOR_NORMAL}
}
set_menu () {
PS3="亲,请选择:"
select menu in 安装mysql 安装apache 远程登录主机;do
if [ $REPLY = "1" ];then
install_mysql
set_color mysql已安装 0
elif [ $REPLY = "2" ];then
install_apache
set_color apache已安装 0
elif [ $REPLY = "3" ];then
yum -y install expect
set_ctl
fi
break
done
}
install_mysql () {
yum -y install mysql
}
install_apache () {
yum -y install apache
}
set_ctl () {
net=10.0.0
n=1
declare -a numer
numer=({1..10})
while [ $n -lt ${#numer[*]} ];do
expect <<EOF
spawn ssh $net.$n
expect {
"password" { send "zhang0811\n" }
}
EOF
read -p "退出请输exit,继续请输yes:"
if [ $REPLY = "exit" ];then
break;
elif [ $REPLY = "yes" ];then
let n++
fi
done
}
set_menu