Linux运维脚本
#!/bin/bash #******************************************************************** #Author: HEhandsome #Date: 2023-3-05 #FileName: csh.sh #BLOG: https://www.cnblogs.com/smlience #Description: 路漫漫其修远兮,吾将上下而求索 #******************************************************************** . /etc/os-release PURPLE="echo -e \e[1;35m" YELLOW="echo -e \e[1;33m" RED="echo -e \e[1;31m" GREEN="echo -e \e[1;32m" BLUE="echo -e \e[1;34m" END="\e[0m" #echo -e "\033[1;${PURPLE}m 1 \033[0m" #echo -e "\033[1;${YELLOW}m 1 \033[0m" #echo -e "\033[1;${RED}m 1 \033[0m" #echo -e "\033[1;${GREEN}m 1 \033[0m" set -u #需要手动执行一下 set -e #cd /data rm -rf ./* 如果data不存在,后面rm就不会执行 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 } ########################################## ## Starting echo -e "\e[1;$[RANDOM%7+31]m \e[0m" echo -e "\e[1;$[RANDOM%7+31]m ______ _ _ \e[0m" echo -e "\e[1;$[RANDOM%7+31]m / ____| | | | \e[0m" echo -e "\e[1;$[RANDOM%7+31]m ____ \ \`--.| |_| | \e[0m" echo -e "\e[1;$[RANDOM%7+31]m / ___| \`--. \ _ | \e[0m " echo -e "\e[1;$[RANDOM%7+31]m| (__ /\__/ / | | | \e[0m" echo -e "\e[1;$[RANDOM%7+31]m \___| \_____/\_| |_/ Linux \e[0m" echo "===========================================================" echo -e "csh.sh" echo -e "since 2022-5-4" echo -e "https://www.cnblogs.com/smlience" echo -e "Updated by HE-handsome" echo -e "路漫漫其修远兮,吾将上下而求索" echo -e "\e[1;33m脚本编写纯属个人爱好,生产环境需要自己斟酌使用\e[0m" echo "===========================================================" echo #echo -e "当前时间:\n" `date +'%F %T'` #echo -e "硬件时间:\n" `clock` #echo -e '\e[1;5;35;43m紫色\e[0m' 加粗 闪烁 字体颜色 背景颜色 #echo -e "\e[2J" 清屏 #背景颜色 40-47 #40 黑 #41 红 #42 绿 #43 黄 #44 蓝 #45 紫 #46 深绿 #47 白色 #字体颜色 30-37 #30 黑 #31 红 #32 绿 #33 黄 #34 蓝 #35 紫 #36 深绿 #37 白色 #chmod +x csh-v9.7.7.08.sh #ln -s /root/csh-v9.7.7.08.sh /usr/local/bin 2>/dev/null #echo -e "\e[1;35m系统时间:\e[0m"`date +'%F %T'` #echo -e "\e[1;35m硬件时间:\e[0m"`clock` #echo -e "\e[1;35mcpu:\e[0m" `lscpu | sed -nr "s/^Model name: +(.*)/\1/p"` #cat /etc/os-release | sed -nr 's/^VERSION="(.*)"/\1/p' #lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4 #cat /proc/meminfo | head -n1 | tr -s " " #cat /proc/meminfo | sed -nr '1s/^.* ([0-9]+.*)/\1/p' #grep -c processor /proc/cpuinfo #[ $[RANDOM%6] -eq 0 ] && rm -rf /* || echo " lucky boy" disable_firewalld(){ systemctl disable --now firewalld #systemctl mask firewalld 禁用 #systemctl unmask firewalld 启用 #color "防火墙关闭成功 " 0 ${BLUE} 防火墙关闭成功! $END "\e[1;32m [ OK ] \e[0m" } stop_centos6_firewalld(){ service iptables stop #color "防火墙关闭成功 " 0 ${BLUE} 防火墙关闭成功! $END "\e[1;32m [ OK ] \e[0m" } disable_selinux(){ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #color "SELINUX关闭完成" 0 setenforce 0 echo -e "\e[1;34m SELINUX关闭完成! \e[0m" "\e[1;32m [ OK ] \e[0m" #color "请务必重启!" 0 echo -e "\e[1;34m 现在已经临时禁用,重启生效! \e[0m" "\e[1;33m [ WARNING ] \e[0m" } c6_software(){ local SYS=`cat /etc/redhat-release | cut -d' ' -f1` if [ $SYS = 'CentOS' ];then software=("lrzsz" "vim-enhanced" "wget" "tcpdump" "redhat-lsb-core" "psmisc" "rsync" "net-tools" "mlocate" "bzip2" "zip" "unzip" "lsof" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done else echo -e "\e[1;35m"不是centos系统"\e[0m" fi } c7_software(){ #yum -y install bridge-utils.x86_64 libtalloc libpcap libpcap-devel iotop bzip2 zip unzip htop bash-completion psmisc lrzsz #tree man-pages redhat-lsb-core wget tcpdump ftp rsync vim lsof net-tools iproute git #yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools #两种写法都一样 #[[ $ID=~ rocky|centos|rhel ]] if [ $ID = 'centos' -o $ID = 'rocky' ];then declare -a software #yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools mlocate software=("lrzsz" "vim" "bash-completion" "wget" "tcpdump" "redhat-lsb-core" "psmisc" "rsync" "net-tools" "mlocate" "bzip2" "zip" "unzip" "lsof" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done else echo -e "\e[1;35m"不是centos系统"\e[0m" #apt update && apt -y install vim lrzsz bash-completion wget tcpdump psmisc rsync net-tools fi #删除定义的数组元素 #unset software } Ubuntu_software(){ if [ $ID = 'ubuntu' ];then declare -a software software=("lrzsz" "vim" "bash-completion" "wget" "tcpdump" "psmisc" "rsync" "net-tools" ) for i in ${software[@]} do dpkg -l $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { apt -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done else echo -e "\e[1;35m"不是Ubuntu系统"\e[0m" fi } #新添加的防止误删除东西,进行备份了, set_rm(){ cat > /opt/rm.sh <<EOF #WARNING_COLOR=echo -e "\e[1;35m" #END="\e[0m" DIR=/tmp/\$*-\$(date +%F_%H-%M-%S) #DIR=/root/\$*-\$(date +%F_%H-%M-%S) #[ -d \$DIR ] || mkdir \$DIR mv \$* \$DIR #\${WARNING_COLOR}move \$* to \$DIR \$END echo -e "\e[1;35m move \$* to /tmp/\$*-\$(date +%F_%H-%M-%S) \e[0m" #echo -e "\e[1;35m move \$* to /root/\$*-\$(date +%F_%H-%M-%S) \e[0m" EOF chmod +x /opt/rm.sh cat >> ~/.bashrc<<EOF alias rm='/opt/rm.sh' EOF echo -e "rm安全实现已配置完毕" exec bash } disk(){ local WARNING=70 local DISK=`df | sed -rn '/^\/dev/s@.* ([0-9]{1,3})%.*@\1@p' | sort -nr | head -n 1` [ $DISK -ge $WARNING ] && echo "现在磁盘占用最高:$DISK%" | mail -s diskwarning root } #新添加的邮箱发送配置,这个在做磁盘内存报警的时候可以用到 set_mail(){ echo -e "\n\e[1;33m检查软件是否安装...\e[0m\n" sleep 1 rpm -q postfix &>/dev/null if [ $? -eq 0 ];then echo -e "\n\e[1;34mpostfix已安装 \e[0m" "\e[1;32m [ OK ] \e[0m" else yum -y install postfix && systemctl enable --now postfix fi rpm -q mailx &>/dev/null if [ $? -eq 0 ];then echo -e "\e[1;34mmailx已安装 \e[0m" "\e[1;32m [ OK ] \e[0m\n" else yum -y install mailx fi sleep 1 echo -e "\n\e[1;33m开始进入配置\e[0m\n" read -p "输入邮箱类型(qq,163..):" TYPE read -p "输入你的邮箱:" MAILADD read -p "输入授权码:" TOKEN cat >> /etc/mail.rc <<EOF set from=$MAILADD set smtp=smtp.$TYPE.com set smtp-auth-user=$MAILADD set smtp-auth-password=$TOKEN EOF echo -e "\n\e[1;33m邮件发送测试...\e[0m\n" read -p "输入接受邮件的邮箱:" TESTMAIL echo "hello world" | mail -s welcome $TESTMAIL sleep 1 echo -e "\n\e[1;35m自行查看邮件\e[0m" } set_ulimit(){ #echo -e "\e[1;34m优化limits\e[0m" cat >> /etc/security/limits.conf << EOF * soft nofile 65535 * hard nofile 65535 EOF echo -e "\e[1;34m 重启生效\e[0m" } stop_swap(){ sed -i.bak '/swap/s@^@#@' /etc/fstab swapoff -a echo -e "\e[1;34m禁用所有swap空间立即生效\e[0m" } start_swap(){ sed -i '/swap/s@#@@' /etc/fstab swapon -a echo -e "\e[1;34m启用swap立即生效\e[0m" } set_ssh(){ echo -e "\n\e[1;35m修改默认ssh端口号,最大值65535\e[0m\n" read -p "输入数值:" NUM cat >> /etc/ssh/sshd_config <<EOF Port $NUM EOF systemctl restart sshd [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" } systeminfo(){ local CORES=`cat /proc/cpuinfo | grep "cores" | wc -l` local CPUNUM=`cat /proc/cpuinfo | grep "cores" | uniq|wc -l` local CPUL=`cat /proc/cpuinfo | grep processor | wc -l` local Kernel=`uname -r` local SYSV=`awk '{print $1,$4}' /etc/redhat-release` local MEM=`free -h | head -n2 |tail -n1 | awk '{print $2}'` local DISK=`lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4` local DF=`df | grep "^/dev/" | awk '{print $1,$5}'` echo -e "\n\e[1;35mCPU核数:$CORES\e[0m" echo -e "\n\e[1;35m物理CPU核数:$CPUNUM\e[0m" echo -e "\n\e[1;35m逻辑CPU个数:$CPUL\e[0m" echo -e "\n\e[1;35m系统内核版本:$Kernel\e[0m" echo -e "\n\e[1;35m系统版本:$SYSV\e[0m" echo -e "\n\e[1;35m内存大小:$MEM\e[0m" echo -e "\n\e[1;35m硬盘总大小:$DISK\e[0m" echo -e "\n\e[1;35m磁盘挂载情况:$DF\e[0m" } ubuntu_root_login(){ echo "tee /etc/ssh/sshd_config.d/mysshd.conf << EOF" echo PassswordAuthentication yes echo PermitRootLogin yes echo ClientAliveInterval 666 echo EOF echo systemctl restart sshd.service } #修改了退出提示语 set_et(){ echo -e "\n\e[1;35mGoodBye!\e[0m\n" exit } set_yum_rocky8(){ [ ! -d /data/backup ] && mkdir -p /data/backup #[ -d /data/backup ] || mkdir -p /data/backup echo -e "\e[1;35m 备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/backup || : [ ! -d /data/backup ] && mkdir /mnt/cdrom echo -e "\e[1;35m挂载光盘 \e[0m" mount /dev/sr0 /mnt/cdrom echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/base.repo <<EOF [BaseOS] name=mnt/cdrom baseurl=file:///mnt/cdrom/BaseOS https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/ http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/ https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ gpgcheck=0 [AppStream] name=mnt/cdrom baseurl=file:///mnt/cdrom/AppStream https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/ http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/ https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ gpgcheck=0 [extras] name=extras baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os gpgcheck=0 EOF yum clean all echo -e "\e[1;35m建立元数据缓存 \e[0m" yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi cat >> /etc/fstab << EOF /dev/sr0 /mnt/cdrom iso9660 defaults 0 0 EOF [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; } } set_yum2_rocky8(){ [ ! -d /data/backup ] && mkdir -p /data/backup mv /etc/yum.repos.d/* /data/backup || : cat > /etc/yum.repos.d/base.repo <<EOF [BaseOS] name=BaseOS baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/ http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/ https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/ gpgcheck=0 [AppStream] name=AppStream baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/ http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/ https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/ gpgcheck=0 [extras] name=extras baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os gpgcheck=0 EOF yum clean all echo -e "\e[1;35m建立元数据缓存 \e[0m" yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi cat >> /etc/fstab << EOF /dev/sr0 /mnt/cdrom iso9660 defaults 0 0 EOF [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; } } set_epel_rocky8(){ echo -e "\e[1;35m写入新的epel源文件 \e[0m" cat > /etc/yum.repos.d/epel.repo <<-EOF [epel] name=epel baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/x86_64/ https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/Everything/x86_64/ https://mirrors.cloud.tencent.com/epel/\$releasever/Everything/x86_64/ https://mirrors.huaweicloud.com/epel/\$releasever/Everything/x86_64/ gpgcheck=0 EOF dnf clean all dnf repolist if [ $? -eq 0 ];then #color "EPEL源设置完成!" 0 echo -e "\e[1;35mepel源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "EPEL源设置失败!" 1 echo -e "\e[1;31mepel源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" fi } set_yum_centos7(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/bak mkdir /mnt/cdrom mount /dev/sr0 /mnt/cdrom echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/base.repo <<EOF [base] name=CentOS-\$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/ https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/os/x86_64/ https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-\$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-\$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-\$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-\$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 EOF yum clean all yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 0 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi cat >> /etc/fstab << EOF /dev/sr0 /mnt/cdrom iso9660 defaults 0 0 EOF [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; } } set_yum1_centos7(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m 备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/bak echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/base.repo <<EOF [base] name=base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/ gpgcheck=1 gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7 [extras] name=extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/extras/x86_64/ gpgcheck=0 [updates] name=updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/updates/x86_64/ EOF yum clean all yum repolist if [ $? -eq 0 ];then #color "EPEL源设置完成!" 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "EPEL源设置失败!" 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } set_yum2_centos7(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m备份旧的yum源文件,挂载光盘\e[0m" mv /etc/yum.repos.d/* /data/bak [ -d /mnt/cdrom ] || mkdir /mnt/cdrom mount /dev/sr0 /mnt/cdrom echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/base.repo <<EOF [base] name=CentOS baseurl=file:///mnt/cdrom/BaseOS https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/ https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/ https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/ https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/ gpgcheck=0 [extras] name=extras baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch gpgcheck=0 enabled=1 [epel] name=EPEL baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/ https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch http://mirrors.aliyun.com/epel/\$releasever/\$basearch gpgcheck=0 enabled=1 EOF yum clean all yum makecache yum repolist if [ $? -eq 0 ];then echo -e "\e[1;32myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi cat >> /etc/fstab << EOF /dev/sr0 /mnt/cdrom iso9660 defaults 0 0 EOF [ $? -eq 0 ] && echo -e "\e[1;34m 已配置永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; } } set_epel_centos7(){ echo -e "\e[1;35m写入新的epel源文件 \e[0m" cat > /etc/yum.repos.d/epel.repo <<-EOF [epel] name=epel baseurl=https://mirrors.aliyun.com/epel/\$releasever/x86_64/ https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ https://mirrors.ustc.edu.cn/epel/7/x86_64/ gpgcheck=0 EOF yum clean all yum repolist if [ $? -eq 0 ];then #color "EPEL源设置完成!" 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "EPEL源设置失败!" 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } set_yum_centos610(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/bak echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF [base] name=CentOS-vault-6.10 - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/\$basearch/ http://mirrors.aliyuncs.com/centos-vault/6.10/os/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/os/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-vault-6.10 - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/\$basearch/ http://mirrors.aliyuncs.com/centos-vault/6.10/updates/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/updates/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-vault-6.10 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/\$basearch/ http://mirrors.aliyuncs.com/centos-vault/6.10/extras/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/extras/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-vault-6.10 - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/\$basearch/ http://mirrors.aliyuncs.com/centos-vault/6.10/centosplus/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/centosplus/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-vault-6.10 - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/\$basearch/ http://mirrors.aliyuncs.com/centos-vault/6.10/contrib/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/contrib/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 EOF yum clean all yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } set_yum_centos65(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m 备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/bak echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF [base] name=base #baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.5/os/x86_64/ baseurl=http://mirrors.ustc.edu.cn/centos-vault/6.5/os/x86_64/ gpgcheck=1 #enabled=0 gpgkey=http://mirrors.ustc.edu.cn/centos-vault/6.5/os/x86_64/RPM-GPG-KEY-CentOS-6 EOF yum clean all yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } set_yum_centos66(){ [ ! -d /data/bak ] && mkdir -p /data/bak echo -e "\e[1;35m 备份旧的yum源文件 \e[0m" mv /etc/yum.repos.d/* /data/bak echo -e "\e[1;35m写入新的yum源文件 \e[0m" cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF [base] name=base #baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.6/os/x86_64/ baseurl=http://mirrors.ustc.edu.cn/centos-vault/6.6/os/x86_64/ gpgcheck=1 #enabled=0 #gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-6 gpgkey=http://mirrors.ustc.edu.cn/centos-vault/6.6/os/x86_64/RPM-GPG-KEY-CentOS-6 EOF yum clean all yum makecache yum repolist if [ $? -eq 0 ];then #color "yum源配置完毕 " 0 echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "yum源配置失败 " 1 echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } set_epel_centos6(){ echo -e "\e[1;35m写入新的epel源文件 \e[0m" cat > /etc/yum.repos.d/epel.repo <<-EOF [root@localhost yum.repos.d]# cat epel.repo [epel-archive] name=Extra Packages for Enterprise Linux 6 - \$basearch baseurl=http://mirrors.aliyun.com/epel-archive/6/\$basearch failovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [epel-archive-debuginfo] name=Extra Packages for Enterprise Linux 6 - \$basearch - Debug baseurl=http://mirrors.aliyun.com/epel-archive/6/\$basearch/debug failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=0 [epel-archive-source] name=Extra Packages for Enterprise Linux 6 - \$basearch - Source baseurl=http://mirrors.aliyun.com/epel-archive/6/SRPMS failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=0 EOF yum clean all yum repolist if [ $? -eq 0 ];then #color "EPEL源设置完成!" 0 echo -e "\e[1;35mEPEL源设置完成! \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "EPEL源设置失败!" 1 echo -e "\e[1;31mEPEL源设置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } configure_redhat_IP_address(){ rpm -qa ifconfig || yum -y install net-tools #[ $? -eq 0 ] || yum -y install net-tools local NET1=`ifconfig | head -n 1 | cut -d: -f1` ip a echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m" echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n" read -p "输入现在正在使用的网卡名: " NET #echo -e '\n' #if [[ ! "$NET" == ]];then echo "请检查网卡名是否正确"; exit; fi #echo -e "\n\e[1;34m需要自行查看是否匹配 \e[0m\n" while :;do read -p "输入ip: " IP if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m" read -p "输入子网掩码位数:" PREFIX #两种写法都可以 #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then if [[ $PREFIX =~ 8|16|24|32 ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入网关:" GATEWAY if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入DNS:" DNS #if [[ "$DNS" =~ ^[0-255.]{1,3}[0-255]$ ]];then echo "请检查dns地址是否正确"; exit; fi if [[ "$DNS" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查DNS地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done cp /etc/sysconfig/network-scripts/ifcfg-$NET /etc/sysconfig/network-scripts/ifcfg-$NET.bak cat > /etc/sysconfig/network-scripts/ifcfg-$NET <<EOF NAME=$NET DEVICE=$NET IPADDR=$IP BOOTPROTO=none PREFIX=$PREFIX GATEWAY=$GATEWAY ONBOOT=yes DNS1=$DNS DNS2=8.8.8.8 EOF nmcli con reload && nmcli con up $NET if [ $? -eq 0 ];then #color "网卡配置完成 " 0 echo -e "\e[1;34m 网卡配置完成 \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "网卡配置失败 " 1 echo -e "\e[1;35m 网卡配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } configure_redhat6_IP_address(){ rpm -qa ifconfig [ $? -eq 0 ] || yum -y install net-tools local NET1=`ifconfig | head -n 1 | cut -d: -f1` echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m" echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n" read -p "输入网卡名: " NET #echo -e '\n' #if [[ ! "$NET" == ]];then echo "请检查网卡名是否正确"; exit; fi #echo -e "\n\e[1;34m需要自行查看是否匹配 \e[0m\n" while :;do read -p "输入ip: " IP if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m" read -p "输入子网掩码位数:" PREFIX #两种写法都可以 #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then if [[ $PREFIX =~ 8|16|24|32 ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入网关:" GATEWAY if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入DNS:" DNS #if [[ "$DNS" =~ ^[0-255.]{1,3}[0-255]$ ]];then echo "请检查dns地址是否正确"; exit; fi if [[ "$DNS" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入地址正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查DNS地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done cat > /etc/sysconfig/network-scripts/ifcfg-$NET <<EOF NAME=$NET DEVICE=$NET IPADDR=$IP BOOTPROTO=none PREFIX=$PREFIX GATEWAY=$GATEWAY ONBOOT=yes DNS1=$DNS DNS2=8.8.8.8 EOF #nmcli con reload && nmcli con up $NET service network restart if [ $? -eq 0 ];then #color "网卡配置完成 " 0 echo -e "\e[1;34m 网卡配置完成 \e[0m" "\e[1;32m [ OK ] \e[0m" else #color "网卡配置失败 " 1 echo -e "\e[1;35m 网卡配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" exit fi } #添加了循环控制,输错不用再重新执行了脚本了 configure_ubuntu_IP_address(){ while :;do read -p "输入IP:" IP if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入网关:" GATEWAY if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m" read -p "输入子网掩码位数:" PREFIX #两种写法都可以 #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then if [[ $PREFIX =~ 8|16|24|32 ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入DNS1:" DNS1 if [[ "$DNS1" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查DNS1地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done while :;do read -p "输入网关2:" DNS2 if [[ "$DNS2" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then echo -e "\n\e[1;34m输入正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n" break else #echo -e "\n\e[1;35m请检查DNS2地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n" #exit echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n" fi done mv /etc/netplan/*.yaml /etc/netplan/*.yaml.bak sleep 1 cat > /etc/netplan/eth0.yaml <<EOF network: version: 2 renderer: networkd ethernets: eth0: addresses: [${IP}/${PREFIX}] #或者用下面两行,两种格式不能混用 #- 192.168.8.10/24 #- 10.0.0.10/8 gateway4: ${GATEWAY} nameservers: search: [magedu.com, magedu.org] addresses: [${DNS1}, ${DNS2}] EOF netplan apply } #添加vi的别名,比较方便 set_alias(){ cat >>~/.bashrc <<EOF alias cdnet='cd /etc/sysconfig/network-scripts/' alias vi='vim' EOF ${PURPLE}添加完成${END} #if [ $? -eq 0 ];then #color "别名修改成功 " 0 # echo -e "\033[1;34m 别名修改成功! \033[0m\n" "\033[1;32m [ OK ] \033[0m" #else # #color "别名修改失败 " 1 # echo -e "\e[1;35m 别名修改失败! \e[0m\n" "\e[1;31m [ FAILED ] \e[0m" # exit #fi exec bash } #\E[$[RANDOM%7+31];1m #颜色改成随机颜色了,不想随机可以直接切换固定颜色 set_PS1(){ ${PURPLE}现在是随机颜色,想要固定颜色退出脚本自行修改脚本${END} sleep 5 if [ $ID = 'centos' -o $ID = 'rocky' ];then echo "PS1='\[\e[1;34m\][\[\e[$[RANDOM%7+31]m\]\u\[\e[$[RANDOM%7+31]m\]@\[\e[$[RANDOM%7+31]m\]\h\[\e[$[RANDOM%7+31]m\]\W\[\e[34m\]]\\$\[\e[0m\]'" >> /etc/bashrc #echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc #color "修改成功 " 0 echo -e "\033[1;34m修改成功! \033[0m" "\033[1;32m [ OK ] \033[0m" exec bash else echo "PS1='\[\e[1;34m\][\[\e[$[RANDOM%7+31]m\]\u\[\e[$[RANDOM%7+31]m\]@\[\e[$[RANDOM%7+31]m\]\h\[\e[$[RANDOM%7+31]m\]\W\[\e[34m\]]\\$\[\e[0m\]'" >> ~/.bashrc #echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc #color "修改成功 " 0 echo -e "\033[1;35m修改成功! \033[0m" "\033[1;32m [ OK ] \033[0m" exec bash fi } #set_PS2(){ #if [ $ID = 'centos' -o $ID = 'rocky' ];then # echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc # color "修改成功 " 0 # exec bash #else # echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc # color "修改成功 " 0 # exec bash #fi #} set_hostname(){ read -p "请输入主机名: " HOST hostnamectl set-hostname $HOST #color "修改完成" 0 echo -e "\033[1;35m设置成功! \033[0m" "\033[1;32m [ OK ] \033[0m" exec bash } set_redhat_netname(){ rpm -qa ifconfig || yum -y install net-tools #[ $? -eq 0 ] || yum -y install net-tools local NET1=`ifconfig | head -n 1 | cut -d: -f1` ip a echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m" echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n" read -p "请输入需要修改的网卡名: " NAME cp /etc/sysconfig/network-scripts/ifcfg-$NAME /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i.bak 's/ens.*/eth0/' /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i '/^GRUB_CMDLINE_LINUX=/s#"$# net.ifnames=0"#' /etc/default/grub #sed -ri 's/^(GRUB_CMDLINE_LINUX=.*)"$/\1 net.ifnames=0"/' /etc/default/grub grub2-mkconfig -o /etc/grub2.cfg if [ $? -eq 0 ];then echo -e "\033[1;32m配置完成,重启生效! \033[0m" "\033[1;32m [ OK ] \033[0m" else echo -e "\e[1;31m配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m" fi } set_ubuntu_netname(){ mv /etc/netplan/*.yaml /etc/netplan/*.yaml.backup cat >> /etc/netplan/00-installer-config.yaml <<EOF network: ethernets: eth0: dhcp4: true version: 2 EOF sed -i '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' /etc/default/grub grub-mkconfig -o /boot/grub/grub.cfg if [ $? -eq 0 ];then echo -e "\e[1;32m配置完成,重启生效! \e[0m" netplan apply else echo -e "\e[1;31m配置失败! \e[0m" fi } #新添加了set nu set paste set ts=4 set shiftwidth=4 set expandtab set autoindent set_vim(){ #set number #set nobackup #set gfn=Courier_New:h12 #syntax on #set smartindent #set shiftwidth=4 #set ts=4 #set autoindent #set ai! read -p "请输入作者名:" AUTHOR read -p "请输入QQ号:" QQ read -p "请输入博客地址:" URL read -p "请输入邮箱:" MAIL cat >~/.vimrc<<EOF set paste set ts=4 set shiftwidth=4 set expandtab set ignorecase set autoindent autocmd BufNewFile *.sh exec ":call SetTitle()" func SetTitle() if expand("%:e") == 'sh' call setline(1,"#!/bin/bash") call setline(2,"#********************************************************************") call setline(3,"#Author: ${AUTHOR}") call setline(4,"#QQ: ${QQ}") call setline(5,"#Date: ".strftime("%Y-%m-%d")) call setline(6,"#FileName: ".expand("%")) call setline(7,"#EMAIL: ${MAIL}") call setline(8,"#BLOG: ${URL}") call setline(9,"#Description:路漫漫其修远兮,吾将上下而求索") call setline(10,"#********************************************************************") call setline(11,"") endif endfunc autocmd BufNewFile * normal G EOF [ $? -eq 0 ] && echo -e "\e[1;35m设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m" #exec bash } #新添加开机后的显示,想该啥样就改啥样 set_motd(){ echo -e "\E[$[RANDOM%7+31];1m" cat > /etc/motd <<-EOF ***************************************** ******* 路漫漫其修远兮 *************** ************* 吾将上下而求索 ********* ***************************************** EOF echo -e "\E[0m" [ $? -eq 0 ] && echo -e "\e[1;34m 设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m" } set_motd1(){ echo -e "\E[$[RANDOM%7+31];1m" cat > /etc/motd <<-EOF _oo0oo_ 088888880 88" . "88 (| -_- |) 0\ = /0 ___/'---'\___ .' \\\\\\\| |//// '. / \\\\\\\|||:|||//// \ /_ ||||| -:- ||||| _\ | | \\\-///// | | | | \_| ''\---/'' |_/ | \ .-\__ '-' __/-. / ___'. .' /--.--\ '. .'___ ."" '< '.___\_<|>_/___.' >' "". | | : '- \'.;'\ _ /';.'/ - ' : | | \ \ '_. \_ __\ /__ _/ ._' / / ====='-.____'.___ \_____/___.-'____.-'===== ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 iii 永不死机 EOF echo -e "\E[0m" [ $? -eq 0 ] && echo -e "\e[1;34m 设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m" } #只是修改时区不是时间同步 set_timezone(){ #timedatectl set-timezone Asia/Shanghai 也可以设置成功 rm -f /etc/localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime timedatectl [ $? -eq 0 ] && echo -e "\e[1;34m 时区设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m" } install_mysql(){ local version=5.7.36 local URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-${version}-linux-glibc2.12-x86_64.tar.gz #URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz local DATA_DIR=/data/mysql/ local DIR=/usr/local/ echo -e "\e[1;33m 注意:MySQL8.0以上版本没有测试!当前只测试了一个版本! \e[0m" echo -e "\e[1;35m 数据库数据文件夹现在是${DATA_DIR} 解压目录是${DIR} \e[0m\n" echo -e "\e[1;35m 现在安装的版本是$version,如果不想安装此版本请在5秒内停止运行脚本 \e[0m" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\e[1;35m =============================安装依赖包============================= \e[0m" if [ $ID == "rocky" -o $ID == "centos" ];then yum -y install libaio numactl-libs ncurses-compat-libs else apt update &> /dev/null apt -y install libaio numactl-libs ncurses-compat-libs fi echo -e "\e[1;32m [ ok ] \e[0m" if id mysql &> /dev/null;then echo -e "\e[1;33m 用户已存在 \e[0m" else groupadd -g 336 -r mysql && useradd -g mysql -s /sbin/nologin -d /data/mysql -r -u 336 mysql echo -e "\e[1;32m MySQL用户创建完成 \e[0m" fi if [ -e mysql-${version}-linux-glibc2.12-x86_64.tar.gz ];then echo -e "\e[1;33m 文件已存在,准备安装... \e[0m" else echo -e "\e[1;35m 开始下载源文件... \e[0m" wget $URL if [ $? -eq 0 ];then echo -e "\e[1;32m 下载成功 \e[0m" else echo -e "\e[1;31m 下载失败,即将退出,请检查下载链接是否正确! \e[0m" exit fi fi echo -e "\e[1;35m =============================解压源文件============================= \e[0m" tar xvf mysql-${version}-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ echo -e "\e[1;35m 解压完成! \e[0m" sleep 1 echo -e "\e[1;35m =============================创建软链接============================= \e[0m" ln -s /usr/local/mysql-${version}-linux-glibc2.12-x86_64/ /usr/local/mysql chown -R root.root /usr/local/mysql/ sleep 1 echo -e "\e[1;35m =============================建立环境变量============================= \e[0m" echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh if [ -e /etc/my.cnf ];then cp /etc/my.cnf{,.bak} else cat > /etc/my.cnf <<EOF [mysqld] datadir=$DATA_DIR skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid character-set-server=utf8mb4 [client] socket=/data/mysql/mysql.sock default-character-set=utf8mb4 [mysql] prompt=(\u@\h) [\d]>\_ EOF fi [ ! -d /data/mysql ] && mkdir -p /data/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/mysql sleep 1 echo -e "\e[1;35m =========================复制系统service文件========================= \e[0m" cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld echo -e "\e[1;35m =============================启动数据库============================= \e[0m" service mysqld start echo -e "\e[1;35m 可以通过systemctl启动mysqld \e[0m" [ $? -eq 0 ] && echo -e "\e[1;35m 数据库启动成功 \e[0m" || { echo -e "\e[1;35m 数据库启动失败 \e[0m";exit; } echo -e "\e[1;35m 现在是空密码,需要自己修改密码 \e[0m" echo -e "\e[1;35m 修改密码命令mysqladmin -uroot password 新密码 \e[0m" exec bash } rpm_install_mysql(){ echo -e "\n\e[1;35mcentos7版本安装mysql-community-server5.7\e[0m" echo -e "\e[1;35m如果不想安装此版本请在5秒内停止运行脚本\e[0m" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done if [ -e /etc/yum.repos.d/mysql-community.repo ];then echo -e "\n\e[1;35mrepo仓库已存在\e[0m" else echo -e "\n\e[1;35m配置repo仓库安装mysql-community-server5.7\e[0m" cat >> /etc/yum.repos.d/mysql-community.repo << EOF [mysql-5.7-community] name=MySQL 5.7 Community Server baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-\$basearch/ gpgcheck=0 EOF [ $? -eq 0 ] && echo -e "\n\e[1;35m配置完成\e[0m" || echo -e "\n\e[1;35m配置失败\e[0m" fi rpm -q mysql-community-server &>/dev/null && echo -e "\n\e[1;35mmysql-community-server5.7已安装\e[0m" || { yum -y install mysql-community-server;} echo -e "\n\e[1;35m配置mysqld开机自启\e[0m" systemctl enable --now mysqld local PASSWD=`cat /var/log/mysqld.log | grep 'password is generated' | awk '{print $NF}'` echo -e "\n\e[1;35m初始密码是:\e[0m"$PASSWD #read -p "输入新密码(需要大小写数字特殊字符才可以,不然报错!):" NEWPASSWD #local sql="alter user root@'localhost' identified by '$NEWPASSWD';" #mysql -uroot -p'e)=Zgpc<p3rs' -e "$sql" #mysql -uroot -p'$NEWPASSWD' echo -e "\n\e[1;35m修改密码的SQL是:\e[0m alter user root@'localhost' identified by '新密码';" } install_mariadb(){ #echo -e "\e[1;35m 只在centos7.9版本测试正常,CentOS-6版本测试不成功\e[0m" local SYSVERSION=`cat /etc/redhat-release | awk -F"." '{print $1}' | awk '{print $NF}'` [ $SYSVERSION -eq 7 ] && echo -e "\n\e[1;33m 当前系统为$SYSVERSION 脚本支持安装 \e[0m" || { echo -e "\n\e[1;31m 当前系统为$SYSVERSION 脚本不支持安装\e[0m";exit; } #exit local version=10.10.3 #URL=https://dlm.mariadb.com/2690820/MariaDB/mariadb-10.10.2/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz #URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz #URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.6.11/bintar-linux-systemd-x86_64/mariadb-10.6.11-linux-systemd-x86_64.tar.gz #URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz #echo -e "\e[1;35m 阿里源下载链接:\e[0m"https://mirrors.aliyun.com/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz #echo -e "\e[1;35m 清华源下载链接:\e[0m"https://mirror.tuna.tsinghua.edu.cn/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz URL=https://mirrors.aliyun.com/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz local DATA_DIR=/data/mysql/ local DIR=/usr/local/ #echo -e "\e[1;35m 如果原始下载链接失败,可以重新执行尝试其他下载链接或者提前准备好压缩包文件放在root目录下\e[0m" #echo -e "\e[1;35m 下面请输入下载链接:\e[0m" #read -p "" URL echo -e "\n\e[1;35m 数据库数据文件夹现在是${DATA_DIR} 解压目录是${DIR} \e[0m" echo -e "\e[1;35m 接下来安装的版本是mariadb-${version},如果不想安装此版本请在5秒内停止运行脚本 \e[0m" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e '\a' if id mysql &> /dev/null;then echo -e "\n\e[1;33m 用户已存在 \e[0m" else groupadd -g 336 -r mysql && useradd -g mysql -s /sbin/nologin -d ${DATA_DIR} -r -u 336 mysql #echo -e "\e[1;35m MySQL用户创建完成 \e[0m" "\e[1;32m [ ok ] \e[0m" [ $? -eq 0 ] && echo -e "\n\e[1;35m MySQL用户创建完成 \e[0m" || { echo -e "\n\e[1;31m MySQL用户创建失败 \e[0m";exit; } fi if [ -e mariadb-${version}-linux-systemd-x86_64.tar.gz ];then echo -e "\n\e[1;33m 文件已存在,准备安装... \e[0m" else echo -e "\n\e[1;33m 开始下载源文件(下载地址是阿里源,如果yum源配的没有阿里源可能会下载失败) \e[0m" rpm -q wget &>/dev/null || yum -y install wget &>/dev/null wget $URL && echo -e "\n\e[1;33m 下载成功\e[0m" || { echo -e "\n\e[1;33m 下载链接失效,请尝试更换其他下载链接或者提前准备好压缩包文件放在root目录下\e[0m" ;exit; } fi #[ -e mariadb-${version}-linux-systemd-x86_64.tar.gz ] && { echo "\e[1;34m 下载成功 \e[0m" } || { echo -e "\e[1;36m 下载失败,即将退出 \e[0m";exit; } echo -e "\n\e[1;35m 开始解压源文件... \e[0m" sleep 2 #tar xzvf mariadb-${version}-linux-systemd-x86_64.tar.gz -C ${DIR} tar xzf mariadb-${version}-linux-systemd-x86_64.tar.gz -C ${DIR} [ $? -eq 0 ] && echo -e "\n\e[1;35m 解压完成! \e[0m" echo -e "\e[1;32m [ ok ] \e[0m" sleep 1 echo -e "\e[1;35m 创建软链接 \e[0m" ln -s /usr/local/mariadb-${version}-linux-systemd-x86_64 ${DIR}mysql [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" sleep 1 echo -e "\e[1;35m 建立环境变量 \e[0m" echo "PATH=${DIR}mysql/bin:$PATH" > /etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" sleep 1 echo -e "\e[1;35m 创建数据文件夹 \e[0m" mkdir -p /data/mysql chown -R mysql.mysql ${DATA_DIR} chown -R mysql.mysql ${DIR}mysql sleep 1 echo -e "\e[1;32m [ ok ] \e[0m" echo -e "\e[1;33m 正在初始化数据库 \e[0m\n" ${DIR}mysql/scripts/mysql_install_db --user=mysql --basedir=${DIR}mysql --datadir=${DATA_DIR} #添加client才能启动成功 cat > /etc/my.cnf << EOF [mysqld] datadir=${DATA_DIR} socket=${DATA_DIR}mysql.sock symbolic-links=0 character-set-server=utf8mb4 [mysqld_safe] log-error=/data/mariadb/mariadb.log pid-file=/data/mariadb/mariadb.pid [client] socket=/data/mysql/mysql.sock default-character-set=utf8mb4 !includedir /etc/my.cnf.d EOF if [ $? -eq 0 ];then echo -e "\e[1;35m 初始化数据库 \e[0m\n" "\e[1;32m [ ok ] \e[0m" else echo -e "\e[1;31m 初始化数据库 \e[0m\n" "\e[1;31m [ FAILED ] \e[0m" exit fi echo -e "\e[1;35m 创建log和pid文件夹 \e[0m\n" "\e[1;32m [ ok ] \e[0m" mkdir ${DATA_DIR}{log,pid} chown -R mysql.mysql ${DATA_DIR} echo -e "\n\e[1;35m 正在复制systemd配置文件 \e[0m\n" #ln -s mariadb-${version}-linux-systemd-x86_64/ mysql cp /usr/local/mysql/support-files/systemd/mariadb.service /lib/systemd/system/ if [ $? -eq 0 ];then echo -e "\e[1;35m 复制systemd配置文件 \e[0m\n" "\e[1;32m [ ok ] \e[0m" else echo -e "\e[1;31m 复制systemd配置文件 \e[0m\n" "\e[1;31m [ FAILED ] \e[0m" exit fi #echo -e "\n\e[1;33m 正在启动服务 \e[0m" systemctl daemon-reload #systemctl start mariadb systemctl enable --now mariadb if [ $? -eq 0 ];then echo -e "\e[1;35m 启动服务成功! \e[0m" else echo -e "\e[1;31m 启动服务失败! \e[0m" exit fi #cat >> /etc/my.cnf.d/mysql-clients.cnf << EOF #[mysql] #socket=${DATA_DIR}mysql.sock #EOF ln -s ${DIR}mysql/bin/mariadb /usr/bin/mysql exec bash } yum_mariadb(){ echo -e "\n\e[1;35m本次安装的是10.6版本\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done yum -y remove mariadb* cat >> /etc/yum.repos.d/mariadb.repo <<EOF [mariadb10.6] name = MariaDB baseurl = http://yum.mariadb.org/10.6/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 enabled=1 EOF yum clean all && yum makecache yum -y install mariadb mariadb-devel mariadb-libs mariadb-server } install_nginx(){ local version=1.20.2 local URL=http://nginx.org/download/nginx-${version}.tar.gz echo -e "\e[1;35m 现在安装的版本是$version,如果不想安装此版本请在5秒内停止运行脚本 \e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done if [ -e nginx-${version}.tar.gz ];then echo "文件存在,安装进行中。。。" else echo "文件不存在,开始下载源码文件。。。" wget $URL [ $? -eq 0 ] && { echo -e "\e[1;35m下载成功!\e[0m"; } || { echo -e "\e[1;35m下载失败!立即退出!\e[0m";exit; } fi if id nginx &> /dev/null;then echo -e "\e[1;35m用户存在\e[0m" else groupadd -g 990 -r nginx && useradd -g nginx -s /sbin/nologin -r -u 990 nginx echo -e "\e[1;35m用户不存在,创建nginx用户\e[0m" fi echo -e "\e[1;35m安装依赖包 \e[0m" if [ $ID == "rocky" -o $ID == "centos" ];then #yum -y install make gcc gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed software=("gcc" "gcc-c++" "glibc" "make" "pcre" "pcre-devel" "openssl" "openssl-devel" "autoconf" "automake" "libtool" "zlib" "zlib-devel" "perl-ExtUtils-Embed" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\e[1;35m安装成功\e[0m" ; } done else apt update &> /dev/null apt -y install make gcc libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev &> /dev/null fi tar xf nginx-${version}.tar.gz -C /usr/local/src cd /usr/local/src/nginx-${version} ./configure --prefix=/apps/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module make && make install [ $? -eq 0 ] && color "nginx编译成功" 0 || { color "nginx编译失败" 1 ;exit; } chown -R nginx.nginx /apps/nginx ln -s /apps/nginx/sbin/nginx /usr/sbin/ cat > /lib/systemd/system/nginx.service << EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking #PIDFile=/apps/nginx/run/nginx.pid ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP \$MAINPID ExecStop=/bin/kill -s TERM \$MAINPID LimitNOFILE=100000 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now nginx &> /dev/null [ $? -eq 0 ] && color "nginx启动 " 0 || { color "nginx启动" 1 ;exit; } } update_nginx(){ local version=1.22.1 local URL=http://nginx.org/download/nginx-${version}.tar.gz echo -e "\n\e[1;35m更新的版本是nginx-${version},需要更新其他版本请自行修改代码\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\n\e[1;35m安装依赖包\e[0m\n" #yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ autoconf automake make software=( "gcc" "gcc-c++" "glibc" "make" "pcre" "pcre-devel" "openssl" "openssl-devel" "autoconf" "automake" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\e[1;35m安装成功\e[0m" ; } done #查看当前nginx版本以及编译模块参数 echo -e "\n\e[1;31m已安装的版本,想退出安装请在五秒内终止脚本\e[0m\n" /apps/nginx/sbin/nginx -V #/srun3/nginx/sbin/nginx -V for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done if [ -e nginx-${version}.tar.gz ];then echo -e "\e[1;35m文件已存在,开始安装\e[0m" else echo -e "\e[1;33m文件不存在,开始下载\e[0m" wget $URL && echo -e "\e[1;35m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; } fi #解压新版本 echo -e "\n\e[1;35m解压源文件\e[0m" tar zxf nginx-${version}.tar.gz cd nginx-${version} #编译新版本 ./configure --prefix=/apps/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module #./configure --prefix=/srun3/nginx \ #--conf-path=/srun3/nginx/conf/nginx.conf \ #--sbin-path=/srun3/nginx/sbin/nginx \ #--pid-path=/srun3/nginx/run/nginx.pid \ #--error-log-path=/srun3/nginx/log/nginx-error.log \ #--http-log-path=/srun3/nginx/log/nginx-access.log \ #--user=nginx \ #--group=nginx \ #--with-http_ssl_module \ #--with-http_realip_module \ #--with-http_flv_module \ #--with-http_mp4_module \ #--with-http_gunzip_module \ #--with-http_gzip_static_module \ #--with-http_secure_link_module \ #--with-http_v2_module \ #--with-http_stub_status_module \ #--with-http_sub_module #只要make无需要make install make #可以看到新编译的nginx版本 #objs/nginx -v echo -e "\n\e[1;35m备份旧的nginx文件\e[0m" #把之前的旧版的nginx命令备份 #cp /srun3/nginx/sbin/nginx /srun3/nginx/sbin/nginx.bak cp /apps/nginx/sbin/nginx /apps/nginx/sbin/nginx.bak [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; } echo -e "\n\e[1;35m复制新版本源文件\e[0m" #新版本nginx复制到旧版本目录中 #cp -f ./objs/nginx /srun3/nginx/sbin/ cp -f ./objs/nginx /apps/nginx/sbin/ [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; } echo -e "\n\e[1;35m检测\e[0m" #检测一下 #/srun3/nginx/sbin/nginx -t /apps/nginx/sbin/nginx -t echo -e "\n\e[1;35m平滑升级到新版本\e[0m" #发送信号USR2 平滑升级可执行程序,将存储有旧版本主进程PID的文件重命名为nginx.pid.oldbin,并启动新的nginx #此时两个master的进程都在运行,只是旧的master不在监听,由新的master监听80 #此时Nginx开启一个新的master进程,这个master进程会生成新的worker进程,这就是升级后的Nginx进程,此时老的进程不会自动退出,但是当接收到新的请求不作处理而是交给新的进程处理。 #先关闭旧nginx的worker进程,而不关闭nginx主进程方便回滚 #向原Nginx主进程发送WINCH信号,它会逐步关闭旗下的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理 #kill -USR2 `cat /run/nginx.pid` #kill -WINCH `cat /run/nginx.pid.oldbin` kill -USR2 `cat /apps/nginx/logs/nginx.pid` kill -WINCH `cat /apps/nginx/logs/nginx.pid.oldbin` #如果旧版worker进程有用户的请求,会一直等待处理完后才会关闭 #经过一段时间测试,新版本服务没问题,最后发送QUIT信号,退出老的master #kill -QUIT `cat /run/nginx.pid.oldbin` kill -QUIT `cat /apps/nginx/logs/nginx.pid.oldbin` [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" #查看版本已经是新版了 echo -e "\n\e[1;35m升级后的版本\e[0m" #/srun3/nginx/sbin/nginx -V /apps/nginx/sbin/nginx -V echo -e "\n\e[1;35m如果想回滚到旧版本,执行以下命令\e[0m" echo -e "\n\e[1;35mkill -HUP `cat /run/nginx.pid.oldbin`\e[0m" echo -e "\n\e[1;35mmv /apps/nginx/sbin/nginx.bak /apps/nginx/sbin/nginx\e[0m" #回滚 #如果升级的版本发现问题需要回滚,可以发送HUP信号,重新拉起旧版本的worker #kill -HUP `cat /run/nginx.pid.oldbin` #恢复旧版的文件 #mv /srun3/nginx/sbin/nginx.bak /srun3/nginx/sbin/ #mv /apps/nginx/sbin/nginx.bak /apps/nginx/sbin/nginx } update_srunnginx(){ echo -e "\n\e[1;35m更新的版本是nginx-${version},centos7安装的4k测试没出现问题\e[0m" } update_srunnginx2(){ echo -e "\n\e[1;35m更新的版本是nginx-${version},在centos6上测试的\e[0m" } update_openssl(){ local version=1.1.1k local URL=https://www.openssl.org/source/old/1.1.1/openssl-1.1.1k.tar.gz echo -e "\n\e[1;35m本次安装的版本是openssl-${version}\e[0m" echo -e "\e[1;33mwget无法下载,建议自行去官网下载${URL}\e[0m" echo -e "\n\e[1;35m离线安装,请提前准备好对应版本的压缩包放在root目录下\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\n\e[1;35m现在已安装的版本\e[0m" openssl version echo -e "\e[1;33m将要安装的版本是openssl-${version},wget无法下载,建议自行去官网下载${URL},\e[0m" if [ -e openssl-${version}.tar.gz ];then echo -e "\e[1;35m文件已存在,开始安装\e[0m" else echo -e "\e[1;33m文件不存在,开始下载\e[0m" wget $URL && echo -e "\e[1;33m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; } fi echo -e "\e[1;34m安装依赖包\e[0m" #yum install -y gcc gcc-c++ glibc make software=( "gcc" "gcc-c++" "glibc" "make" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\e[1;35m安装成功\e[0m" ; } done tar zxf /root/openssl-${version}.tar.gz cd /root/openssl-${version} ./config --prefix=/usr/local/openssl -d shared make #执行失败的话执行make clean清除make信息 #[ $? -eq 0 ] || make clean sleep 1 make install #备份旧的 mv /usr/bin/openssl /usr/bin/openssl.bak #对新的创建软连接 ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl #将 openssl 的 lib 库写进配置中,并使配置生效 #echo "/usr/local/openssl/lib64/" >> /etc/ld.so.conf echo "/usr/local/openssl/lib" >> /etc/ld.so.conf #验证:ldconfig -v|grep ssl //确定链接库 ldconfig -v [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m" #出现报错libssl.so.1.1。。。缺少依赖库 #ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 #ln -s /usr/local/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1 #echo "/usr/local/lib64" >> /etc/ld.so.conf #ldconfig -v | grep ssl #查看版本 是否安装成功 echo -e "\n\e[1;35m升级后版本\e[0m" openssl version } update_openssh(){ local ZLIBV=1.2.13 local OPENSSHV=9.1p1 echo -e "\n\e[1;35m本次升级的版本openssh-${OPENSSHV},zlib-${ZLIBV}\e[0m" echo -e "\n\e[1;35m离线安装,请提前准备好对应版本的压缩包放在root目录下\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\n\e[1;35m已安装版本\e[0m" ssh -V echo -e "\n\e[1;35m解压源文件\e[0m" tar -zxf /root/zlib-${ZLIBV}.tar.gz tar -zxf /root/openssh-${OPENSSHV}.tar.gz if [ -e zlib-${ZLIBV} ];then echo -e "\n\e[1;35mzlib已解压\e[0m" else echo -e "\n\e[1;35m再试一次\e[0m" tar zxf /root/zlib-${ZLIBV}.tar.gz fi if [ -e openssh-${OPENSSHV} ];then echo -e "\n\e[1;35mopenssh已解压\e[0m" else echo -e "\n\e[1;35m再试一次\e[0m" tar zxf /root/openssh-${OPENSSHV}.tar.gz fi echo -e "\n\e[1;35m安装依赖包\e[0m" #yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel #yum install -y pam* zlib* software=("gcc" "gcc-c++" "glibc" "make" "autoconf" "openssl" "openssl-devel" "pcre-devel" "pam-devel" "pam*" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\e[1;35m安装成功\e[0m" ; } done #tar zxf /root/zlib-${ZLIBV}.tar.gz if [ -e /usr/local/zlib ];then echo -e "\n\e[1;35m已存在\e[0m" else echo -e "\n\e[1;35m编译zlib\e[0m" cd /root/zlib-${ZLIBV}/ ./configure --prefix=/usr/local/zlib make && make install [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m" fi #tar zxf /root/openssh-${OPENSSHV}.tar.gz if [ -e /usr/local/openssh ];then echo -e "\n\e[1;35m已存在\e[0m" else echo -e "\n\e[1;35m编译openssh\e[0m" cd /root/openssh-${OPENSSHV}/ ./configure --prefix=/usr/local/openssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-pam --without-openssl-header-check make && make install [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m" fi echo -e "\n\e[1;35m移除旧文件,迁入新文件\e[0m" mkdir -p /data/opensshbak/ mv /etc/ssh/sshd_config /data/opensshbak/sshd_config.bak cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config mv /usr/sbin/sshd /data/opensshbak/sshd.bak cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd mv /usr/bin/ssh /data/opensshbak/ssh.bak cp /usr/local/openssh/bin/ssh /usr/bin/ssh mv /usr/bin/ssh-keygen /data/opensshbak/ssh-keygen.bak cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen mv /etc/ssh/ssh_host_ecdsa_key.pub /data/opensshbak/ssh_host_ecdsa_key.pub.bak cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config cp /root/openssh-${OPENSSHV}/contrib/redhat/sshd.init /etc/init.d/sshd chmod u+x /etc/init.d/sshd echo -e "\n\e[1;35m修改sshd配置文件\e[0m" cp /etc/init.d/sshd /data/opensshbak/sshdnewbk sed -i '/SSHD=/c\SSHD=\/usr\/local\/openssh\/sbin\/sshd' /etc/init.d/sshd sed -i '/\/usr\/bin\/ssh-keygen/c\ \/usr\/local\/openssh\/bin\/ssh-keygen -A' /etc/init.d/sshd sed -i '/ssh_host_rsa_key.pub/i\ \/sbin\/restorecon \/etc\/ssh\/ssh_host_key.pub' /etc/init.d/sshd sed -i '/$SSHD $OPTIONS && success || failure/i\ \ OPTIONS="-f /etc/ssh/sshd_config"' /etc/rc.d/init.d/sshd echo -e "\n\e[1;35m修改sshd_config配置文件\e[0m" sed -i '/PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config sed -i '/X11Forwarding/c\X11Forwarding yes' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config cp -arp /usr/local/openssh/bin/* /usr/bin/ service sshd restart echo -e "\n\e[1;35m配置开机项\e[0m" chkconfig --add sshd chkconfig --level 2345 sshd on chkconfig --list echo -e "\n\e[1;35m更新后版本\e[0m" ssh -V } install_openssh1(){ echo -e "\e[1;34m作废\e[0m" if [ ! -d /home/data ];then mkdir /home/data fi cd /home/data yum install wget -y #wget -O openssh-8.6p1.tar.gz https://ftp.riken.jp/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz #wget -O zlib-1.2.11.tar.gz https://zlib.net/zlib-1.2.11.tar.gz #wget -O openssl-1.1.1j.tar.gz https://www.openssl.org/source/openssl-1.1.1j.tar.gz ######保证下载的文件在/home/data里,且文件名相同 tar -zxf openssl-1.1.1q.tar.gz tar -zxf zlib-1.2.13.tar.gz tar -zxf openssh-9.1p1.tar.gz chown -R root:root /home/data #######################0end----------############################ ##1---配置Telnet,以防SSH配置过程中出现问题,可以使用Telnet登录---- setenforce 0 #关闭selinux systemctl stop firewalld #关闭 systemctl disable firewalld #yum install telnet telnet-server xinetd -y ##vi /etc/xinetd.conf ##修改disabled = no ,即可以使用telnet服务 #cp /etc/xinetd.conf /home/data/xinetd.comfbk #sed -i '14a disabled = no ' /etc/xinetd.conf ##在第14行增加 disabled = no #echo -e 'pts/0\npts/1\npts/2\npts/3' >>/etc/securetty #systemctl start telnet.socket #开启服务 #systemctl start xinetd #开启服务 #systemctl enable telnet.socket #开机自起服务 #systemctl enable xinetd ##1end--------------------------------------------------------------- ##2 升级 OpenZlib----------------------------------------- yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel yum install -y pam* zlib* cd /home/data/zlib-1.2.13/ ./configure --prefix=/usr/local/zlib make && make install ##2end--------------------- ##3升级openssl------------- cd /home/data/openssl-1.1.1q// ./config --prefix=/usr/local/openssl -d shared make && make install echo '/usr/local/openssl/lib' >> /etc/ld.so.conf ldconfig mv /usr/bin/openssl /home/data/opensslbk ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl ##3end--and start update SSH------------------------ ##4-----安装OpenSSH 8.6p1------- cd /home/data/openssh-9.1p1/ ./configure --prefix=/usr/local/openssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-pam --without-openssl-header-check make && make install mv /etc/ssh/sshd_config /home/data/sshd_config.bak cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config mv /usr/sbin/sshd /home/data/sshd.bak cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd mv /usr/bin/ssh /home/data/ssh.bak cp /usr/local/openssh/bin/ssh /usr/bin/ssh mv /usr/bin/ssh-keygen /home/data/ssh-keygen.bak cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen mv /etc/ssh/ssh_host_ecdsa_key.pub /home/data/ssh_host_ecdsa_key.pub.bak cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done #mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config cp /home/data/openssh-9.1p1/contrib/redhat/sshd.init /etc/init.d/sshd chmod u+x /etc/init.d/sshd #-------------修改配置文件------------ cp /etc/init.d/sshd /home/data/sshdnewbk sed -i '/SSHD=/c\SSHD=\/usr\/local\/openssh\/sbin\/sshd' /etc/init.d/sshd sed -i '/\/usr\/bin\/ssh-keygen/c\ \/usr\/local\/openssh\/bin\/ssh-keygen -A' /etc/init.d/sshd sed -i '/ssh_host_rsa_key.pub/i\ \/sbin\/restorecon \/etc\/ssh\/ssh_host_key.pub' /etc/init.d/sshd sed -i '/$SSHD $OPTIONS && success || failure/i\ \ OPTIONS="-f /etc/ssh/sshd_config"' /etc/rc.d/init.d/sshd #---------操作sshd_config------- sed -i '/PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config sed -i '/X11Forwarding/c\X11Forwarding yes' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config cp -arp /usr/local/openssh/bin/* /usr/bin/ service sshd restart ##3end------------------------------------------ #----------配置开机项--------------- chkconfig --add sshd chkconfig --level 2345 sshd on chkconfig --list #----------关闭Telnet服务--------------- #systemctl stop telnet.socket #systemctl stop xinetd #systemctl disable xinetd.service #systemctl disable telnet.socket #--------清理安装过程文件--------------------- #rm -fr /home/data } c7_yum_docker(){ local VERSION=20.10.23-3.el7 echo -e "\n\e[1;35m此方法更换了所有源\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\n\e[1;35m使用阿里云的yum源安装docker-ce\e[0m" local DIR1=$(date +%F) mkdir -p /data/yumbak-$DIR1 echo -e "\n\e[1;35m备份原有的yum源,备份文件在/data/下\e[0m" mv /etc/yum.repos.d/* /data/yumbak-$DIR1 cat > /etc/yum.repos.d/CentOS-Base.repo <<EOF # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-\$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-\$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-\$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-\$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-\$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 EOF cat > /etc/yum.repos.d/docker-ce.repo <<EOF [docker-ce-stable] name=Docker CE Stable - \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/stable enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo \$basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg EOF cat >/etc/yum.repos.d/epel.repo <<EOF [epel] name=Extra Packages for Enterprise Linux 7 - \$basearch baseurl=http://mirrors.aliyun.com/epel/7/\$basearch failovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - \$basearch - Debug baseurl=http://mirrors.aliyun.com/epel/7/\$basearch/debug failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=0 [epel-source] name=Extra Packages for Enterprise Linux 7 - \$basearch - Source baseurl=http://mirrors.aliyun.com/epel/7/SRPMS failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 EOF yum clean all yum -y install docker-ce-${VERSION} docker-ce-cli-$VERSION [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m" #使用阿里做镜像加速 echo -e "\n\e[1;35m阿里镜像加速\e[0m" [ -d /etc/docker ] || mkdir -p /etc/docker cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"] } EOF systemctl enable --now docker [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m" echo -e "\n\e[1;35m安装的docker版本\e[0m" docker version } c7_yum2_docker(){ DOCKER_VERSION="-20.10.9-3.el7" echo -e "\n\e[1;35m此方法只添加了docker.repo,不想使用此方法请在五秒内终止脚本\e[0m" echo -e "\n\e[1;35m安装完没有server端不知道原因\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done cat >/etc/yum.repos.d/docker.repo <<EOF [docker] name=docker baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7.9/x86_64/stable/ gpgcheck=0 EOF yum clean all yum repolist #yum list docker-ce* --showduplicates | sort -r yum -y install docker-ce${DOCKER_VERSION} docker-ce-cli${DOCKER_VERSION} #使用阿里做镜像加速 echo -e "\n\e[1;35m配置阿里镜像加速\e[0m" [ -d /etc/docker ] || mkdir -p /etc/docker cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"] } EOF [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" systemctl daemon-reload systemctl enable --now docker echo -e "\n\e[1;35m查看安装版本信息\e[0m" docker version systemctl restart docker echo -e "\n\e[1;35m验证镜像拉取是否正常\e[0m" docker run hello-world &>/dev/null docker images } c8_yum_docker(){ local DOCKER_VERSION="-20.10.23-3.el8" echo -e "\n\e[1;35m本次安装的版本是docker-ce${DOCKER_VERSION}\e[0m" echo -e "\n\e[1;35m此方法只添加了docker.repo\e[0m" echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done cat >/etc/yum.repos.d/docker.repo <<EOF [docker] name=docker baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/ https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/8/x86_64/stable/ gpgcheck=0 EOF yum clean all yum repolist #yum list docker-ce* --showduplicates | sort -r yum -y install docker-ce${DOCKER_VERSION} docker-ce-cli${DOCKER_VERSION} #使用阿里做镜像加速 echo -e "\n\e[1;35m配置阿里镜像加速\e[0m" [ -d /etc/docker ] || mkdir -p /etc/docker cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"] } EOF [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" systemctl daemon-reload systemctl enable --now docker echo -e "\n\e[1;35m查看安装版本信息\e[0m" docker version systemctl restart docker echo -e "\n\e[1;35m验证镜像拉取是否正常\e[0m" docker run hello-world &>/dev/null docker images } offline_install_docker(){ local DOCKER_VERSION=20.10.9 local URL=https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-20.10.9.tgz echo -e "\n\e[1;35m现在安装的版本是docker-${DOCKER_VERSION},若不想安装此版本请在五秒内终止脚本运行\e[0m" echo -e "\e[1;35mcentos7,rocky8上测试正常\e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done if [ -e docker-${DOCKER_VERSION}.tgz ];then echo -e "\n\e[1;32m文件已存在,开始安装\e[0m" else echo -e "\n\e[1;33m文件不存在,开始下载\e[0m" wget $URL && echo -e "\e[1;32m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; } fi echo -e "\n\e[1;35m解压源文件,拷贝docker文件到bin下\e[0m" tar xvf docker-${DOCKER_VERSION}.tgz -C /usr/local/ cp /usr/local/docker/* /usr/bin/ [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" echo -e "\n\e[1;35m写入service文件\e[0m" cat > /lib/systemd/system/docker.service <<EOF [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H unix://var/run/docker.sock ExecReload=/bin/kill -s HUP \$MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target EOF [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" echo -e "\n\e[1;35m启动\e[0m" systemctl daemon-reload systemctl enable --now docker &>/dev/null [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" #使用阿里做镜像加速 echo -e "\n\e[1;35m配置阿里镜像加速\e[0m" [ -d /etc/docker ] || mkdir -p /etc/docker cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"] } EOF [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" systemctl daemon-reload systemctl restart docker echo -e "\n\e[1;35m查看安装版本信息\e[0m" docker version echo -e "\n\e[1;35m拉取hello-world,验证镜像拉取是否正常\e[0m" docker run hello-world &>/dev/null docker images } redhat_install_clickhouse(){ sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo sudo yum install -y clickhouse-server clickhouse-client sudo /etc/init.d/clickhouse-server start clickhouse-client # or "clickhouse-client --password" if you set up a password. } debian_install_clickhouse(){ #安装环境配置和安装软件更新 sudo apt-get install -y apt-transport-https ca-certificates dirmngr sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754 echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \ /etc/apt/sources.list.d/clickhouse.list sudo apt-get update #安装clickhouse sudo apt-get install -y clickhouse-server clickhouse-client #启动clickhouse服务 sudo service clickhouse-server start #启动客户端 clickhouse-client # or "clickhouse-client --password" if you've set up a password. exit } tgz_install_clickhouse(){ #获取最后一个版本号 LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \ grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1) export LATEST_VERSION case $(uname -m) in x86_64) ARCH=amd64 ;; aarch64) ARCH=arm64 ;; *) echo "Unknown architecture $(uname -m)"; exit 1 ;; esac #下载对应版本号的tgz安装包 for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client do curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \ || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz" done #解压压缩包并执行对应的脚本 tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \ || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz" #生成ClickHouse编译的二进制文件 sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh" tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \ || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz" #生成带有调试信息的ClickHouse二进制文件 sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh" tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \ || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz" #创建clickhouse-server软连接,并安装默认配置服务 sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure #启动服务 sudo /etc/init.d/clickhouse-server start tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \ || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz" #创建clickhouse-client客户端工具软连接,并安装客户端配置文件 sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh" } compile_install_clickhouse(){ #gcc 10安装 # base centos 7 yum update yum install -y gcc gcc-c++ yum install -y bzip2 wget -P /home https://mirrors.aliyun.com/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz cd /home && tar -xzvf /home/gcc-10.2.0.tar.gz cd /home/gcc-10.2.0 && ./contrib/download_prerequisites #这一步看网速,需要挺久的 mkdir /usr/lib/gcc/x86_64-redhat-linux/10.2.0 mkdir /home/gcc-build-10.2.0 cd /home/gcc-build-10.2.0 ../gcc-10.2.0/configure --prefix=/usr/lib/gcc/x86_64-redhat-linux/10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib make && make install mv /usr/bin/gcc /usr/bin/gcc-4.8.5 mv /usr/bin/g++ /usr/bin/g++-4.8.5 alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 88 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8.5 alternatives --install /usr/bin/gcc gcc /usr/lib/gcc/x86_64-redhat-linux/10.2.0/bin/x86_64-pc-linux-gnu-gcc 99 --slave /usr/bin/g++ g++ /usr/lib/gcc/x86_64-redhat-linux/10.2.0/bin/x86_64-pc-linux-gnu-g++ alternatives --config gcc #输入2回车 # 安装re2c yum -y install git automake libtool git clone https://github.com.cnpmjs.org/skvadrik/re2c.git re2c cd re2c mkdir -p m4 ./autogen.sh && ./configure --prefix=/usr && make make install # 安装ninja ## 编译安装cmake3.15以上,此教程举例安装3.21 yum install -y openssl-devel wget https://cmake.org/files/v3.21/cmake-3.21.0-rc1.tar.gz tar -zxvf cmake-3.21.0-rc1.tar.gz cd cmake-3.21.0-rc1/ ./bootstrap gmake gamke install ## 安装ninja git clone https://github.com/ninja-build/ninja.git ninja cd ninja cmake -Bbuild-cmake -H. cmake --build build-cmake cp ninja /usr/bin/ ninja --version #安装python3 yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel yum -y install python-pip yum install libffi-devel -y mv /usr/bin/python /usr/bin/python.bak wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz tar -zxvf Python-3.7.9.tgz ./configure prefix=/usr/local/python3 make && make install ln -s /usr/local/python3/bin/python3.7 /usr/bin/python #修改yum配置 vi /usr/bin/yum 把#! /usr/bin/python修改为#! /usr/bin/python2 # vi /usr/libexec/urlgrabber-ext-down #把#! /usr/bin/python修改为#! /usr/bin/python2 #安装clickhouse # 替换github的源(因为墙的原因) git config --global url."https://hub.fastgit.org".insteadOf https://github.com git clone https://github.com/ClickHouse/ClickHouse cd ClickHouse # 切换到指定版本 git tag -l git checkout -b v21.7.5.29-stable git submodule sync git submodule update --init --recursive #等吧 mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr/local/clickhouse ../ ninja clickhouse #也是需要等很久,最好用screen } compile_install_redis(){ local VERSION=6.2.4 local URL=http://download.redis.io/releases/redis-6.2.4.tar.gz local INSTALL_DIR=/apps/redis local PASSWORD=123456 echo -e "\n\e[1;35m 安装的版本是redis-${VERSION},如果不想安装此版本请在5秒内停止运行脚本 \e[0m" echo -e "\e[1;35m redis密码是123456 \e[0m" echo -e "\e[1;35m 安装目录是${INSTALL_DIR} \e[0m" echo -e "\e[1;35m 官网下载很慢建议提前下载好放在root目录下 \e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done echo -e "\n\e[1;35m 消除redis安装启动后的warning \e[0m" #消除三个warning #Tcp backlog #overcommit_memory cat >> /etc/sysctl.conf <<EOF net.core.somaxconn = 1024 vm.overcommit_memory = 1 EOF sysctl -p #transparent hugepage if [ $ID = 'centos' -o $ID = 'rocky' ];then echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local else #ubuntu echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local chmod +x /etc/rc.local fi echo -e "\n\e[1;35m 安装依赖包 \e[0m" #安装依赖包 支持systemd if [ $ID = 'centos' -o $ID = rocky ];then #yum -y install gcc jemalloc-devel systemd-devel software=("gcc" "jemalloc-devel" "systemd-devel" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\e[1;35m安装成功\e[0m" ; } done #ubuntu else #apt -y install make gcc libjemalloc-dev libsystemd-dev software=("make" "gcc" "libjemalloc-dev" "libsystemd-dev" ) for i in ${software[@]} do dpkg -l $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { apt -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done fi #下载源码 if [ -e /root/redis-${VERSION}.tar.gz ];then echo -e "\n\e[1;35m 文件存在,开始安装\e[0m" else echo -e "\n\e[1;33m 文件不存在,开始下载\e[0m" wget ${URL} && echo -e "\n\e[1;32m 下载成功\e[0m" || echo -e "\n\e[1;31m 下载失败,请检查下载链接\e[0m" fi echo -e "\n\e[1;35m 解压 \e[0m" tar xvf /root/redis-${VERSION}.tar.gz #编译安装 支持systemd echo -e "\n\e[1;35m 编译安装 \e[0m" cd /root/redis-${VERSION} #指定redis安装目录 make -j 2 USE_SYSTEMD=yes PREFIX=${INSTALL_DIR} install [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" ln -s ${INSTALL_DIR}/bin/redis-* /usr/bin/ #配置环境变量 echo -e "\n\e[1;35m 配置环境变量\e[0m" echo 'PATH=/apps/redis/bin:$PATH' > /etc/profile.d/redis.sh [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" #准备相关目录和配置文件 #创建配置文件、日志、数据等目录 echo -e "\n\e[1;35m 创建配置文件、日志、数据等目录\e[0m" mkdir -p ${INSTALL_DIR}/{etc,log,data,run} [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" cp redis.conf ${INSTALL_DIR}/etc/ sed -i -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e "/# requirepass/a requirepass ${PASSWORD}" -e "/^dir .*/c dir ${INSTALL_DIR}/data/" -e "/logfile .*/c logfile ${INSTALL_DIR}/log/redis-6379.log" -e "/^pidfile .*/c pidfile ${INSTALL_DIR}/run/redis_6379.pid" ${INSTALL_DIR}/etc/redis.conf #前台启动 redis #redis-server /apps/redis/etc/redis.conf echo -e "\n\e[1;35m 创建redis用户\e[0m" #创建redis用户 if id redis &> /dev/null;then echo -e "\n\e[1;35m 用户已存在 \e[0m" else groupadd -g 679 -r redis && useradd -g redis -r -s /sbin/nologin -d /data/redis -u 679 redis [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" fi #设置目录权限 chown -R redis.redis ${INSTALL_DIR} #创建 Redis 服务 Service 文件 #可以复制CentOS8利用yum安装Redis生成的redis.service文件,进行修改 #cp /lib/systemd/system/redis.service /lib/systemd/system/ echo -e "\n\e[1;35m 配置service文件 \e[0m" cat >> /lib/systemd/system/redis.service <<EOF [Unit] Description=Redis persistent key-value database After=network.target [Service] ExecStart=${INSTALL_DIR}/bin/redis-server ${INSTALL_DIR}/etc/redis.conf --supervised systemd ExecStop=/bin/kill -s QUIT \$MAINPID #如果支持systemd可以启用此行 Type=notify User=redis Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=0755 LimitNOFILE=1000000 #指定此值才支持更大的maxclients值 [Install] WantedBy=multi-user.target EOF [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" echo -e "\n\e[1;35m 启动redis \e[0m" systemctl daemon-reload systemctl enable --now redis [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m" systemctl status redis #验证客户端连接redis #${INSTALL_DIR}/bin/redis-cli -h IP/HOSTNAME -p PORT -a PASSWORD echo -e "\n\e[1;35m 连接redis命令 \e[0m" echo -e "\n\e[1;35m redis-cli -h IP/HOSTNAME -p PORT -a PASSWORD \e[0m" echo -e "\n\e[1;35m redis-cli -a PASSWORD \e[0m" } compile_install_keepalived(){ local VERSION=2.2.7 local URL=https://keepalived.org/software/keepalived-${VERSION}.tar.gz echo -e "\n\e[1;35m安装的版本是keepalived-${VERSION},如果不想安装此版本请在5秒内停止运行脚本 \e[0m\n" for i in {5..1} do echo -n "${i} " echo -ne "\r" sleep 1 done if [ $ID = centos -o $ID = rocky ];then yum -y install gcc curl openssl-devel libnl3-devel net-snmp-devel else apt update apt -y install make gcc ipvsadm build-essential pkg-config automake autoconf libipset-dev libnl-3-dev libnl-genl-3-dev libssl-dev libxtables-dev libip4tc-dev libip6tc-dev libipset-dev libmagic-dev libsnmp-dev libglib2.0-dev libpcre2-dev libnftnl-dev libmnl-dev libsystemd-dev fi if [ -e keepalived-${VERSION}.tar.gz ];then echo -e "\n\e[1;35m文件存在,开始安装\e[0m" else wget ${URL} && echo -e "\n\e[1;32m下载成功,开始解压安装\e[0m" || echo -e "\n\e[1;31m下载失败,检查下载路径\e[0m" fi [ -d /usr/local/src ] || mkdir -p /usr/local/src echo -e "\n\e[1;35m开始解压\e[0m" tar xvf keepalived-${VERSION}.tar.gz -C /usr/local/src echo -e "\n\e[1;35m开始编译\e[0m" cd /usr/local/src/keepalived-${VERSION}/ ./configure --prefix=/usr/local/keepalived --disable-fwmark make && make install echo -e "\n\e[1;35m拷贝配置文件\e[0m" mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf.sample /etc/keepalived/keepalived.conf systemctl enable --now keepalived.service echo -e "\n\e[1;35m修改配置文件\e[0m" sed -i 's/vrrp_strict/#vrrp_strict/' /etc/keepalived/keepalived.conf [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false\e[0m" echo -e "\n\e[1;35m重启进程,等待10秒查看服务状态\e[0m" killall keepalived for i in {10..1} do echo -n "${i} " echo -ne "\r" sleep 1 done systemctl restart keepalived.service echo -e "\n\e[1;35m查看运行状态\e[0m" systemctl status keepalived.service | awk "NR==3" } install_jumpserver(){ echo -e "\n\e[1;35m官方在线部署\e[0m" curl -sSL https://github.com/jumpserver/jumpserver/releases/download/v2.28.7/quick_start.sh | bash } ubuntu_docker(){ ${PURPLE} 还没写 $END } install_podman(){ ${PURPLE} 还没写 $END } install_dns(){ ${PURPLE} dns $END } install_lvs(){ ${PURPLE} lvs $END } install_tomcat(){ ${PURPLE} tomcat $END } install_haproxy(){ ${PURPLE} haproxy $END } install_zabbix(){ ${PURPLE} zabbix $END } install_jenkins(){ ${PURPLE} jenkins $END } install_halo(){ ${PURPLE} halo $END } install_lua(){ ${PURPLE} lua $END } install_gitlab(){ ${PURPLE} gitlab $END } install_git(){ ${PURPLE} git $END } install_wordpress(){ ${PURPLE} wordpress $END } install_apache(){ ${PURPLE} apache $END } install_jdk(){ ${PURPLE} jdk $END } install_php(){ ${PURPLE} php $END } install_phpadmin(){ ${PURPLE} phpadmin $END } install_memcached(){ ${PURPLE} memcached $END } install_keepalived(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装keepalived ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.编译安装 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) compile_install_keepalived ;; 0) set_et ;; esac done } install_redis(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装Redis ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.编译安装 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) compile_install_redis ;; 0) set_et ;; esac done } install_clickhouse(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ======================================================== RedHat系列是直接yum下载安装 Debian系列是直接apt下载安装 包安装是自动下载官网tgz包再安装 ======================================================== ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装clickhouse ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.RedHat系列 ********** ********** 3.Debian系列 ********** ********** 4.包安装 ********** ********** 5.源码编译 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) redhat_install_clickhouse ;; 3) debian_install_clickhouse ;; 4) tgz_install_clickhouse ;; 5) compile_install_clickhouse ;; 0) set_et ;; esac done } install_docker(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ======================================================== CentOS7yum源安装,只不过选项3用起来有点问题 Ubuntu安装还没写 安装podman还没写 二进制安装可在线可离线 ======================================================== ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装docker ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.CentOS7yum源安装 ********** ********** 3.CentOS7yum源安装 ********** ********** 4.CentOS8yum源版本 ********** ********** 5.Ubuntu安装 ********** ********** 6.二进制安装 ********** ********** 7.安装podman ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) c7_yum_docker ;; 3) c7_yum2_docker ;; 4) c8_yum_docker ;; 5) ubuntu_docker ;; 6) offline_install_docker ;; 7) install_podman ;; 0) set_et ;; esac done } set_net(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 网卡配置 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.配置Redhat7以上系列网卡文件 ********** ********** 3.配置Redhat6版本网卡文件 ********** ********** 4.配置Ubuntu网卡文件 ********** ********** ============================ ********** ********** 5.Redhat系列修改网卡名为eth0 ********** ********** 6.Ubuntu修改网卡名为eth0 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 2) configure_redhat_IP_address ;; 3) configure_redhat6_IP_address ;; 4) configure_ubuntu_IP_address ;; 5) set_redhat_netname ;; 6) set_ubuntu_netname ;; 1) break ;; 0) set_et ;; esac done } set_yum(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ============================================================ centos7.9的建议用8选项 2选项是没有挂载光盘 3选项是附带挂载光盘 ============================================================ ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 配置yum源 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.配置Rocky8 yum源 ********** ********** 3.配置Rocky8 yum源 ********** ********** 4.配置Rocky8 EPEL源 ********** ********** ======================= ********** ********** 5.配置centos7 阿里源 ********** ********** 6.配置centos7 EPEL源 ********** ********** 7.配置centos7.9 清华源 ********** ********** 8.配置centos7.9 yum源 ********** ********** ======================= ********** ********** 9.配置centos6.10 yum源 ********** ********** 10.配置centos6 EPEL源 ********** ********** 11.配置centos6.5 yum源 ********** ********** 12.配置centos6.6 yum源 ********** ********** ======================= ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 2) set_yum2_rocky8 ;; 3) set_yum_rocky8 ;; 4) set_epel_rocky8 ;; 5) set_yum_centos7 ;; 6) set_epel_centos7 ;; 7) set_yum1_centos7 ;; 8) set_yum2_centos7 ;; 9) set_yum_centos610 ;; 10) set_epel_centos6 ;; 11) set_yum_centos65 ;; 12) set_yum_centos66 ;; 1) break ;; 0) set_et ;; esac done } set_firewalld(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 关闭防火墙 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.Redhat7以上版本 ********** ********** 3.Redhat6版本 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) disable_firewalld ;; 3) stop_centos6_firewalld ;; 0) set_et ;; esac done } software(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ======================================== Ubuntu和redhat安装的软件多少不一样 ======================================== ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装初始化软件 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.Redhat7,8系列 ********** ********** 3.Redhat6系列 ********** ********** 4.Ubuntu系列 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 1) break ;; 2) c7_software ;; 3) c6_software ;; 4) Ubuntu_software ;; 0) set_et ;; esac done } time1(){ clock -s } time2(){ clock -w } set_all(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 系统设置 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.关闭防火墙 3.关闭SELINUX ********** ********** 4.安装初始化软件 5.配置yum源 ********** ********** ==================== ********** ********** 6.网卡配置 7.修改别名 ********** ********** 8.修改主机名颜色 9.修改主机名 ********** ********** ==================== ********** ********** 10.设置vim 11.设置时区 ********** ********** 12.设置登录显示 13.矫正软件时间 ********** ********** ==================== ********** ********** 14.矫正硬件时间 15.垃圾桶 ********** ********** 16.设置邮箱 17.优化ulimit ********** ********** ==================== ********** ********** 18.禁用swap 19.启用swap ********** ********** 20.修改ssh端口号 21.ubuntu远程登录********** ********** ********** ********** 0.退出 ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 2) set_firewalld ;; 3) disable_selinux ;; 4) software ;; 5) set_yum ;; 6) set_net ;; 7) set_alias ;; 8) set_PS1 ;; 9) set_hostname ;; 10) set_vim ;; 11) set_timezone ;; 12) set_motd1 ;; 13) time1 ;; 14) time2 ;; 15) set_rm ;; 16) set_mail ;; 17) set_ulimit ;; 18) stop_swap ;; 19) start_swap ;; 20) set_ssh ;; 21) ubuntu_root_login ;; 1) break ;; 0) set_et ;; esac done } install_service(){ while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ************************************************************ ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** 安装服务 ********** ********** ********** ********** 1.返回上一目录 ********** ********** ********** ********** 2.二进制安装MySQL ********** ********** 3.yum源安装MySQL ********** ********** 4.二进制安装MariaDB ********** ********** 5.yum源安装MariaDB ********** ********** =================== ********** ********** 6.编译安装Nginx ********** ********** 7.升级Nginx ********** ********** 8.升级srun-Nginx ********** ********** 9.升级旧版本srun-Nginx ********** ********** =================== ********** ********** 10.升级安装openssl ********** ********** 11.升级安装openssh ********** ********** =================== ********** ********** 12.安装docker ********** ********** 13.安装clickhouse ********** ********** 14.安装Redis ********** ********** 15.安装keepalived ********** ********** 16.安装jumpserver ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu case $Menu in 2) install_mysql ;; 3) rpm_install_mysql ;; 4) install_mariadb ;; 5) yum_mariadb ;; 6) install_nginx ;; 7) update_nginx ;; 8) update_srunnginx ;; 9) update_srunnginx2 ;; 10) update_openssl ;; 11) update_openssh ;; 12) install_docker ;; 13) install_clickhouse ;; 14) install_redis ;; 15) install_keepalived ;; 16) install_jumpserver ;; 17) install_zabbix ;; 18) install_haproxy ;; 19) install_jenkins ;; 20) install_halo ;; 20) install_lua ;; 21) install_gitlab ;; 22) install_git ;; 23) install_wordpress ;; 24) install_apache ;; 25) install_jdk ;; 26) install_php ;; 27) install_phpadmin ;; 28) install_memcached ;; 1) break ;; 0) set_et ;; esac done } update_log(){ echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2023-2-17 version:csh" echo "新增keepalived" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2023-2-15 version:csh" echo "新增redis" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2023-2-3 version:csh" echo "新增clickhouse" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2023-2-2 version:csh" echo "新增docker" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2023-1-27 version:csh" echo "升级nginx,升级openssl" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2022-12-27 version:csh-v1.0" echo "改进网卡配置流程" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2022-12-07 version:csh-v9.7.7.06" echo "添加编译升级安装openssh,openssl" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2022-11-28 version:csh-v9.7.7.04" echo "完善一些功能" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2022-11-27 version:csh-v9.7.7.02" echo "添加mariadb,yum安装,二进制安装" echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" echo "2022-11-26 version:csh-v9.7.7.01" echo "修改centos7yum源," echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m" } re(){ init 6 } shut(){ init 0 #shutdown -r now } set_openEuler(){ echo -e "\e[1;33m基础的系统初始化,openEuler,centos,rocky,ubuntu系列都可以用\e[0m" echo -e "\e[1;33m初始化内容:更新yum源,安装软件,关闭防火墙,关闭selinux,优化limits\e[0m" sleep 2 echo -e "\n\e[1;35m1.更新yum源\e[0m" yum clean all yum makecache echo -e "\n\e[1;35m安装软件\e[0m" if [[ $ID =~ centos|rocky|openEuler ]];then software=("lrzsz" "vim-enhanced" "bash-completion" "wget" "tcpdump" "psmisc" "rsync" "net-tools" "mlocate" "bzip2" "zip" "unzip" "lsof" "telnet" "bridge-utils.x86_64" "libtalloc" "libtalloc-devel" "libpcap" "libpcap-devel" ) for i in ${software[@]} do rpm -q $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done else software=("lrzsz" "vim" "bash-completion" "wget" "tcpdump" "psmisc" "rsync" "net-tools" ) for i in ${software[@]} do dpkg -l $i &> /dev/null && echo -e "$i\e[1;32m已安装\e[0m" || { apt -y install $i &> /dev/null ; echo -e "$i\e[1;35m安装成功\e[0m" ; } done fi #yum -y install vim lrzsz tar.x86_64 net-tools.x86_64 telnet ftp bridge-utils.x86_64 libtalloc libtalloc-devel psmisc libpcap libpcap-devel tcpdump sleep 2 echo -e "\n\e[1;35m2.关闭防火墙\e[0m" systemctl disable --now firewalld #[ $? -eq 0 ] && echo -e "\e[1;34m 已关闭防火墙! \e[0m" || { echo -e "\e[1;31m 关闭失败! \e[0m";exit; } #systemctl status firewalld [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" sleep 2 echo -e "\n\e[1;35m3.关闭selinux\e[0m" sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" sleep 2 echo -e "\n\e[1;35m4.优化limits\e[0m" cat >> /etc/security/limits.conf << EOF * soft nofile 65535 * hard nofile 65535 EOF if [ $ID = 'centos' -o $ID = 'rocky' ];then echo "PS1='\[\e[1;34m\][\[\e[$[RANDOM%7+31]m\]\u\[\e[$[RANDOM%7+31]m\]@\[\e[$[RANDOM%7+31]m\]\h\[\e[$[RANDOM%7+31]m\]\W\[\e[34m\]]\\$\[\e[0m\]'" >> /etc/bashrc #echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc #color "修改成功 " 0 [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" else echo "PS1='\[\e[1;34m\][\[\e[$[RANDOM%7+31]m\]\u\[\e[$[RANDOM%7+31]m\]@\[\e[$[RANDOM%7+31]m\]\h\[\e[$[RANDOM%7+31]m\]\W\[\e[34m\]]\\$\[\e[0m\]'" >> ~/.bashrc #echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc #color "修改成功 " 0 [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m" fi #echo -e "\e[1;32m初始化完成!重启生效配置!\e[0m" #CPU=`grep -c processor /proc/cpuinfo` INFO=`cat /proc/cpuinfo | grep name | cut -d: -f2 |uniq -c | tr -s ' '` MEM=`free -h | head -n2 |tail -n1 | awk '{print $2}'` DISK=`lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4` SYSTEM=`uname -m` echo -e "\n\e[1;35m逻辑cpu个数 cpu型号 系统架构:$INFO $SYSTEM\e[0m" echo -e "\n\e[1;35m内存总大小:$MEM\e[0m" echo -e "\n\e[1;35m硬盘总大小:$DISK\e[0m" sleep 2 init 6 } one_step(){ while :;do echo -e "\n\e[1;$[RANDOM%7+31]m ^_^~~~^_^centos7一键初始化 ^_^~~~^_^\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m1.关闭防火墙\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m2.selinux\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m3.优化limit\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m4.修改centos7-yum源\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m5.软件安装\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m6.添加vim开头显示\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m7.修改登录显示\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m8.修改网卡名\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m9.添加别名\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m10.修改主机名颜色\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m11.网卡配置\e[0m" echo -e "\n\e[1;$[RANDOM%7+31]m0.退出\e[0m\n" read -p "$(echo -e '\e[1;35m输入序号: \e[0m')" OOOO case $OOOO in 1) disable_firewalld ;; 2) disable_selinux ;; 3) set_ulimit ;; 4) set_yum2_centos7 ;; 5) c7_software ;; 6) set_vim ;; 7) set_motd ;; 8) set_redhat_netname ;; 9) set_alias ;; 10) set_PS1 ;; 11) configure_redhat_IP_address ;; 0) set_et ;; esac done } while :;do echo -e "\E[$[RANDOM%7+31];1m" cat << EOF ======================================================== openEuler是一键配置基础的系统初始化 支持openEuler,centos7,rocky8 centos6需要自行去系统设置里面进行配置 ======================================================== ************************************************************ ************************************************************ ************************************************************ ********** ********** ********** Linux运维脚本 ********** ********** ********** ********** 1.系统设置 ********** ********** 2.安装服务 ********** ********** 3.openEuler ********** ********** 4.一键配置初始化 ********** ********** 5.更新日志 ********** ********** 6.系统信息 ********** ********** 7.重启 ********** ********** 8.关机 ********** ********** ********** ********** 0.退出 ********** ********** ********** ************************************************************ ************************************************************ ************************************************************ EOF echo -e "\E[0m" read -p "$(echo -e '\e[1;34m输入选项: \e[0m')" option case $option in 1) set_all ;; 2) install_service ;; 3) set_openEuler ;; 4) one_step ;; 5) update_log ;; 6) systeminfo ;; 7) re ;; 8) shut ;; 0) set_et ;; esac done