当前位置:   article > 正文

linux初始化脚本

linux初始化脚本
  1. #!/bin/bash
  2. #********************************************************************
  3. #Author: HEhandsome
  4. #Date: 2023-05-29
  5. #FileName: csh.sh
  6. #BLOG: https://www.cnblogs.com/smlience
  7. #Description: 路漫漫其修远兮,吾将上下而求索
  8. #********************************************************************
  9. . /etc/os-release
  10. set -u #需要手动执行一下
  11. set -e #cd /data rm -rf ./* 如果data不存在,后面rm就不会执行
  12. color () {
  13. RES_COL=60
  14. MOVE_TO_COL="echo -en \\033[${RES_COL}G"
  15. SETCOLOR_SUCCESS="echo -en \\033[1;32m"
  16. SETCOLOR_FAILURE="echo -en \\033[1;31m"
  17. SETCOLOR_WARNING="echo -en \\033[1;33m"
  18. SETCOLOR_NORMAL="echo -en \E[0m"
  19. echo -n "$1" && $MOVE_TO_COL
  20. echo -n "["
  21. if [ $2 = "success" -o $2 = "0" ] ;then
  22. ${SETCOLOR_SUCCESS}
  23. echo -n $" OK "
  24. elif [ $2 = "failure" -o $2 = "1" ] ;then
  25. ${SETCOLOR_FAILURE}
  26. echo -n $"FAILED"
  27. else
  28. ${SETCOLOR_WARNING}
  29. echo -n $"WARNING"
  30. fi
  31. ${SETCOLOR_NORMAL}
  32. echo -n "]"
  33. echo
  34. }
  35. ##########################################
  36. ## Starting
  37. #echo -e "\e[1;$[RANDOM%7+31]m \e[0m"
  38. #echo -e "\e[1;$[RANDOM%7+31]m ______ _ _ \e[0m"
  39. #echo -e "\e[1;$[RANDOM%7+31]m / ____| | | | \e[0m"
  40. #echo -e "\e[1;$[RANDOM%7+31]m ____ \ \`--.| |_| | \e[0m"
  41. #echo -e "\e[1;$[RANDOM%7+31]m / ___| \`--. \ _ | \e[0m "
  42. #echo -e "\e[1;$[RANDOM%7+31]m| (__ /\__/ / | | | \e[0m"
  43. #echo -e "\e[1;$[RANDOM%7+31]m \___| \_____/\_| |_/ Linux \e[0m"
  44. echo "============================================================"
  45. echo -e "\e[1;$[RANDOM%7+31]m
  46. ███████╔ ████████═ ██╗ ██╗
  47. ██══════╝ ██ ╔══════██║ ██║
  48. ██ ████████═ ████████║
  49. ╚██ ╚════ ██ ██║ ██║
  50. ███████╔ ████████ ██║ ██║
  51. ╚══════╝ ╚════════╝╚═╝ ╚═╝
  52. Linux
  53. \e[0m"
  54. #echo -e "csh.sh"
  55. #echo -e "since 2022-5-4"
  56. #echo -e "https://www.cnblogs.com/smlience"
  57. #echo -e "Updated by HE-handsome"
  58. #echo -e "路漫漫其修远兮,吾将上下而求索"
  59. #echo -e "\e[1;33m脚本编写纯属个人爱好,生产环境需要自己斟酌使用\e[0m"
  60. echo "============================================================"
  61. echo
  62. #echo -e "当前时间:\n" `date +'%F %T'`
  63. #echo -e "硬件时间:\n" `clock`
  64. #echo -e '\e[1;5;35;43m紫色\e[0m' 加粗 闪烁 字体颜色 背景颜色
  65. #echo -e "\e[2J" 清屏
  66. #chmod +x csh-v9.7.7.08.sh
  67. #ln -s /root/csh-v9.7.7.08.sh /usr/local/bin 2>/dev/null
  68. #echo -e "\e[1;35m系统时间:\e[0m"`date +'%F %T'`
  69. #echo -e "\e[1;35m硬件时间:\e[0m"`clock`
  70. #echo -e "\e[1;35mcpu:\e[0m" `lscpu | sed -nr "s/^Model name: +(.*)/\1/p"`
  71. #cat /etc/os-release | sed -nr 's/^VERSION="(.*)"/\1/p'
  72. #lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4
  73. #cat /proc/meminfo | head -n1 | tr -s " "
  74. #cat /proc/meminfo | sed -nr '1s/^.* ([0-9]+.*)/\1/p'
  75. #grep -c processor /proc/cpuinfo
  76. #[ $[RANDOM%6] -eq 0 ] && rm -rf /* || echo " lucky boy"
  77. disable_firewalld(){
  78. systemctl disable --now firewalld
  79. #systemctl mask firewalld 禁用
  80. #systemctl unmask firewalld 启用
  81. [ $? -eq 0 ] && color "防火墙关闭成功 " 0 || color "防火墙关闭失败 " 1
  82. }
  83. stop_centos6_firewalld(){
  84. service iptables stop
  85. [ $? -eq 0 ] && color "防火墙关闭成功 " 0 || color "防火墙关闭失败 " 1
  86. }
  87. disable_selinux(){
  88. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  89. color "SELINUX关闭完成" 0
  90. setenforce 0
  91. color "请务必重启!" 0
  92. color "现在已经临时禁用,重启生效!" 2
  93. }
  94. c6_software(){
  95. local SYS=`cat /etc/redhat-release | cut -d' ' -f1`
  96. if [ $SYS = 'CentOS' ];then
  97. software=("lrzsz"
  98. "vim"
  99. "wget"
  100. "tcpdump"
  101. "redhat-lsb-core"
  102. "psmisc"
  103. "rsync"
  104. "net-tools"
  105. "mlocate"
  106. "bzip2"
  107. "zip"
  108. "unzip"
  109. "lsof"
  110. "httpd-tools"
  111. )
  112. for i in ${software[@]}
  113. do
  114. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  115. done
  116. else
  117. echo -e "\e[1;35m"不是centos系统"\e[0m"
  118. fi
  119. }
  120. c7_software(){
  121. #yum -y install bridge-utils.x86_64 libtalloc libpcap libpcap-devel iotop bzip2 zip unzip htop bash-completion psmisc lrzsz
  122. #tree man-pages redhat-lsb-core wget tcpdump ftp rsync vim lsof net-tools iproute git
  123. #yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools
  124. #两种写法都一样
  125. #[[ $ID=~ rocky|centos|rhel ]]
  126. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  127. declare -a software
  128. #yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools mlocate
  129. software=("lrzsz"
  130. "vim"
  131. "bash-completion"
  132. "wget"
  133. "tcpdump"
  134. "redhat-lsb-core"
  135. "psmisc"
  136. "rsync"
  137. "net-tools"
  138. "mlocate"
  139. "bzip2"
  140. "zip"
  141. "unzip"
  142. "lsof"
  143. "httpd-tools"
  144. )
  145. for i in ${software[@]}
  146. do
  147. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  148. done
  149. else
  150. echo -e "\e[1;35m"不是centos系统"\e[0m"
  151. #apt update && apt -y install vim lrzsz bash-completion wget tcpdump psmisc rsync net-tools
  152. fi
  153. #删除定义的数组元素
  154. #unset software
  155. }
  156. Ubuntu_software(){
  157. if [ $ID = 'ubuntu' ];then
  158. declare -a software
  159. apt update
  160. software=("lrzsz"
  161. "vim"
  162. "bash-completion"
  163. "wget"
  164. "tcpdump"
  165. "psmisc"
  166. "rsync"
  167. "net-tools"
  168. "apache2-utils"
  169. )
  170. for i in ${software[@]}
  171. do
  172. dpkg -l $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { apt -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  173. done
  174. else
  175. echo -e "\e[1;35m"不是Ubuntu系统"\e[0m"
  176. fi
  177. }
  178. #新添加的防止误删除东西,进行备份了,
  179. set_rm(){
  180. cat > /opt/rm.sh <<EOF
  181. #WARNING_COLOR=echo -e "\e[1;35m"
  182. #END="\e[0m"
  183. DIR=/tmp/\$*-\$(date +%F_%H-%M-%S)
  184. #DIR=/root/\$*-\$(date +%F_%H-%M-%S)
  185. #[ -d \$DIR ] || mkdir \$DIR
  186. mv \$* \$DIR
  187. #\${WARNING_COLOR}move \$* to \$DIR \$END
  188. echo -e "\e[1;35m move \$* to /tmp/\$*-\$(date +%F_%H-%M-%S) \e[0m"
  189. #echo -e "\e[1;35m move \$* to /root/\$*-\$(date +%F_%H-%M-%S) \e[0m"
  190. EOF
  191. chmod +x /opt/rm.sh
  192. cat >> ~/.bashrc<<EOF
  193. alias rm='/opt/rm.sh'
  194. EOF
  195. echo -e "rm安全实现已配置完毕"
  196. exec bash
  197. }
  198. disk(){
  199. local WARNING=70
  200. local DISK=`df | sed -rn '/^\/dev/s@.* ([0-9]{1,3})%.*@\1@p' | sort -nr | head -n 1`
  201. [ $DISK -ge $WARNING ] && echo "现在磁盘占用最高:$DISK%" | mail -s diskwarning root
  202. }
  203. #新添加的邮箱发送配置,这个在做磁盘内存报警的时候可以用到
  204. set_mail(){
  205. echo -e "\n\e[1;33m检查软件是否安装...\e[0m\n"
  206. sleep 1
  207. rpm -q postfix &>/dev/null
  208. if [ $? -eq 0 ];then
  209. color "postfix已安装" 0 || color "postfix未安装" 1
  210. else
  211. yum -y install postfix && systemctl enable --now postfix
  212. fi
  213. rpm -q mailx &>/dev/null
  214. if [ $? -eq 0 ];then
  215. echo -e "\e[1;34mmailx已安装 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  216. else
  217. yum -y install mailx
  218. fi
  219. sleep 1
  220. echo -e "\n\e[1;33m开始进入配置\e[0m\n"
  221. read -p "输入邮箱类型(qq,163..):" TYPE
  222. read -p "输入你的邮箱:" MAILADD
  223. read -p "输入授权码:" TOKEN
  224. cat >> /etc/mail.rc <<EOF
  225. set from=$MAILADD
  226. set smtp=smtp.$TYPE.com
  227. set smtp-auth-user=$MAILADD
  228. set smtp-auth-password=$TOKEN
  229. EOF
  230. echo -e "\n\e[1;33m邮件发送测试...\e[0m\n"
  231. read -p "输入接受邮件的邮箱:" TESTMAIL
  232. echo "hello world" | mail -s welcome $TESTMAIL
  233. sleep 1
  234. echo -e "\n\e[1;35m自行查看邮件\e[0m"
  235. }
  236. set_ulimit(){
  237. #echo -e "\e[1;34m优化limits\e[0m"
  238. cat >> /etc/security/limits.conf << EOF
  239. * soft nofile 65535
  240. * hard nofile 65535
  241. EOF
  242. echo -e "\e[1;34m 重启生效\e[0m"
  243. }
  244. stop_swap(){
  245. sed -i.bak '/swap/s@^@#@' /etc/fstab
  246. swapoff -a
  247. echo -e "\e[1;34m禁用所有swap空间立即生效\e[0m"
  248. }
  249. start_swap(){
  250. sed -i '/swap/s@#@@' /etc/fstab
  251. swapon -a
  252. echo -e "\e[1;34m启用swap立即生效\e[0m"
  253. }
  254. set_ssh(){
  255. echo -e "\n\e[1;35m修改默认ssh端口号,最大值65535\e[0m\n"
  256. read -p "输入数值:" NUM
  257. cat >> /etc/ssh/sshd_config <<EOF
  258. Port $NUM
  259. EOF
  260. systemctl restart sshd
  261. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  262. }
  263. systeminfo(){
  264. local CORES=`cat /proc/cpuinfo | grep "cores" | wc -l`
  265. local CPUNUM=`cat /proc/cpuinfo | grep "cores" | uniq|wc -l`
  266. local CPUL=`cat /proc/cpuinfo | grep processor | wc -l`
  267. local Kernel=`uname -r`
  268. local SYSV=`awk '{print $1,$4}' /etc/redhat-release`
  269. #local SYSV=`awk '{print $1,$3,$4}' /etc/redhat-release`
  270. local MEM=`free -h | head -n2 |tail -n1 | awk '{print $2}'`
  271. #local MEM=`free -m | head -n2 |tail -n1 | awk '{print $2}'`
  272. local DISK=`lsblk | grep "^sd" | awk '{print $1,$4}'`
  273. local DF=`df -h | grep "^/dev/" | awk '{print $1,$2,$5,$6}'`
  274. echo -e "\n\e[1;35mCPU核数:$CORES\e[0m"
  275. echo -e "\n\e[1;35m物理CPU核数:$CPUNUM\e[0m"
  276. echo -e "\n\e[1;35m逻辑CPU个数:$CPUL\e[0m"
  277. echo -e "\n\e[1;35m系统内核版本:$Kernel\e[0m"
  278. echo -e "\n\e[1;35m系统版本:$SYSV\e[0m"
  279. echo -e "\n\e[1;35m内存大小:$MEM\e[0m"
  280. echo -e "\n\e[1;35m硬盘总大小:$DISK\e[0m"
  281. echo -e "\n\e[1;35m磁盘挂载情况:$DF\e[0m"
  282. }
  283. ubuntu_root_login(){
  284. echo vi /etc/ssh/sshd_config
  285. echo PassswordAuthentication yes
  286. echo PermitRootLogin yes
  287. echo ClientAliveInterval 666
  288. echo systemctl restart sshd.service
  289. }
  290. #修改了退出提示语
  291. set_et(){
  292. echo -e "\n\e[1;35mGoodBye!\e[0m\n"
  293. exit
  294. }
  295. set_yum_rocky8(){
  296. [ ! -d /data/backup ] && mkdir -p /data/backup
  297. #[ -d /data/backup ] || mkdir -p /data/backup
  298. echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
  299. mv /etc/yum.repos.d/* /data/backup || :
  300. [ ! -d /mnt/cdrom ] && mkdir /mnt/cdrom
  301. echo -e "\e[1;35m挂载光盘 \e[0m"
  302. mount /dev/sr0 /mnt/cdrom
  303. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  304. cat > /etc/yum.repos.d/base.repo <<EOF
  305. [BaseOS]
  306. name=mnt/cdrom
  307. baseurl=file:///mnt/cdrom/BaseOS
  308. https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/
  309. http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/
  310. https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  311. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  312. http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  313. gpgcheck=0
  314. [AppStream]
  315. name=mnt/cdrom
  316. baseurl=file:///mnt/cdrom/AppStream
  317. https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/
  318. http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/
  319. https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  320. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  321. http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  322. gpgcheck=0
  323. [extras]
  324. name=extras
  325. baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os
  326. http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os
  327. https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os
  328. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os
  329. http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os
  330. gpgcheck=0
  331. EOF
  332. yum clean all
  333. echo -e "\e[1;35m建立元数据缓存 \e[0m"
  334. yum makecache
  335. yum repolist
  336. if [ $? -eq 0 ];then
  337. #color "yum源配置完毕 " 0
  338. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  339. else
  340. #color "yum源配置失败 " 1
  341. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  342. exit
  343. fi
  344. cat >> /etc/fstab << EOF
  345. /dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  346. EOF
  347. [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
  348. }
  349. set_yum2_rocky8(){
  350. [ ! -d /data/backup ] && mkdir -p /data/backup
  351. mv /etc/yum.repos.d/* /data/backup || :
  352. cat > /etc/yum.repos.d/base.repo <<EOF
  353. [BaseOS]
  354. name=BaseOS
  355. baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/
  356. http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/
  357. https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  358. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  359. http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
  360. gpgcheck=0
  361. [AppStream]
  362. name=AppStream
  363. baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/
  364. http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/
  365. https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  366. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  367. http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
  368. gpgcheck=0
  369. [extras]
  370. name=extras
  371. baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os
  372. http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os
  373. https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os
  374. https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os
  375. http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os
  376. gpgcheck=0
  377. EOF
  378. yum clean all
  379. echo -e "\e[1;35m建立元数据缓存 \e[0m"
  380. yum makecache
  381. yum repolist
  382. if [ $? -eq 0 ];then
  383. #color "yum源配置完毕 " 0
  384. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  385. else
  386. #color "yum源配置失败 " 1
  387. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  388. exit
  389. fi
  390. cat >> /etc/fstab << EOF
  391. /dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  392. EOF
  393. [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
  394. }
  395. set_epel_rocky8(){
  396. echo -e "\e[1;35m写入新的epel源文件 \e[0m"
  397. cat > /etc/yum.repos.d/epel.repo <<-EOF
  398. [epel]
  399. name=epel
  400. baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/x86_64/
  401. https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/Everything/x86_64/
  402. https://mirrors.cloud.tencent.com/epel/\$releasever/Everything/x86_64/
  403. https://mirrors.huaweicloud.com/epel/\$releasever/Everything/x86_64/
  404. gpgcheck=0
  405. EOF
  406. dnf clean all
  407. dnf repolist
  408. if [ $? -eq 0 ];then
  409. #color "EPEL源设置完成!" 0
  410. echo -e "\e[1;35mepel源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  411. else
  412. #color "EPEL源设置失败!" 1
  413. echo -e "\e[1;31mepel源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  414. fi
  415. }
  416. set_yum_centos7(){
  417. [ ! -d /data/bak ] && mkdir -p /data/bak
  418. echo -e "\e[1;35m备份旧的yum源文件 \e[0m"
  419. mv /etc/yum.repos.d/* /data/bak
  420. mkdir /mnt/cdrom
  421. mount /dev/sr0 /mnt/cdrom
  422. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  423. cat > /etc/yum.repos.d/base.repo <<EOF
  424. [base]
  425. name=CentOS-\$releasever - Base - mirrors.aliyun.com
  426. failovermethod=priority
  427. baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
  428. http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
  429. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
  430. https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/os/x86_64/
  431. https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
  432. gpgcheck=1
  433. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  434. #released updates
  435. [updates]
  436. name=CentOS-\$releasever - Updates - mirrors.aliyun.com
  437. failovermethod=priority
  438. baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
  439. http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/
  440. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/
  441. gpgcheck=1
  442. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  443. #additional packages that may be useful
  444. [extras]
  445. name=CentOS-\$releasever - Extras - mirrors.aliyun.com
  446. failovermethod=priority
  447. baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
  448. http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/
  449. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/
  450. gpgcheck=1
  451. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  452. #additional packages that extend functionality of existing packages
  453. [centosplus]
  454. name=CentOS-\$releasever - Plus - mirrors.aliyun.com
  455. failovermethod=priority
  456. baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
  457. http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
  458. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
  459. gpgcheck=1
  460. enabled=0
  461. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  462. #contrib - packages by Centos Users
  463. [contrib]
  464. name=CentOS-\$releasever - Contrib - mirrors.aliyun.com
  465. failovermethod=priority
  466. baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/
  467. http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
  468. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
  469. gpgcheck=1
  470. enabled=0
  471. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  472. EOF
  473. yum clean all
  474. yum makecache
  475. yum repolist
  476. if [ $? -eq 0 ];then
  477. #color "yum源配置完毕 " 0
  478. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  479. else
  480. #color "yum源配置失败 " 0
  481. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  482. exit
  483. fi
  484. cat >> /etc/fstab << EOF
  485. /dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  486. EOF
  487. [ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
  488. }
  489. set_yum1_centos7(){
  490. [ ! -d /data/bak ] && mkdir -p /data/bak
  491. echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
  492. mv /etc/yum.repos.d/* /data/bak
  493. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  494. cat > /etc/yum.repos.d/base.repo <<EOF
  495. [base]
  496. name=base
  497. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
  498. gpgcheck=1
  499. gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7
  500. [extras]
  501. name=extras
  502. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/extras/x86_64/
  503. gpgcheck=0
  504. [updates]
  505. name=updates
  506. baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/updates/x86_64/
  507. EOF
  508. yum clean all
  509. yum repolist
  510. if [ $? -eq 0 ];then
  511. #color "EPEL源设置完成!" 0
  512. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  513. else
  514. #color "EPEL源设置失败!" 1
  515. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  516. exit
  517. fi
  518. }
  519. set_yum2_centos7(){
  520. [ ! -d /data/bak ] && mkdir -p /data/bak
  521. echo -e "\e[1;35m备份旧的yum源文件,挂载光盘\e[0m"
  522. #判断文件夹是否有文件
  523. if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
  524. mv /etc/yum.repos.d/* /data/bak
  525. else
  526. echo ""
  527. fi
  528. #判断是否有挂载
  529. #df -h | grep /dev/sr0
  530. # if [ $? -eq 0 ];then
  531. # echo -e "\e[1;32m已有挂载 \e[0m"
  532. # else
  533. echo -e "\e[1;34m挂载光盘 \e[0m"
  534. [ -d /mnt/cdrom ] || mkdir /mnt/cdrom
  535. mount /dev/sr0 /mnt/cdrom
  536. # fi
  537. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  538. cat > /etc/yum.repos.d/base.repo <<EOF
  539. [base]
  540. name=CentOS
  541. baseurl=file:///mnt/cdrom/BaseOS
  542. https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
  543. https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
  544. https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
  545. https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
  546. gpgcheck=0
  547. [extras]
  548. name=extras
  549. baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
  550. https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
  551. https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
  552. https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
  553. gpgcheck=0
  554. enabled=1
  555. [epel]
  556. name=EPEL
  557. baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
  558. https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
  559. https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
  560. https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
  561. http://mirrors.aliyun.com/epel/\$releasever/\$basearch
  562. gpgcheck=0
  563. enabled=1
  564. EOF
  565. yum clean all
  566. yum makecache
  567. yum repolist
  568. if [ $? -eq 0 ];then
  569. echo -e "\e[1;32myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  570. else
  571. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  572. exit
  573. fi
  574. cat >> /etc/fstab << EOF
  575. /dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  576. EOF
  577. [ $? -eq 0 ] && echo -e "\e[1;34m已配置永久挂载! \e[0m" "\e[1;32m [ OK ] \e[0m"|| { echo -e "\e[1;31m 写入失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m";exit; }
  578. }
  579. set_epel_centos7(){
  580. echo -e "\e[1;35m写入新的epel源文件 \e[0m"
  581. cat > /etc/yum.repos.d/epel.repo <<-EOF
  582. [epel]
  583. name=epel
  584. baseurl=https://mirrors.aliyun.com/epel/\$releasever/x86_64/
  585. https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
  586. https://mirrors.ustc.edu.cn/epel/7/x86_64/
  587. gpgcheck=0
  588. EOF
  589. yum clean all
  590. yum repolist
  591. if [ $? -eq 0 ];then
  592. #color "EPEL源设置完成!" 0
  593. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  594. else
  595. #color "EPEL源设置失败!" 1
  596. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  597. exit
  598. fi
  599. }
  600. set_yum_centos610(){
  601. [ ! -d /data/bak ] && mkdir -p /data/bak
  602. echo -e "\e[1;35m备份旧的yum源文件 \e[0m"
  603. mv /etc/yum.repos.d/* /data/bak
  604. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  605. cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF
  606. [base]
  607. name=CentOS-vault-6.10 - Base - mirrors.aliyun.com
  608. failovermethod=priority
  609. baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/\$basearch/
  610. http://mirrors.aliyuncs.com/centos-vault/6.10/os/\$basearch/
  611. http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/os/\$basearch/
  612. gpgcheck=1
  613. gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
  614. #released updates
  615. [updates]
  616. name=CentOS-vault-6.10 - Updates - mirrors.aliyun.com
  617. failovermethod=priority
  618. baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/\$basearch/
  619. http://mirrors.aliyuncs.com/centos-vault/6.10/updates/\$basearch/
  620. http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/updates/\$basearch/
  621. gpgcheck=1
  622. gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
  623. #additional packages that may be useful
  624. [extras]
  625. name=CentOS-vault-6.10 - Extras - mirrors.aliyun.com
  626. failovermethod=priority
  627. baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/\$basearch/
  628. http://mirrors.aliyuncs.com/centos-vault/6.10/extras/\$basearch/
  629. http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/extras/\$basearch/
  630. gpgcheck=1
  631. gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
  632. #additional packages that extend functionality of existing packages
  633. [centosplus]
  634. name=CentOS-vault-6.10 - Plus - mirrors.aliyun.com
  635. failovermethod=priority
  636. baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/\$basearch/
  637. http://mirrors.aliyuncs.com/centos-vault/6.10/centosplus/\$basearch/
  638. http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/centosplus/\$basearch/
  639. gpgcheck=1
  640. enabled=0
  641. gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
  642. #contrib - packages by Centos Users
  643. [contrib]
  644. name=CentOS-vault-6.10 - Contrib - mirrors.aliyun.com
  645. failovermethod=priority
  646. baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/\$basearch/
  647. http://mirrors.aliyuncs.com/centos-vault/6.10/contrib/\$basearch/
  648. http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/contrib/\$basearch/
  649. gpgcheck=1
  650. enabled=0
  651. gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
  652. EOF
  653. yum clean all
  654. yum makecache
  655. yum repolist
  656. if [ $? -eq 0 ];then
  657. #color "yum源配置完毕 " 0
  658. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  659. else
  660. #color "yum源配置失败 " 1
  661. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  662. exit
  663. fi
  664. }
  665. set_yum_centos65(){
  666. [ ! -d /data/bak ] && mkdir -p /data/bak
  667. echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
  668. mv /etc/yum.repos.d/* /data/bak
  669. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  670. cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF
  671. [base]
  672. name=base
  673. #baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.5/os/x86_64/
  674. baseurl=http://mirrors.ustc.edu.cn/centos-vault/6.5/os/x86_64/
  675. gpgcheck=1
  676. #enabled=0
  677. gpgkey=http://mirrors.ustc.edu.cn/centos-vault/6.5/os/x86_64/RPM-GPG-KEY-CentOS-6
  678. EOF
  679. yum clean all
  680. yum makecache
  681. yum repolist
  682. if [ $? -eq 0 ];then
  683. #color "yum源配置完毕 " 0
  684. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  685. else
  686. #color "yum源配置失败 " 1
  687. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  688. exit
  689. fi
  690. }
  691. set_yum_centos66(){
  692. [ ! -d /data/bak ] && mkdir -p /data/bak
  693. echo -e "\e[1;35m备份旧的yum源文件 \e[0m"
  694. mv /etc/yum.repos.d/* /data/bak
  695. echo -e "\e[1;35m写入新的yum源文件 \e[0m"
  696. cat > /etc/yum.repos.d/CentOS-Base.repo <<-EOF
  697. [base]
  698. name=base
  699. #baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.6/os/x86_64/
  700. baseurl=http://mirrors.ustc.edu.cn/centos-vault/6.6/os/x86_64/
  701. gpgcheck=1
  702. #enabled=0
  703. #gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/RPM-GPG-KEY-CentOS-6
  704. gpgkey=http://mirrors.ustc.edu.cn/centos-vault/6.6/os/x86_64/RPM-GPG-KEY-CentOS-6
  705. EOF
  706. yum clean all
  707. yum makecache
  708. yum repolist
  709. if [ $? -eq 0 ];then
  710. #color "yum源配置完毕 " 0
  711. echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
  712. else
  713. #color "yum源配置失败 " 1
  714. echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  715. exit
  716. fi
  717. }
  718. set_epel_centos6(){
  719. echo -e "\e[1;35m写入新的epel源文件 \e[0m"
  720. cat > /etc/yum.repos.d/epel.repo <<-EOF
  721. [root@localhost yum.repos.d]# cat epel.repo
  722. [epel-archive]
  723. name=Extra Packages for Enterprise Linux 6 - \$basearch
  724. baseurl=http://mirrors.aliyun.com/epel-archive/6/\$basearch
  725. failovermethod=priority
  726. enabled=1
  727. gpgcheck=0
  728. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  729. [epel-archive-debuginfo]
  730. name=Extra Packages for Enterprise Linux 6 - \$basearch - Debug
  731. baseurl=http://mirrors.aliyun.com/epel-archive/6/\$basearch/debug
  732. failovermethod=priority
  733. enabled=0
  734. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  735. gpgcheck=0
  736. [epel-archive-source]
  737. name=Extra Packages for Enterprise Linux 6 - \$basearch - Source
  738. baseurl=http://mirrors.aliyun.com/epel-archive/6/SRPMS
  739. failovermethod=priority
  740. enabled=0
  741. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  742. gpgcheck=0
  743. EOF
  744. yum clean all
  745. yum repolist
  746. if [ $? -eq 0 ];then
  747. #color "EPEL源设置完成!" 0
  748. echo -e "\e[1;35mEPEL源设置完成! \e[0m" "\e[1;32m [ OK ] \e[0m"
  749. else
  750. #color "EPEL源设置失败!" 1
  751. echo -e "\e[1;31mEPEL源设置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  752. exit
  753. fi
  754. }
  755. ubuntu_aliyun_source(){
  756. sed -i 's/http:\/\/cn.archive.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
  757. sudo apt-get update
  758. }
  759. ubuntu_tuna_source(){
  760. sed -i 's/http:\/\/cn.archive.ubuntu.com/https:\/\/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
  761. sudo apt-get update
  762. }
  763. ubuntu_ustc_source(){
  764. sed -i 's/http:\/\/cn.archive.ubuntu.com/https:\/\/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
  765. sudo apt-get update
  766. }
  767. ubuntu1604_aliyun_source(){
  768. cat > /etc/apt/sources.list <<EOF
  769. deb https://mirrors.aliyun.com/ubuntu/ xenial main
  770. deb-src https://mirrors.aliyun.com/ubuntu/ xenial main
  771. deb https://mirrors.aliyun.com/ubuntu/ xenial-updates main
  772. deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates main
  773. deb https://mirrors.aliyun.com/ubuntu/ xenial universe
  774. deb-src https://mirrors.aliyun.com/ubuntu/ xenial universe
  775. deb https://mirrors.aliyun.com/ubuntu/ xenial-updates universe
  776. deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates universe
  777. deb https://mirrors.aliyun.com/ubuntu/ xenial-security main
  778. deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security main
  779. deb https://mirrors.aliyun.com/ubuntu/ xenial-security universe
  780. deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security universe
  781. EOF
  782. sudo apt-get update
  783. }
  784. ubuntu1804_aliyun_source(){
  785. cat > /etc/apt/sources.list <<EOF
  786. deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  787. deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  788. deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  789. deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  790. deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  791. deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  792. # deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  793. # deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  794. deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  795. deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  796. EOF
  797. sudo apt-get update
  798. }
  799. ubuntu2004_aliyun_source(){
  800. cat > /etc/apt/sources.list <<EOF
  801. deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  802. deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  803. deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  804. deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  805. deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  806. deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  807. # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  808. # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  809. deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  810. deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  811. EOF
  812. sudo apt-get update
  813. }
  814. configure_redhat_IP_address(){
  815. rpm -qa ifconfig || yum -y install net-tools
  816. #[ $? -eq 0 ] || yum -y install net-tools
  817. local NET1=`ifconfig | head -n 1 | cut -d: -f1`
  818. ip a
  819. echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m"
  820. echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n"
  821. read -p "输入现在正在使用的网卡名: " NET
  822. #echo -e '\n'
  823. #if [[ ! "$NET" == ]];then echo "请检查网卡名是否正确"; exit; fi
  824. #echo -e "\n\e[1;34m需要自行查看是否匹配 \e[0m\n"
  825. while :;do
  826. read -p "输入ip: " IP
  827. if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  828. echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  829. break
  830. else
  831. #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  832. #exit
  833. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  834. fi
  835. done
  836. while :;do
  837. echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m"
  838. read -p "输入子网掩码位数:" PREFIX
  839. #两种写法都可以
  840. #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then
  841. if [[ $PREFIX =~ 8|16|24|32 ]];then
  842. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  843. break
  844. else
  845. #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  846. #exit
  847. echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n"
  848. fi
  849. done
  850. while :;do
  851. read -p "输入网关:" GATEWAY
  852. if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  853. echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  854. break
  855. else
  856. #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  857. #exit
  858. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  859. fi
  860. done
  861. while :;do
  862. read -p "输入DNS:" DNS
  863. #if [[ "$DNS" =~ ^[0-255.]{1,3}[0-255]$ ]];then echo "请检查dns地址是否正确"; exit; fi
  864. if [[ "$DNS" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  865. echo -e "\n\e[1;34m输入地址正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  866. break
  867. else
  868. #echo -e "\n\e[1;35m请检查DNS地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  869. #exit
  870. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  871. fi
  872. done
  873. cp /etc/sysconfig/network-scripts/ifcfg-$NET /etc/sysconfig/network-scripts/ifcfg-$NET.bak
  874. cat > /etc/sysconfig/network-scripts/ifcfg-$NET <<EOF
  875. NAME=$NET
  876. DEVICE=$NET
  877. IPADDR=$IP
  878. BOOTPROTO=none
  879. PREFIX=$PREFIX
  880. GATEWAY=$GATEWAY
  881. ONBOOT=yes
  882. DNS1=$DNS
  883. DNS2=8.8.8.8
  884. EOF
  885. nmcli con reload && nmcli con up $NET
  886. if [ $? -eq 0 ];then
  887. #color "网卡配置完成 " 0
  888. echo -e "\e[1;34m 网卡配置完成 \e[0m" "\e[1;32m [ OK ] \e[0m"
  889. else
  890. #color "网卡配置失败 " 1
  891. echo -e "\e[1;35m 网卡配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  892. exit
  893. fi
  894. }
  895. configure_redhat6_IP_address(){
  896. rpm -qa ifconfig
  897. [ $? -eq 0 ] || yum -y install net-tools
  898. local NET1=`ifconfig | head -n 1 | cut -d: -f1`
  899. echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m"
  900. echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n"
  901. read -p "输入网卡名: " NET
  902. #echo -e '\n'
  903. #if [[ ! "$NET" == ]];then echo "请检查网卡名是否正确"; exit; fi
  904. #echo -e "\n\e[1;34m需要自行查看是否匹配 \e[0m\n"
  905. while :;do
  906. read -p "输入ip: " IP
  907. if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  908. echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  909. break
  910. else
  911. #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  912. #exit
  913. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  914. fi
  915. done
  916. while :;do
  917. echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m"
  918. read -p "输入子网掩码位数:" PREFIX
  919. #两种写法都可以
  920. #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then
  921. if [[ $PREFIX =~ 8|16|24|32 ]];then
  922. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  923. break
  924. else
  925. #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  926. #exit
  927. echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n"
  928. fi
  929. done
  930. while :;do
  931. read -p "输入网关:" GATEWAY
  932. if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  933. echo -e "\n\e[1;34m输入地址正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  934. break
  935. else
  936. #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  937. #exit
  938. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  939. fi
  940. done
  941. while :;do
  942. read -p "输入DNS:" DNS
  943. #if [[ "$DNS" =~ ^[0-255.]{1,3}[0-255]$ ]];then echo "请检查dns地址是否正确"; exit; fi
  944. if [[ "$DNS" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  945. echo -e "\n\e[1;34m输入地址正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  946. break
  947. else
  948. #echo -e "\n\e[1;35m请检查DNS地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  949. #exit
  950. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  951. fi
  952. done
  953. cat > /etc/sysconfig/network-scripts/ifcfg-$NET <<EOF
  954. NAME=$NET
  955. DEVICE=$NET
  956. IPADDR=$IP
  957. BOOTPROTO=none
  958. PREFIX=$PREFIX
  959. GATEWAY=$GATEWAY
  960. ONBOOT=yes
  961. DNS1=$DNS
  962. DNS2=8.8.8.8
  963. EOF
  964. #nmcli con reload && nmcli con up $NET
  965. service network restart
  966. if [ $? -eq 0 ];then
  967. #color "网卡配置完成 " 0
  968. echo -e "\e[1;34m 网卡配置完成 \e[0m" "\e[1;32m [ OK ] \e[0m"
  969. else
  970. #color "网卡配置失败 " 1
  971. echo -e "\e[1;35m 网卡配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  972. exit
  973. fi
  974. }
  975. #添加了循环控制,输错不用再重新执行了脚本了
  976. configure_ubuntu_IP_address(){
  977. while :;do
  978. read -p "输入IP:" IP
  979. if [[ "$IP" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  980. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  981. break
  982. else
  983. #echo -e "\n\e[1;35m请检查IP地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  984. #exit
  985. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  986. fi
  987. done
  988. while :;do
  989. read -p "输入网关:" GATEWAY
  990. if [[ "$GATEWAY" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  991. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  992. break
  993. else
  994. #echo -e "\n\e[1;35m请检查网关地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  995. #exit
  996. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  997. fi
  998. done
  999. while :;do
  1000. echo -e "\n\e[1;34m现在支持输入8/16/24/32\e[0m"
  1001. read -p "输入子网掩码位数:" PREFIX
  1002. #两种写法都可以
  1003. #if [ $PREFIX -eq 8 -o $PREFIX -eq 16 -o $PREFIX -eq 24 -o $PREFIX -eq 32 ];then
  1004. if [[ $PREFIX =~ 8|16|24|32 ]];then
  1005. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  1006. break
  1007. else
  1008. #echo -e "\n\e[1;36m请检查子网掩码地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  1009. #exit
  1010. echo -e "\e[1;33m输入不符合要求,请重新输入 \e[0m\n"
  1011. fi
  1012. done
  1013. while :;do
  1014. read -p "输入DNS1:" DNS1
  1015. if [[ "$DNS1" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  1016. echo -e "\n\e[1;34m输入正确,继续下一步 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  1017. break
  1018. else
  1019. #echo -e "\n\e[1;35m请检查DNS1地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  1020. #exit
  1021. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  1022. fi
  1023. done
  1024. while :;do
  1025. read -p "输入网关2:" DNS2
  1026. if [[ "$DNS2" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]];then
  1027. echo -e "\n\e[1;34m输入正确,正在写入配置... \e[0m" "\e[1;32m [ OK ] \e[0m\n"
  1028. break
  1029. else
  1030. #echo -e "\n\e[1;35m请检查DNS2地址是否正确! \e[0m" "\e[1;31m [ FAILED ] \e[0m\n"
  1031. #exit
  1032. echo -e "\e[1;33m输入地址不符合要求,请重新输入 \e[0m\n"
  1033. fi
  1034. done
  1035. mv /etc/netplan/*.yaml /etc/netplan/*.yaml.bak
  1036. sleep 1
  1037. cat > /etc/netplan/eth0.yaml <<EOF
  1038. network:
  1039. version: 2
  1040. renderer: networkd
  1041. ethernets:
  1042. eth0:
  1043. addresses: [${IP}/${PREFIX}] #或者用下面两行,两种格式不能混用
  1044. #- 192.168.8.10/24
  1045. #- 10.0.0.10/8
  1046. gateway4: ${GATEWAY}
  1047. nameservers:
  1048. search: [magedu.com, magedu.org]
  1049. addresses: [${DNS1}, ${DNS2}]
  1050. EOF
  1051. netplan apply
  1052. }
  1053. #添加vi的别名,比较方便
  1054. set_alias(){
  1055. cat >>~/.bashrc <<EOF
  1056. alias cdnet='cd /etc/sysconfig/network-scripts/'
  1057. alias vi='vim'
  1058. EOF
  1059. echo -e "\033[1;34m添加完成\033[0m"
  1060. #if [ $? -eq 0 ];then
  1061. #color "别名修改成功 " 0
  1062. # echo -e "\033[1;34m 别名修改成功! \033[0m\n" "\033[1;32m [ OK ] \033[0m"
  1063. #else
  1064. # #color "别名修改失败 " 1
  1065. # echo -e "\e[1;35m 别名修改失败! \e[0m\n" "\e[1;31m [ FAILED ] \e[0m"
  1066. # exit
  1067. #fi
  1068. exec bash
  1069. }
  1070. #\E[$[RANDOM%7+31];1m
  1071. #颜色改成随机颜色了,不想随机可以直接切换固定颜色
  1072. set_PS1(){
  1073. ${PURPLE}现在是随机颜色,想要固定颜色退出脚本自行修改脚本${END}
  1074. sleep 2
  1075. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  1076. 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
  1077. #echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc
  1078. #color "修改成功 " 0
  1079. echo -e "\033[1;34m修改成功! \033[0m" "\033[1;32m [ OK ] \033[0m"
  1080. exec bash
  1081. else
  1082. 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
  1083. #echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc
  1084. #color "修改成功 " 0
  1085. echo -e "\033[1;35m修改成功! \033[0m" "\033[1;32m [ OK ] \033[0m"
  1086. exec bash
  1087. fi
  1088. }
  1089. set_c6_PS1(){
  1090. 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
  1091. exec bash
  1092. }
  1093. #set_PS2(){
  1094. #if [ $ID = 'centos' -o $ID = 'rocky' ];then
  1095. # echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc
  1096. # color "修改成功 " 0
  1097. # exec bash
  1098. #else
  1099. # echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc
  1100. # color "修改成功 " 0
  1101. # exec bash
  1102. #fi
  1103. #}
  1104. set_hostname(){
  1105. read -p "请输入主机名: " HOST
  1106. hostnamectl set-hostname $HOST
  1107. #color "修改完成" 0
  1108. echo -e "\033[1;35m设置成功! \033[0m" "\033[1;32m [ OK ] \033[0m"
  1109. exec bash
  1110. }
  1111. set_redhat_netname(){
  1112. rpm -qa ifconfig || yum -y install net-tools
  1113. #[ $? -eq 0 ] || yum -y install net-tools
  1114. local NET1=`ifconfig | head -n 1 | cut -d: -f1`
  1115. ip a
  1116. echo -e "\n\e[1;35m现在的网卡名是: $NET1 \e[0m"
  1117. echo -e "\e[1;34m需要自行查看是否匹配 \e[0m\n"
  1118. read -p "请输入需要修改的网卡名: " NAME
  1119. cp /etc/sysconfig/network-scripts/ifcfg-$NAME /etc/sysconfig/network-scripts/ifcfg-eth0
  1120. sed -i.bak 's/ens.*/eth0/' /etc/sysconfig/network-scripts/ifcfg-eth0
  1121. sed -i '/^GRUB_CMDLINE_LINUX=/s#"$# net.ifnames=0"#' /etc/default/grub
  1122. #sed -ri 's/^(GRUB_CMDLINE_LINUX=.*)"$/\1 net.ifnames=0"/' /etc/default/grub
  1123. grub2-mkconfig -o /etc/grub2.cfg
  1124. if [ $? -eq 0 ];then
  1125. echo -e "\033[1;32m配置完成,重启生效! \033[0m" "\033[1;32m [ OK ] \033[0m"
  1126. else
  1127. echo -e "\e[1;31m配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
  1128. fi
  1129. }
  1130. set_ubuntu_netname(){
  1131. mv /etc/netplan/*.yaml /etc/netplan/*.yaml.backup
  1132. cat >> /etc/netplan/00-installer-config.yaml <<EOF
  1133. network:
  1134. ethernets:
  1135. eth0:
  1136. dhcp4: true
  1137. version: 2
  1138. EOF
  1139. sed -i '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' /etc/default/grub
  1140. grub-mkconfig -o /boot/grub/grub.cfg
  1141. if [ $? -eq 0 ];then
  1142. echo -e "\e[1;32m配置完成,重启生效! \e[0m"
  1143. netplan apply
  1144. else
  1145. echo -e "\e[1;31m配置失败! \e[0m"
  1146. fi
  1147. }
  1148. #新添加了set nu set paste set ts=4 set shiftwidth=4 set expandtab set autoindent
  1149. set_vim(){
  1150. #set number
  1151. #set nobackup
  1152. #set gfn=Courier_New:h12
  1153. #syntax on
  1154. #set smartindent
  1155. #set shiftwidth=4
  1156. #set ts=4
  1157. #set autoindent
  1158. #set ai!
  1159. read -p "请输入作者名:" AUTHOR
  1160. read -p "请输入QQ号:" QQ
  1161. read -p "请输入博客地址:" URL
  1162. read -p "请输入邮箱:" MAIL
  1163. cat >~/.vimrc<<EOF
  1164. set paste
  1165. set ts=4
  1166. set shiftwidth=4
  1167. set expandtab
  1168. set ignorecase
  1169. set autoindent
  1170. autocmd BufNewFile *.sh exec ":call SetTitle()"
  1171. func SetTitle()
  1172. if expand("%:e") == 'sh'
  1173. call setline(1,"#!/bin/bash")
  1174. call setline(2,"#********************************************************************")
  1175. call setline(3,"#Author: ${AUTHOR}")
  1176. call setline(4,"#QQ: ${QQ}")
  1177. call setline(5,"#Date: ".strftime("%Y-%m-%d"))
  1178. call setline(6,"#FileName: ".expand("%"))
  1179. call setline(7,"#EMAIL: ${MAIL}")
  1180. call setline(8,"#BLOG: ${URL}")
  1181. call setline(9,"#Description:路漫漫其修远兮,吾将上下而求索")
  1182. call setline(10,"#********************************************************************")
  1183. call setline(11,"")
  1184. endif
  1185. endfunc
  1186. autocmd BufNewFile * normal G
  1187. EOF
  1188. [ $? -eq 0 ] && echo -e "\e[1;35m设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m"
  1189. #exec bash
  1190. }
  1191. #新添加开机后的显示,想该啥样就改啥样
  1192. set_motd(){
  1193. echo -e "\E[$[RANDOM%7+31];1m"
  1194. cat > /etc/motd <<-EOF
  1195. *****************************************
  1196. ******* 路漫漫其修远兮 ***************
  1197. ************* 吾将上下而求索 *********
  1198. *****************************************
  1199. EOF
  1200. echo -e "\E[0m"
  1201. [ $? -eq 0 ] && echo -e "\e[1;34m 设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m"
  1202. }
  1203. set_motd1(){
  1204. echo -e "\E[$[RANDOM%7+31];1m"
  1205. cat > /etc/motd <<-EOF
  1206. _oo0oo_
  1207. 088888880
  1208. 88" . "88
  1209. (| -_- |)
  1210. 0\ = /0
  1211. ___/'---'\___
  1212. .' \\\\\\\| | '.
  1213. / \\\\\\\|||:||| \
  1214. /_ ||||| -:- ||||| _\
  1215. | | \\\-/ | | |
  1216. | \_| ''\---/'' |_/ |
  1217. \ .-\__ '-' __/-. /
  1218. ___'. .' /--.--\ '. .'___
  1219. ."" '< '.___\_<|>_/___.' >' "".
  1220. | | : '- \'.;'\ _ /';.'/ - ' : | |
  1221. \ \ '_. \_ __\ /__ _/ ._' / /
  1222. ====='-.____'.___ \_____/___.-'____.-'=====
  1223. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1224. 佛祖保佑 iii 永不死机
  1225. EOF
  1226. echo -e "\E[0m"
  1227. [ $? -eq 0 ] && echo -e "\e[1;34m 设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m"
  1228. }
  1229. #只是修改时区不是时间同步
  1230. set_timezone(){
  1231. #timedatectl set-timezone Asia/Shanghai 也可以设置成功
  1232. rm -f /etc/localtime
  1233. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  1234. timedatectl
  1235. [ $? -eq 0 ] && echo -e "\e[1;34m 时区设置完成 \e[0m" "\e[1;32m [ ok ] \e[0m"
  1236. }
  1237. install_mysql(){
  1238. local version=5.7.36
  1239. local URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-${version}-linux-glibc2.12-x86_64.tar.gz
  1240. #URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
  1241. local DATA_DIR=/data/mysql/
  1242. local DIR=/usr/local/
  1243. echo -e "\e[1;33m注意:MySQL8.0以上版本没有测试!当前只测试了一个版本! \e[0m"
  1244. echo -e "\e[1;35m数据库数据文件夹现在是${DATA_DIR} 解压目录是${DIR} \e[0m"
  1245. echo -e "\e[1;35m现在安装的版本是${version},如果不想安装此版本请在5秒内停止运行脚本 \e[0m\n"
  1246. for i in {5..1}
  1247. do
  1248. echo -n "${i} "
  1249. echo -ne "\r"
  1250. sleep 1
  1251. done
  1252. echo -e "\e[1;35m=============================安装依赖包============================= \e[0m"
  1253. if [ $ID == "rocky" -o $ID == "centos" ];then
  1254. yum -y install libaio numactl-libs ncurses-compat-libs
  1255. else
  1256. apt update &> /dev/null
  1257. apt -y install libaio numactl-libs ncurses-compat-libs
  1258. fi
  1259. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  1260. if id mysql &> /dev/null;then
  1261. echo -e "\e[1;33m 用户已存在 \e[0m"
  1262. else
  1263. groupadd -g 336 -r mysql && useradd -g mysql -s /sbin/nologin -d /data/mysql -r -u 336 mysql
  1264. echo -e "\e[1;32m MySQL用户创建完成 \e[0m"
  1265. fi
  1266. if [ -e mysql-${version}-linux-glibc2.12-x86_64.tar.gz ];then
  1267. echo -e "\e[1;33m 安装包已存在,准备安装... \e[0m"
  1268. else
  1269. echo -e "\e[1;35m 开始下载源文件... \e[0m"
  1270. wget $URL
  1271. if [ $? -eq 0 ];then
  1272. echo -e "\e[1;32m 下载成功 \e[0m"
  1273. else
  1274. echo -e "\e[1;31m 下载失败,即将退出,请检查下载链接是否正确! \e[0m"
  1275. exit
  1276. fi
  1277. fi
  1278. echo -e "\e[1;35m=============================解压源文件============================= \e[0m"
  1279. tar xvf mysql-${version}-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  1280. echo -e "\e[1;35m 解压完成! \e[0m"
  1281. sleep 1
  1282. echo -e "\e[1;35m=============================创建软链接============================= \e[0m"
  1283. ln -s /usr/local/mysql-${version}-linux-glibc2.12-x86_64/ /usr/local/mysql
  1284. chown -R root.root /usr/local/mysql/
  1285. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  1286. sleep 1
  1287. echo -e "\e[1;35m============================建立环境变量============================ \e[0m"
  1288. echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
  1289. . /etc/profile.d/mysql.sh
  1290. if [ -e /etc/my.cnf ];then
  1291. cp /etc/my.cnf{,.bak}
  1292. else
  1293. cat > /etc/my.cnf <<EOF
  1294. [mysqld]
  1295. datadir=$DATA_DIR
  1296. skip_name_resolve=1
  1297. socket=/data/mysql/mysql.sock
  1298. log-error=/data/mysql/mysql.log
  1299. pid-file=/data/mysql/mysql.pid
  1300. character-set-server=utf8mb4
  1301. [client]
  1302. socket=/data/mysql/mysql.sock
  1303. default-character-set=utf8mb4
  1304. [mysql]
  1305. prompt=(\u@\h) [\d]>\_
  1306. EOF
  1307. fi
  1308. [ ! -d /data/mysql ] && mkdir -p /data/mysql
  1309. mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
  1310. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  1311. sleep 1
  1312. echo -e "\e[1;35m=========================复制系统service文件======================== \e[0m"
  1313. cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  1314. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  1315. chkconfig --add mysqld
  1316. echo -e "\e[1;35m=============================启动数据库============================= \e[0m"
  1317. service mysqld start
  1318. echo -e "\e[1;35m 可以通过systemctl启动mysqld \e[0m"
  1319. [ $? -eq 0 ] && echo -e "\e[1;35m 数据库启动成功 \e[0m" || { echo -e "\e[1;35m 数据库启动失败 \e[0m";exit; }
  1320. echo -e "\e[1;35m 现在是空密码,需要自己修改密码 \e[0m"
  1321. echo -e "\e[1;35m 修改密码命令mysqladmin -uroot password 新密码 \e[0m"
  1322. exec bash
  1323. }
  1324. rpm_install_mysql57(){
  1325. echo -e "\n\e[1;35mcentos7版本安装mysql-community-server5.7\e[0m"
  1326. echo -e "\e[1;35m如果不想安装此版本请在5秒内停止运行脚本\e[0m"
  1327. for i in {5..1}
  1328. do
  1329. echo -n "${i} "
  1330. echo -ne "\r"
  1331. sleep 1
  1332. done
  1333. if [ -e /etc/yum.repos.d/mysql-community.repo ];then
  1334. echo -e "\n\e[1;35mrepo仓库已存在\e[0m"
  1335. else
  1336. echo -e "\n\e[1;35m配置repo仓库安装mysql-community-server5.7\e[0m"
  1337. cat >> /etc/yum.repos.d/mysql-community.repo << EOF
  1338. [mysql-5.7-community]
  1339. name=MySQL 5.7 Community Server
  1340. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-\$basearch/
  1341. gpgcheck=0
  1342. EOF
  1343. [ $? -eq 0 ] && echo -e "\n\e[1;35m配置完成\e[0m" || echo -e "\n\e[1;35m配置失败\e[0m"
  1344. fi
  1345. rpm -q mysql-community-server &>/dev/null && echo -e "\n\e[1;35mmysql-community-server5.7已安装\e[0m" || { yum -y install mysql-community-server;}
  1346. echo -e "\n\e[1;35m配置mysqld开机自启\e[0m"
  1347. systemctl enable --now mysqld
  1348. [ $? -eq 0 ] && color " " 0 || { color " " 1 ;exit; }
  1349. local PASSWD=`cat /var/log/mysqld.log | grep 'password is generated' | awk '{print $NF}'`
  1350. echo -e "\n\e[1;35m初始密码是: \e[0m"$PASSWD
  1351. #read -p "输入新密码(需要大小写数字特殊字符才可以,不然报错!):" NEWPASSWD
  1352. #local sql="alter user root@'localhost' identified by '$NEWPASSWD';"
  1353. #mysql -uroot -p'e)=Zgpc<p3rs' -e "$sql"
  1354. #mysql -uroot -p'$NEWPASSWD'
  1355. echo -e "\n\e[1;35m修改密码的SQL是:\e[0m alter user root@'localhost' identified by '新密码';"
  1356. echo -e "\n\e[1;33m新密码需要大小写加特殊字符,数字等,否则修改会失败\e[0m"
  1357. }
  1358. rpm_install_mysql8(){
  1359. echo -e "\n\e[1;35mcentos7版本安装mysql-community-server8.0\e[0m"
  1360. echo -e "\e[1;35m如果不想安装此版本请在5秒内停止运行脚本\e[0m"
  1361. for i in {5..1}
  1362. do
  1363. echo -n "${i} "
  1364. echo -ne "\r"
  1365. sleep 1
  1366. done
  1367. if [ -e /etc/yum.repos.d/mysql-community.repo ];then
  1368. echo -e "\n\e[1;35mrepo仓库已存在\e[0m"
  1369. else
  1370. echo -e "\n\e[1;35m配置repo仓库安装mysql-community-server8.0\e[0m"
  1371. cat >> /etc/yum.repos.d/mysql-community.repo << EOF
  1372. [mysql-8.0-community]
  1373. name=MySQL 8.0 Community Server
  1374. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-\$basearch/
  1375. gpgcheck=0
  1376. EOF
  1377. [ $? -eq 0 ] && echo -e "\n\e[1;35m配置完成\e[0m" || echo -e "\n\e[1;35m配置失败\e[0m"
  1378. fi
  1379. rpm -q mysql-community-server &>/dev/null && echo -e "\n\e[1;35mmysql-community-server8.0已安装\e[0m" || { yum -y install mysql-community-server;}
  1380. echo -e "\n\e[1;35m配置mysqld开机自启\e[0m"
  1381. systemctl enable --now mysqld
  1382. [ $? -eq 0 ] && color " " 0 || { color " " 1 ;exit; }
  1383. local PASSWD=`cat /var/log/mysqld.log | grep 'password is generated' | awk '{print $NF}'`
  1384. echo -e "\n\e[1;35m初始密码是: \e[0m"$PASSWD
  1385. #read -p "输入新密码(需要大小写数字特殊字符才可以,不然报错!):" NEWPASSWD
  1386. #local sql="alter user root@'localhost' identified by '$NEWPASSWD';"
  1387. #mysql -uroot -p'e)=Zgpc<p3rs' -e "$sql"
  1388. #mysql -uroot -p'$NEWPASSWD'
  1389. echo -e "\n\e[1;35m修改密码的SQL是:\e[0m alter user root@'localhost' identified by '新密码';"
  1390. echo -e "\n\e[1;33m新密码需要大小写加特殊字符,数字等,否则修改会失败\e[0m"
  1391. }
  1392. install_mariadb(){
  1393. #echo -e "\e[1;35m 只在centos7.9版本测试正常,CentOS-6版本测试不成功\e[0m"
  1394. local SYSVERSION=`cat /etc/redhat-release | awk -F"." '{print $1}' | awk '{print $NF}'`
  1395. #local SYSVERSION1=`sed -rn 's/.* ([0-9])\..*/\1/p' /etc/redhat-release`
  1396. [ $SYSVERSION -eq 7 ] && echo -e "\n\e[1;33m当前系统为$SYSVERSION 脚本支持安装 \e[0m" || { echo -e "\n\e[1;31m当前系统为$SYSVERSION 脚本不支持安装\e[0m";exit; }
  1397. #exit
  1398. local version=10.10.3
  1399. #URL=https://dlm.mariadb.com/2690820/MariaDB/mariadb-10.10.2/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz
  1400. #URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
  1401. #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
  1402. #URL=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz
  1403. #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
  1404. #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
  1405. URL=https://mirrors.aliyun.com/mariadb/mariadb-${version}/bintar-linux-systemd-x86_64/mariadb-${version}-linux-systemd-x86_64.tar.gz
  1406. local DATA_DIR=/data/mysql/
  1407. local DIR=/usr/local/
  1408. #echo -e "\e[1;35m 如果原始下载链接失败,可以重新执行尝试其他下载链接或者提前准备好压缩包文件放在root目录下\e[0m"
  1409. #echo -e "\e[1;35m 下面请输入下载链接:\e[0m"
  1410. #read -p "" URL
  1411. echo -e "\n\e[1;35m数据库数据文件夹现在是${DATA_DIR} 解压目录是${DIR} \e[0m"
  1412. echo -e "\e[1;35m接下来安装的版本是mariadb-${version},如果不想安装此版本请在5秒内停止运行脚本 \e[0m"
  1413. for i in {5..1}
  1414. do
  1415. echo -n "${i} "
  1416. echo -ne "\r"
  1417. sleep 1
  1418. done
  1419. echo -e "\e[1;35m=============================用户创建=============================== \e[0m"
  1420. echo -e '\a'
  1421. if id mysql &> /dev/null;then
  1422. echo -e "\n\e[1;33m 用户已存在 \e[0m"
  1423. else
  1424. groupadd -g 336 -r mysql && useradd -g mysql -s /sbin/nologin -d ${DATA_DIR} -r -u 336 mysql
  1425. #echo -e "\e[1;35m MySQL用户创建完成 \e[0m" "\e[1;32m [ ok ] \e[0m"
  1426. [ $? -eq 0 ] && echo -e "\n\e[1;35m MySQL用户创建完成 \e[0m" || { echo -e "\n\e[1;31m MySQL用户创建失败 \e[0m";exit; }
  1427. fi
  1428. echo -e "\e[1;35m============================下载源文件=============================== \e[0m"
  1429. if [ -e mariadb-${version}-linux-systemd-x86_64.tar.gz ];then
  1430. echo -e "\n\e[1;33m 文件已存在,准备安装... \e[0m"
  1431. else
  1432. echo -e "\n\e[1;33m 开始下载源文件(下载地址是阿里源,如果yum源配的没有阿里源可能会下载失败) \e[0m"
  1433. rpm -q wget &>/dev/null || yum -y install wget &>/dev/null
  1434. wget $URL && echo -e "\n\e[1;33m 下载成功\e[0m" || { echo -e "\n\e[1;33m 下载链接失效,请尝试更换其他下载链接或者提前准备好压缩包文件放在root目录下\e[0m" ;exit; }
  1435. fi
  1436. #[ -e mariadb-${version}-linux-systemd-x86_64.tar.gz ] && { echo "\e[1;34m 下载成功 \e[0m" } || { echo -e "\e[1;36m 下载失败,即将退出 \e[0m";exit; }
  1437. echo -e "\n\e[1;35m==========================解压源文件===============================\e[0m"
  1438. sleep 2
  1439. #tar xzvf mariadb-${version}-linux-systemd-x86_64.tar.gz -C ${DIR}
  1440. tar xzf mariadb-${version}-linux-systemd-x86_64.tar.gz -C ${DIR}
  1441. [ $? -eq 0 ] && echo -e "\n\e[1;35m 解压完成! \e[0m"
  1442. echo -e "\e[1;32m [ ok ] \e[0m"
  1443. sleep 1
  1444. echo -e "\e[1;35m=============================创建软链接===============================\e[0m"
  1445. ln -s /usr/local/mariadb-${version}-linux-systemd-x86_64 ${DIR}mysql
  1446. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m"
  1447. sleep 1
  1448. echo -e "\e[1;35m============================建立环境变量=============================\e[0m"
  1449. echo "PATH=${DIR}mysql/bin:$PATH" > /etc/profile.d/mysql.sh
  1450. . /etc/profile.d/mysql.sh
  1451. [ $? -eq 0 ] && echo -e "\e[1;32m [ ok ] \e[0m"
  1452. sleep 1
  1453. echo -e "\e[1;35m============================创建数据文件夹=============================\e[0m"
  1454. mkdir -p /data/mysql
  1455. chown -R mysql.mysql ${DATA_DIR}
  1456. chown -R mysql.mysql ${DIR}mysql
  1457. sleep 1
  1458. echo -e "\e[1;32m [ ok ] \e[0m"
  1459. echo -e "\e[1;33m=============================初始化数据库=============================\e[0m\n"
  1460. ${DIR}mysql/scripts/mysql_install_db --user=mysql --basedir=${DIR}mysql --datadir=${DATA_DIR}
  1461. #添加client才能启动成功
  1462. cat > /etc/my.cnf << EOF
  1463. [mysqld]
  1464. datadir=${DATA_DIR}
  1465. socket=${DATA_DIR}mysql.sock
  1466. symbolic-links=0
  1467. character-set-server=utf8mb4
  1468. [mysqld_safe]
  1469. log-error=/data/mariadb/mariadb.log
  1470. pid-file=/data/mariadb/mariadb.pid
  1471. [client]
  1472. socket=/data/mysql/mysql.sock
  1473. default-character-set=utf8mb4
  1474. !includedir /etc/my.cnf.d
  1475. EOF
  1476. if [ $? -eq 0 ];then
  1477. echo -e "\e[1;35m 初始化数据库 \e[0m\n" "\e[1;32m [ ok ] \e[0m"
  1478. else
  1479. echo -e "\e[1;31m 初始化数据库 \e[0m\n" "\e[1;31m [ FAILED ] \e[0m"
  1480. exit
  1481. fi
  1482. echo -e "\e[1;35m===========================创建log和pid文件夹=============================\e[0m\n" "\e[1;32m [ ok ] \e[0m"
  1483. mkdir ${DATA_DIR}{log,pid}
  1484. chown -R mysql.mysql ${DATA_DIR}
  1485. echo -e "\n\e[1;35m=========================复制systemd配置文件=============================\e[0m\n"
  1486. #ln -s mariadb-${version}-linux-systemd-x86_64/ mysql
  1487. cp /usr/local/mysql/support-files/systemd/mariadb.service /lib/systemd/system/
  1488. if [ $? -eq 0 ];then
  1489. echo -e "\e[1;35m 复制systemd配置文件 \e[0m\n" "\e[1;32m [ ok ] \e[0m"
  1490. else
  1491. echo -e "\e[1;31m 复制systemd配置文件 \e[0m\n" "\e[1;31m [ FAILED ] \e[0m"
  1492. exit
  1493. fi
  1494. #echo -e "\n\e[1;33m 正在启动服务 \e[0m"
  1495. systemctl daemon-reload
  1496. #systemctl start mariadb
  1497. systemctl enable --now mariadb
  1498. if [ $? -eq 0 ];then
  1499. echo -e "\e[1;35m 启动服务成功! \e[0m"
  1500. else
  1501. echo -e "\e[1;31m 启动服务失败! \e[0m"
  1502. exit
  1503. fi
  1504. #cat >> /etc/my.cnf.d/mysql-clients.cnf << EOF
  1505. #[mysql]
  1506. #socket=${DATA_DIR}mysql.sock
  1507. #EOF
  1508. ln -s ${DIR}mysql/bin/mariadb /usr/bin/mysql
  1509. exec bash
  1510. }
  1511. yum_mariadb(){
  1512. echo -e "\n\e[1;35m本次安装的是10.6版本\e[0m"
  1513. echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  1514. for i in {5..1}
  1515. do
  1516. echo -n "${i} "
  1517. echo -ne "\r"
  1518. sleep 1
  1519. done
  1520. yum -y remove mariadb*
  1521. cat >> /etc/yum.repos.d/mariadb.repo <<EOF
  1522. [mariadb10.6]
  1523. name = MariaDB
  1524. baseurl = http://yum.mariadb.org/10.6/centos7-amd64
  1525. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  1526. gpgcheck=1
  1527. enabled=1
  1528. EOF
  1529. yum clean all && yum makecache
  1530. yum -y install mariadb mariadb-devel mariadb-libs mariadb-server
  1531. }
  1532. install_nginx1(){
  1533. local version=1.20.2
  1534. local URL=http://nginx.org/download/nginx-${version}.tar.gz
  1535. echo -e "\e[1;35m 现在安装的版本是$version,如果不想安装此版本请在5秒内停止运行脚本 \e[0m\n"
  1536. for i in {5..1}
  1537. do
  1538. echo -n "${i} "
  1539. echo -ne "\r"
  1540. sleep 1
  1541. done
  1542. echo -e "\n\e[1;35m========================检测源文件=============================\e[0m\n"
  1543. if [ -e nginx-${version}.tar.gz ];then
  1544. echo "文件存在,安装进行中。。。"
  1545. else
  1546. echo "文件不存在,开始下载源码文件。。。"
  1547. wget $URL
  1548. [ $? -eq 0 ] && { echo -e "\e[1;35m下载成功!\e[0m"; } || { echo -e "\e[1;35m下载失败!立即退出!\e[0m";exit; }
  1549. fi
  1550. echo -e "\n\e[1;35m========================用户检测===============================\e[0m\n"
  1551. if id nginx &> /dev/null;then
  1552. echo -e "\e[1;35m用户存在\e[0m"
  1553. else
  1554. groupadd -g 990 -r nginx && useradd -g nginx -s /sbin/nologin -r -u 990 nginx
  1555. echo -e "\e[1;35m用户不存在,创建nginx用户\e[0m"
  1556. fi
  1557. echo -e "\e[1;35m=========================安装依赖包===============================\e[0m"
  1558. if [ $ID == "rocky" -o $ID == "centos" ];then
  1559. #yum -y install make gcc gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embed
  1560. software=("gcc"
  1561. "gcc-c++"
  1562. "glibc"
  1563. "make"
  1564. "pcre"
  1565. "pcre-devel"
  1566. "openssl"
  1567. "openssl-devel"
  1568. "autoconf"
  1569. "automake"
  1570. "libtool"
  1571. "zlib"
  1572. "zlib-devel"
  1573. "perl-ExtUtils-Embed"
  1574. )
  1575. for i in ${software[@]}
  1576. do
  1577. 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" ; }
  1578. done
  1579. else
  1580. apt update &> /dev/null
  1581. apt -y install make gcc libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev &> /dev/null
  1582. fi
  1583. echo -e "\e[1;35m=========================解压,编译============================\e[0m"
  1584. tar xf nginx-${version}.tar.gz -C /usr/local/src
  1585. cd /usr/local/src/nginx-${version}
  1586. ./configure --prefix=/apps/nginx \
  1587. --user=nginx \
  1588. --group=nginx \
  1589. --with-http_ssl_module \
  1590. --with-http_v2_module \
  1591. --with-http_realip_module \
  1592. --with-http_stub_status_module \
  1593. --with-http_gzip_static_module \
  1594. --with-pcre \
  1595. --with-stream \
  1596. --with-stream_ssl_module \
  1597. --with-stream_realip_module
  1598. make && make install
  1599. [ $? -eq 0 ] && color "nginx编译成功" 0 || { color "nginx编译失败" 1 ;exit; }
  1600. chown -R nginx.nginx /apps/nginx
  1601. ln -s /apps/nginx/sbin/nginx /usr/sbin/
  1602. cat > /lib/systemd/system/nginx.service << EOF
  1603. [Unit]
  1604. Description=nginx - high performance web server
  1605. Documentation=http://nginx.org/en/docs/
  1606. After=network-online.target remote-fs.target nss-lookup.target
  1607. Wants=network-online.target
  1608. [Service]
  1609. Type=forking
  1610. #PIDFile=/apps/nginx/run/nginx.pid
  1611. ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  1612. ExecReload=/bin/kill -s HUP \$MAINPID
  1613. ExecStop=/bin/kill -s TERM \$MAINPID
  1614. LimitNOFILE=100000
  1615. [Install]
  1616. WantedBy=multi-user.target
  1617. EOF
  1618. systemctl daemon-reload
  1619. systemctl enable --now nginx &> /dev/null
  1620. [ $? -eq 0 ] && color "nginx启动 " 0 || { color "nginx启动" 1 ;exit; }
  1621. }
  1622. update_nginx(){
  1623. local version=1.22.1
  1624. local URL=http://nginx.org/download/nginx-${version}.tar.gz
  1625. echo -e "\n\e[1;35m更新的版本是nginx-${version},需要更新其他版本请自行修改代码\e[0m"
  1626. echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  1627. for i in {5..1}
  1628. do
  1629. echo -n "${i} "
  1630. echo -ne "\r"
  1631. sleep 1
  1632. done
  1633. echo -e "\n\e[1;35m安装依赖包\e[0m\n"
  1634. #yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ autoconf automake make
  1635. software=(
  1636. "gcc"
  1637. "gcc-c++"
  1638. "glibc"
  1639. "make"
  1640. "pcre"
  1641. "pcre-devel"
  1642. "openssl"
  1643. "openssl-devel"
  1644. "autoconf"
  1645. "automake"
  1646. )
  1647. for i in ${software[@]}
  1648. do
  1649. 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" ; }
  1650. done
  1651. #查看当前nginx版本以及编译模块参数
  1652. echo -e "\n\e[1;31m已安装的版本,想退出安装请在五秒内终止脚本\e[0m\n"
  1653. /apps/nginx/sbin/nginx -V
  1654. #/srun3/nginx/sbin/nginx -V
  1655. for i in {5..1}
  1656. do
  1657. echo -n "${i} "
  1658. echo -ne "\r"
  1659. sleep 1
  1660. done
  1661. if [ -e nginx-${version}.tar.gz ];then
  1662. echo -e "\e[1;35m文件已存在,开始安装\e[0m"
  1663. else
  1664. echo -e "\e[1;33m文件不存在,开始下载\e[0m"
  1665. wget $URL && echo -e "\e[1;35m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; }
  1666. fi
  1667. #解压新版本
  1668. echo -e "\n\e[1;35m解压源文件\e[0m"
  1669. tar zxf nginx-${version}.tar.gz
  1670. cd nginx-${version}
  1671. #编译新版本
  1672. ./configure --prefix=/apps/nginx \
  1673. --user=nginx \
  1674. --group=nginx \
  1675. --with-http_ssl_module \
  1676. --with-http_v2_module \
  1677. --with-http_realip_module \
  1678. --with-http_stub_status_module \
  1679. --with-http_gzip_static_module \
  1680. --with-pcre \
  1681. --with-stream \
  1682. --with-stream_ssl_module \
  1683. --with-stream_realip_module
  1684. #./configure --prefix=/srun3/nginx \
  1685. #--conf-path=/srun3/nginx/conf/nginx.conf \
  1686. #--sbin-path=/srun3/nginx/sbin/nginx \
  1687. #--pid-path=/srun3/nginx/run/nginx.pid \
  1688. #--error-log-path=/srun3/nginx/log/nginx-error.log \
  1689. #--http-log-path=/srun3/nginx/log/nginx-access.log \
  1690. #--user=nginx \
  1691. #--group=nginx \
  1692. #--with-http_ssl_module \
  1693. #--with-http_realip_module \
  1694. #--with-http_flv_module \
  1695. #--with-http_mp4_module \
  1696. #--with-http_gunzip_module \
  1697. #--with-http_gzip_static_module \
  1698. #--with-http_secure_link_module \
  1699. #--with-http_v2_module \
  1700. #--with-http_stub_status_module \
  1701. #--with-http_sub_module
  1702. #只要make无需要make install
  1703. make
  1704. #可以看到新编译的nginx版本
  1705. #objs/nginx -v
  1706. echo -e "\n\e[1;35m备份旧的nginx文件\e[0m"
  1707. #把之前的旧版的nginx命令备份
  1708. #cp /srun3/nginx/sbin/nginx /srun3/nginx/sbin/nginx.bak
  1709. cp /apps/nginx/sbin/nginx /apps/nginx/sbin/nginx.bak
  1710. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1711. echo -e "\n\e[1;35m复制新版本源文件\e[0m"
  1712. #新版本nginx复制到旧版本目录中
  1713. #cp -f ./objs/nginx /srun3/nginx/sbin/
  1714. cp -f ./objs/nginx /apps/nginx/sbin/
  1715. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1716. echo -e "\n\e[1;35m检测\e[0m"
  1717. #检测一下
  1718. #/srun3/nginx/sbin/nginx -t
  1719. /apps/nginx/sbin/nginx -t
  1720. echo -e "\n\e[1;35m平滑升级到新版本\e[0m"
  1721. #发送信号USR2 平滑升级可执行程序,将存储有旧版本主进程PID的文件重命名为nginx.pid.oldbin,并启动新的nginx
  1722. #此时两个master的进程都在运行,只是旧的master不在监听,由新的master监听80
  1723. #此时Nginx开启一个新的master进程,这个master进程会生成新的worker进程,这就是升级后的Nginx进程,此时老的进程不会自动退出,但是当接收到新的请求不作处理而是交给新的进程处理。
  1724. #先关闭旧nginx的worker进程,而不关闭nginx主进程方便回滚
  1725. #向原Nginx主进程发送WINCH信号,它会逐步关闭旗下的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理
  1726. #kill -USR2 `cat /run/nginx.pid`
  1727. #kill -WINCH `cat /run/nginx.pid.oldbin`
  1728. kill -USR2 `cat /apps/nginx/logs/nginx.pid`
  1729. kill -WINCH `cat /apps/nginx/logs/nginx.pid.oldbin`
  1730. #如果旧版worker进程有用户的请求,会一直等待处理完后才会关闭
  1731. #经过一段时间测试,新版本服务没问题,最后发送QUIT信号,退出老的master
  1732. #kill -QUIT `cat /run/nginx.pid.oldbin`
  1733. kill -QUIT `cat /apps/nginx/logs/nginx.pid.oldbin`
  1734. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  1735. #查看版本已经是新版了
  1736. echo -e "\n\e[1;35m升级后的版本\e[0m"
  1737. #/srun3/nginx/sbin/nginx -V
  1738. /apps/nginx/sbin/nginx -V
  1739. echo -e "\n\e[1;35m如果想回滚到旧版本,执行以下命令\e[0m"
  1740. echo -e "\n\e[1;35mkill -HUP `cat /run/nginx.pid.oldbin`\e[0m"
  1741. echo -e "\n\e[1;35mmv /apps/nginx/sbin/nginx.bak /apps/nginx/sbin/nginx\e[0m"
  1742. #回滚
  1743. #如果升级的版本发现问题需要回滚,可以发送HUP信号,重新拉起旧版本的worker
  1744. #kill -HUP `cat /run/nginx.pid.oldbin`
  1745. #恢复旧版的文件
  1746. #mv /srun3/nginx/sbin/nginx.bak /srun3/nginx/sbin/
  1747. #mv /apps/nginx/sbin/nginx.bak /apps/nginx/sbin/nginx
  1748. }
  1749. update_srunnginx(){
  1750. local version=1.22.1
  1751. local URL=http://nginx.org/download/nginx-${version}.tar.gz
  1752. echo -e "\n\e[1;35m更新的版本是nginx-${version},centos7安装的4k测试没出现问题\e[0m"
  1753. echo -e "\n\e[1;35m请提交准备好对应版本的压缩包放在root目录下,若没有请在五秒内终止脚本\e[0m\n"
  1754. for i in {5..1}
  1755. do
  1756. echo -n "${i} "
  1757. echo -ne "\r"
  1758. sleep 1
  1759. done
  1760. echo -e "\n\e[1;35m安装依赖包\e[0m\n"
  1761. #openssl库冲突问题
  1762. #yum downgrade openssl
  1763. #yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ autoconf automake make
  1764. software=(
  1765. "gcc"
  1766. "gcc-c++"
  1767. "glibc"
  1768. "make"
  1769. "pcre"
  1770. "pcre-devel"
  1771. "openssl"
  1772. "openssl-devel"
  1773. "autoconf"
  1774. "automake"
  1775. )
  1776. for i in ${software[@]}
  1777. do
  1778. 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" ; }
  1779. done
  1780. #查看当前nginx版本以及编译模块参数
  1781. echo -e "\n\e[1;31m已安装的版本\e[0m"
  1782. /srun3/nginx/sbin/nginx -V
  1783. sleep 2
  1784. if [ -e nginx-${version}.tar.gz ];then
  1785. echo -e "\n\e[1;35m文件已存在,开始安装\e[0m"
  1786. else
  1787. echo -e "\n\e[1;33m文件不存在,开始下载\e[0m"
  1788. wget $URL && echo -e "\e[1;35m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; }
  1789. fi
  1790. #解压新版本
  1791. echo -e "\n\e[1;35m解压源文件\e[0m"
  1792. tar zxf nginx-${version}.tar.gz
  1793. cd nginx-${version}
  1794. sleep 2
  1795. #编译新版本
  1796. echo -e "\n\e[1;35m开始编译\e[0m"
  1797. #新版本编译参数
  1798. ./configure --prefix=/srun3/nginx \
  1799. --conf-path=/srun3/nginx/conf/nginx.conf \
  1800. --sbin-path=/srun3/nginx/sbin/nginx \
  1801. --pid-path=/srun3/nginx/run/nginx.pid \
  1802. --error-log-path=/srun3/nginx/log/nginx-error.log \
  1803. --http-log-path=/srun3/nginx/log/nginx-access.log \
  1804. --user=nginx \
  1805. --group=nginx \
  1806. --with-http_ssl_module \
  1807. --with-http_realip_module \
  1808. --with-http_flv_module \
  1809. --with-http_mp4_module \
  1810. --with-http_gunzip_module \
  1811. --with-http_gzip_static_module \
  1812. --with-http_secure_link_module \
  1813. --with-http_v2_module \
  1814. --with-http_stub_status_module \
  1815. --with-http_sub_module
  1816. #老版本编译参数
  1817. #./configure --prefix=/srun3/nginx
  1818. #--with-http_ssl_module \
  1819. #--with-http_v2_module \
  1820. #--with-http_stub_status_module \
  1821. #--with-ipv6 \
  1822. #--with-pcre \
  1823. #--with-http_realip_module \
  1824. #--with-http_gunzip_module \
  1825. #--with-http_gzip_static_module \
  1826. #--with-file-aio \
  1827. #--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector \
  1828. #--param=ssp-buffer-size=4 -m64 -mtune=generic'
  1829. #只要make无需要make install
  1830. make
  1831. #可以看到新编译的nginx版本
  1832. #objs/nginx -v
  1833. echo -e "\n\e[1;35m备份旧的nginx文件\e[0m"
  1834. #把之前的旧版的nginx命令备份
  1835. cp /srun3/nginx/sbin/nginx /srun3/nginx/sbin/nginx.bak
  1836. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1837. echo -e "\n\e[1;35m复制新版本源文件\e[0m"
  1838. #新版本nginx复制到旧版本目录中
  1839. cp -f ./objs/nginx /srun3/nginx/sbin/
  1840. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1841. echo -e "\n\e[1;35m检测\e[0m"
  1842. #检测一下
  1843. /srun3/nginx/sbin/nginx -t
  1844. echo -e "\n\e[1;35m平滑升级到新版本\e[0m"
  1845. #centos7上装的0803后版本 pid路径
  1846. kill -USR2 `cat /run/nginx.pid`
  1847. kill -WINCH `cat /run/nginx.pid.oldbin`
  1848. kill -QUIT `cat /run/nginx.pid.oldbin`
  1849. #centos6上装的老版本srun pid路径
  1850. #kill -USR2 `cat /var/run/nginx.pid`
  1851. #kill -WINCH `cat /var/run/nginx.pid.oldbin`
  1852. #kill -QUIT `cat /var/run/nginx.pid.oldbin`
  1853. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  1854. #查看版本已经是新版了
  1855. echo -e "\n\e[1;35m升级后的版本\e[0m"
  1856. /srun3/nginx/sbin/nginx -V
  1857. }
  1858. update_srunnginx2(){
  1859. local version=1.22.1
  1860. local URL=http://nginx.org/download/nginx-${version}.tar.gz
  1861. echo -e "\n\e[1;35m更新的版本是nginx-${version},在centos6上测试的\e[0m"
  1862. echo -e "\n\e[1;35m如果不想安装此版本请在五秒内终止脚本\e[0m"
  1863. echo -e "\n\e[1;35m请提前准备好对应版本的压缩包放在root目录下,若没有请在五秒内终止脚本\e[0m\n"
  1864. for i in {5..1}
  1865. do
  1866. echo -n "${i} "
  1867. echo -ne "\r"
  1868. sleep 1
  1869. done
  1870. echo -e "\n\e[1;35m安装依赖包\e[0m\n"
  1871. #解决openssl库冲突问题
  1872. #true是外部命令效率低
  1873. #yum downgrade openssl -y || true
  1874. yum downgrade openssl -y || :
  1875. #yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ autoconf automake make
  1876. software=(
  1877. "gcc"
  1878. "gcc-c++"
  1879. "glibc"
  1880. "make"
  1881. "pcre"
  1882. "pcre-devel"
  1883. "openssl"
  1884. "openssl-devel"
  1885. "autoconf"
  1886. "automake"
  1887. )
  1888. for i in ${software[@]}
  1889. do
  1890. 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" ; }
  1891. done
  1892. #查看当前nginx版本以及编译模块参数
  1893. echo -e "\n\e[1;31m已安装的版本\e[0m"
  1894. /srun3/nginx/sbin/nginx -V
  1895. sleep 2
  1896. if [ -e nginx-${version}.tar.gz ];then
  1897. echo -e "\n\e[1;35m文件已存在,开始安装\e[0m"
  1898. else
  1899. echo -e "\n\e[1;33m文件不存在,开始下载\e[0m"
  1900. wget $URL && echo -e "\e[1;35m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; }
  1901. fi
  1902. #解压新版本
  1903. echo -e "\n\e[1;35m解压源文件\e[0m"
  1904. tar zxf nginx-${version}.tar.gz
  1905. cd nginx-${version}
  1906. sleep 2
  1907. #编译新版本
  1908. echo -e "\n\e[1;35m开始编译\e[0m"
  1909. #老版本编译参数,添加--with-http_v2_module --with-http_stub_status_module
  1910. ./configure --prefix=/srun3/nginx \
  1911. --with-http_ssl_module \
  1912. --with-http_v2_module \
  1913. --with-http_stub_status_module \
  1914. --with-ipv6 \
  1915. --with-pcre \
  1916. --with-http_realip_module \
  1917. --with-http_gunzip_module \
  1918. --with-http_gzip_static_module \
  1919. --with-file-aio \
  1920. --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
  1921. #只要make无需要make install
  1922. make
  1923. #可以看到新编译的nginx版本
  1924. #objs/nginx -v
  1925. echo -e "\n\e[1;35m备份旧的nginx文件\e[0m"
  1926. #把之前的旧版的nginx命令备份
  1927. cp /srun3/nginx/sbin/nginx /srun3/nginx/sbin/nginx.bak
  1928. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1929. echo -e "\n\e[1;35m复制新版本源文件\e[0m"
  1930. #新版本nginx复制到旧版本目录中
  1931. cp -f ./objs/nginx /srun3/nginx/sbin/
  1932. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || { echo -e "\e[1;31m false \e[0m";exit; }
  1933. echo -e "\n\e[1;35m检测\e[0m"
  1934. #检测一下
  1935. /srun3/nginx/sbin/nginx -t
  1936. echo -e "\n\e[1;35m平滑升级到新版本\e[0m"
  1937. #centos6上装的老版本srun pid路径
  1938. kill -USR2 `cat /var/run/nginx.pid`
  1939. sleep 1
  1940. kill -WINCH `cat /var/run/nginx.pid.oldbin`
  1941. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  1942. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  1943. #查看版本已经是新版了
  1944. echo -e "\n\e[1;35m升级后的版本\e[0m"
  1945. /srun3/nginx/sbin/nginx -V
  1946. }
  1947. update_openssl(){
  1948. local version=1.1.1k
  1949. local URL=https://www.openssl.org/source/old/1.1.1/openssl-1.1.1k.tar.gz
  1950. echo -e "\e[1;35m====================================================================\e[0m"
  1951. echo -e "\e[1;35m现在已安装的版本\e[0m"
  1952. openssl version
  1953. echo -e "\e[1;35m本次安装的版本是openssl-${version}\e[0m"
  1954. echo -e "\e[1;35m====================================================================\e[0m"
  1955. echo -e "\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  1956. for i in {5..1}
  1957. do
  1958. echo -n "${i} "
  1959. echo -ne "\r"
  1960. sleep 1
  1961. done
  1962. echo -e "\e[1;35m==========================源文件检查================================\e[0m"
  1963. if [ -e "openssl-${version}.tar.gz" ];then
  1964. echo -e "\e[1;35m文件存在\e[0m"
  1965. else
  1966. echo -e "\e[1;33m文件不存在,开始下载\e[0m"
  1967. wget --no-check-certificate https://www.openssl.org/source/openssl-${version}.tar.gz
  1968. fi
  1969. echo -e "\e[1;35m==========================安装依赖包================================\e[0m"
  1970. #yum install -y gcc gcc-c++ glibc make
  1971. software=(
  1972. "gcc"
  1973. "gcc-c++"
  1974. "glibc"
  1975. "make"
  1976. )
  1977. for i in ${software[@]}
  1978. do
  1979. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  1980. done
  1981. echo -e "\e[1;35m===========================解压,编译===============================\e[0m"
  1982. tar zxf /root/openssl-${version}.tar.gz
  1983. cd /root/openssl-${version}
  1984. ./config --prefix=/usr/local/openssl -d shared
  1985. make
  1986. #执行失败的话执行make clean清除make信息
  1987. #[ $? -eq 0 ] || make clean
  1988. sleep 1
  1989. make install
  1990. echo -e "\e[1;35m============================备份旧文件================================\e[0m"
  1991. #备份旧的
  1992. mv /usr/bin/openssl /usr/bin/openssl.bak
  1993. echo -e "\e[1;35m=========================对新的创建软连接==============================\e[0m"
  1994. #对新的创建软连接
  1995. ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
  1996. echo -e "\e[1;35m==============================验证====================================\e[0m"
  1997. #将 openssl 的 lib 库写进配置中,并使配置生效
  1998. #echo "/usr/local/openssl/lib64/" >> /etc/ld.so.conf
  1999. echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
  2000. #验证:ldconfig -v|grep ssl //确定链接库
  2001. ldconfig -v
  2002. [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2003. #出现报错libssl.so.1.1。。。缺少依赖库
  2004. #ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
  2005. #ln -s /usr/local/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
  2006. #echo "/usr/local/lib64" >> /etc/ld.so.conf
  2007. #ldconfig -v | grep ssl
  2008. #查看版本 是否安装成功
  2009. echo -e "\e[1;35m===============================升级后版本================================\e[0m"
  2010. openssl version
  2011. }
  2012. update_openssh(){
  2013. local ZLIBV=1.3
  2014. local OPENSSHV=9.4p1
  2015. echo -e "\e[1;35m========================================================================\e[0m"
  2016. echo -e "\e[1;35m已安装版本\e[0m"
  2017. ssh -V
  2018. echo -e "\n\e[1;35m本次升级的安装版本openssh-${OPENSSHV},zlib-${ZLIBV}\e[0m"
  2019. echo -e "\e[1;35m离线安装,请提前准备好对应版本的压缩包放在root目录下\e[0m"
  2020. echo -e "\e[1;35m=========================================================================\e[0m"
  2021. echo -e "\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  2022. for i in {5..1}
  2023. do
  2024. echo -n "${i} "
  2025. echo -ne "\r"
  2026. sleep 1
  2027. done
  2028. echo -e "\e[1;35m=============================安装依赖包===================================\e[0m"
  2029. #yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
  2030. #yum install -y pam* zlib*
  2031. software=("gcc"
  2032. "gcc-c++"
  2033. "glibc"
  2034. "make"
  2035. "autoconf"
  2036. "openssl"
  2037. "openssl-devel"
  2038. "pcre-devel"
  2039. "pam-devel"
  2040. "pam*"
  2041. )
  2042. for i in ${software[@]}
  2043. do
  2044. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  2045. done
  2046. echo -e "\e[1;35m=============================源文件检查===================================\e[0m"
  2047. if [[ -e "zlib-${ZLIBV}.tar.gz" ]];then
  2048. echo -e "\e[1;35mzlib源文件存在\e[0m"
  2049. else
  2050. echo -e "\e[1;33mzlib源文件不存在,尝试下载\e[0m"
  2051. wget --no-check-certificate https://nchc.dl.sourceforge.net/project/libpng/zlib/${ZLIBV}/zlib-${ZLIBV}.tar.gz
  2052. fi
  2053. if [[ -e "openssh-${OPENSSHV}.tar.gz" ]];then
  2054. echo -e "\e[1;35mopenssh源文件存在\e[0m"
  2055. else
  2056. echo -e "\e[1;33mopenssh源文件不存在,尝试下载\e[0m"
  2057. wget --no-check-certificate https://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-${OPENSSHV}.tar.gz
  2058. fi
  2059. echo -e "\e[1;35m=============================解压源文件===================================\e[0m"
  2060. tar zxf zlib-${ZLIBV}.tar.gz
  2061. if [ -e /root/zlib-${ZLIBV} ];then
  2062. echo -e "\n\e[1;35mzlib解压成功\e[0m"
  2063. else
  2064. echo -e "\n\e[1;35mzlib解压失败\e[0m"
  2065. exit
  2066. fi
  2067. tar zxf openssh-${OPENSSHV}.tar.gz
  2068. if [ -e /root/openssh-${OPENSSHV} ];then
  2069. echo -e "\e[1;35mopenssh解压成功\e[0m"
  2070. else
  2071. echo -e "\e[1;35mopenssh解压失败\e[0m"
  2072. exit
  2073. fi
  2074. echo -e "\e[1;35m=============================编译zlib===================================\e[0m"
  2075. #tar zxf /root/zlib-${ZLIBV}.tar.gz
  2076. if [ -e /usr/local/zlib ];then
  2077. echo -e "\n\e[1;35m已存在\e[0m"
  2078. else
  2079. echo -e "\n\e[1;35m开始编译\e[0m"
  2080. cd /root/zlib-${ZLIBV}/
  2081. ./configure --prefix=/usr/local/zlib
  2082. make && make install
  2083. [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2084. fi
  2085. echo -e "\e[1;35m=============================编译openssh===================================\e[0m"
  2086. #tar zxf /root/openssh-${OPENSSHV}.tar.gz
  2087. if [ -e /usr/local/openssh ];then
  2088. echo -e "\n\e[1;35m已存在\e[0m"
  2089. else
  2090. echo -e "\n\e[1;35m开始编译\e[0m"
  2091. cd /root/openssh-${OPENSSHV}/
  2092. ./configure --prefix=/usr/local/openssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-pam --without-openssl-header-check
  2093. make && make install
  2094. [ $? -eq 0 ] && echo -e "\e[1;35m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2095. fi
  2096. echo -e "\e[1;35m=======================备份旧文件,迁入新文件=============================\e[0m"
  2097. [ -d /data/opensshbak ] || mkdir -p /data/opensshbak/
  2098. mv /etc/ssh/sshd_config /data/opensshbak/sshd_config.bak
  2099. cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
  2100. mv /usr/sbin/sshd /data/opensshbak/sshd.bak
  2101. cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
  2102. mv /usr/bin/ssh /data/opensshbak/ssh.bak
  2103. cp /usr/local/openssh/bin/ssh /usr/bin/ssh
  2104. mv /usr/bin/ssh-keygen /data/opensshbak/ssh-keygen.bak
  2105. cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
  2106. mv /etc/ssh/ssh_host_ecdsa_key.pub /data/opensshbak/ssh_host_ecdsa_key.pub.bak
  2107. cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
  2108. for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done
  2109. mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
  2110. cp /root/openssh-${OPENSSHV}/contrib/redhat/sshd.init /etc/init.d/sshd
  2111. chmod u+x /etc/init.d/sshd
  2112. echo -e "\e[1;35m=========================修改sshd配置文件===============================\e[0m"
  2113. cp /etc/init.d/sshd /data/opensshbak/sshdnewbk
  2114. sed -i '/SSHD=/c\SSHD=\/usr\/local\/openssh\/sbin\/sshd' /etc/init.d/sshd
  2115. sed -i '/\/usr\/bin\/ssh-keygen/c\ \/usr\/local\/openssh\/bin\/ssh-keygen -A' /etc/init.d/sshd
  2116. sed -i '/ssh_host_rsa_key.pub/i\ \/sbin\/restorecon \/etc\/ssh\/ssh_host_key.pub' /etc/init.d/sshd
  2117. sed -i '/$SSHD $OPTIONS && success || failure/i\ \ OPTIONS="-f /etc/ssh/sshd_config"' /etc/rc.d/init.d/sshd
  2118. echo -e "\e[1;35m======================修改sshd_config配置文件============================\e[0m\n"
  2119. echo -e "\n\e[1;35m修改sshd_config配置文件\e[0m"
  2120. sed -i '/PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config
  2121. sed -i '/X11Forwarding/c\X11Forwarding yes' /etc/ssh/sshd_config
  2122. sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  2123. cp -arp /usr/local/openssh/bin/* /usr/bin/
  2124. service sshd restart
  2125. echo -e "\n\e[1;35m配置开机项\e[0m"
  2126. chkconfig --add sshd
  2127. chkconfig --level 2345 sshd on
  2128. chkconfig --list
  2129. echo -e "\e[1;35m============================更新后版本================================\e[0m"
  2130. ssh -V
  2131. }
  2132. update_sshssl(){
  2133. local ZLIBV=1.2.13
  2134. local OPENSSHV=9.1p1
  2135. local version=1.1.1k
  2136. echo -e "\e[1;35m========================================================================\e[0m"
  2137. echo -e "\e[1;35m现在已安装的版本\e[0m"
  2138. openssl version
  2139. ssh -V
  2140. echo -e "\n\e[1;35m本次安装的版本是openssl-${version}\e[0m"
  2141. echo -e "\e[1;35m本次升级的安装版本openssh-${OPENSSHV},zlib-${ZLIBV}\e[0m"
  2142. echo -e "\e[1;35m离线安装,请提前准备好对应版本的压缩包放在root目录下\e[0m"
  2143. echo -e "\e[1;35m========================================================================\e[0m"
  2144. echo -e "\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  2145. for i in {5..1}
  2146. do
  2147. echo -n "${i} "
  2148. echo -ne "\r"
  2149. sleep 1
  2150. done
  2151. echo -e "\e[1;35m==========================源文件检查=====================================\e[0m"
  2152. if [ -e "openssl-${version}.tar.gz" ];then
  2153. echo -e "\e[1;35mopenssl文件存在\e[0m"
  2154. else
  2155. echo -e "\e[1;33mopenssl文件不存在\e[0m"
  2156. exit
  2157. fi
  2158. if [[ -a "zlib-${ZLIBV}.tar.gz" ]];then
  2159. echo -e "\e[1;35mzlib源文件存在\e[0m"
  2160. else
  2161. echo -e "\e[1;33mzlib源文件不存在\e[0m"
  2162. exit
  2163. fi
  2164. if [[ -a "openssh-${OPENSSHV}.tar.gz" ]];then
  2165. echo -e "\e[1;35mopenssh源文件存在\e[0m"
  2166. else
  2167. echo -e "\e[1;33mopenssh源文件不存在\e[0m"
  2168. exit
  2169. fi
  2170. echo -e "\e[1;35m==========================安装依赖包=====================================\e[0m"
  2171. software=("gcc"
  2172. "gcc-c++"
  2173. "glibc"
  2174. "make"
  2175. "autoconf"
  2176. "openssl"
  2177. "openssl-devel"
  2178. "pcre-devel"
  2179. "pam-devel"
  2180. "pam*"
  2181. )
  2182. for i in ${software[@]}
  2183. do
  2184. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  2185. done
  2186. echo -e "\e[1;35m===========================解压源文件====================================\e[0m"
  2187. tar zxf /root/zlib-${ZLIBV}.tar.gz
  2188. if [ -e /root/zlib-${ZLIBV} ];then
  2189. echo -e "\n\e[1;35mzlib解压成功\e[0m"
  2190. else
  2191. echo -e "\n\e[1;35mzlib解压失败\e[0m"
  2192. exit
  2193. fi
  2194. tar zxf /root/openssh-${OPENSSHV}.tar.gz
  2195. if [ -e /root/openssh-${OPENSSHV} ];then
  2196. echo -e "\e[1;35mopenssh解压成功\e[0m"
  2197. else
  2198. echo -e "\e[1;35mopenssh解压失败\e[0m"
  2199. exit
  2200. fi
  2201. tar zxf /root/openssl-${version}.tar.gz
  2202. if [ -e openssl-${version} ];then
  2203. echo -e "\e[1;35mopenssl解压成功\e[0m\n"
  2204. else
  2205. echo -e "\e[1;35mopenssl解压失败\e[0m"
  2206. exit
  2207. fi
  2208. echo -e "\e[1;35m===========================编译openssl==================================\e[0m"
  2209. cd /root/openssl-${version}
  2210. ./config --prefix=/usr/local/openssl -d shared
  2211. make
  2212. #执行失败的话执行make clean清除make信息
  2213. #[ $? -eq 0 ] || make clean
  2214. sleep 1
  2215. make install
  2216. echo -e "\e[1;35m============================备份旧文件===================================\e[0m"
  2217. #备份旧的
  2218. mv /usr/bin/openssl /usr/bin/openssl.bak
  2219. echo -e "\e[1;35m=========================对新的创建软连接================================\e[0m"
  2220. #对新的创建软连接
  2221. ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
  2222. echo -e "\e[1;35m==============================验证======================================\e[0m"
  2223. #将 openssl 的 lib 库写进配置中,并使配置生效
  2224. #echo "/usr/local/openssl/lib64/" >> /etc/ld.so.conf
  2225. echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
  2226. #验证:ldconfig -v|grep ssl //确定链接库
  2227. ldconfig -v
  2228. [ $? -eq 0 ] && echo -e "\e[1;35m [ OK ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  2229. #出现报错libssl.so.1.1。。。缺少依赖库
  2230. #ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
  2231. #ln -s /usr/local/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
  2232. #echo "/usr/local/lib64" >> /etc/ld.so.conf
  2233. #ldconfig -v | grep ssl
  2234. #查看版本 是否安装成功
  2235. echo -e "\e[1;35m========================升级后openssl版本================================\e[0m"
  2236. openssl version
  2237. sleep 3
  2238. echo -e "\e[1;35m=============================编译zlib===================================\e[0m"
  2239. #tar zxf /root/zlib-${ZLIBV}.tar.gz
  2240. if [ -e /usr/local/zlib ];then
  2241. echo -e "\n\e[1;35m已存在\e[0m"
  2242. else
  2243. echo -e "\n\e[1;35m开始编译\e[0m"
  2244. cd /root/zlib-${ZLIBV}/
  2245. ./configure --prefix=/usr/local/zlib
  2246. make && make install
  2247. [ $? -eq 0 ] && echo -e "\e[1;35m [ OK ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  2248. fi
  2249. echo -e "\e[1;35m===========================编译openssh==================================\e[0m"
  2250. #tar zxf /root/openssh-${OPENSSHV}.tar.gz
  2251. if [ -e /usr/local/openssh ];then
  2252. echo -e "\n\e[1;35m已存在\e[0m"
  2253. else
  2254. echo -e "\n\e[1;35m开始编译\e[0m"
  2255. cd /root/openssh-${OPENSSHV}/
  2256. ./configure --prefix=/usr/local/openssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-pam --without-openssl-header-check
  2257. make && make install
  2258. [ $? -eq 0 ] && echo -e "\e[1;35m [ OK ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  2259. fi
  2260. echo -e "\e[1;35m======================备份旧文件,迁入新文件==============================\e[0m"
  2261. [ -d /data/opensshbak ] || mkdir -p /data/opensshbak/
  2262. mv /etc/ssh/sshd_config /data/opensshbak/sshd_config.bak
  2263. cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
  2264. mv /usr/sbin/sshd /data/opensshbak/sshd.bak
  2265. cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
  2266. mv /usr/bin/ssh /data/opensshbak/ssh.bak
  2267. cp /usr/local/openssh/bin/ssh /usr/bin/ssh
  2268. mv /usr/bin/ssh-keygen /data/opensshbak/ssh-keygen.bak
  2269. cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
  2270. mv /etc/ssh/ssh_host_ecdsa_key.pub /data/opensshbak/ssh_host_ecdsa_key.pub.bak
  2271. cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
  2272. for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done
  2273. mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
  2274. cp /root/openssh-${OPENSSHV}/contrib/redhat/sshd.init /etc/init.d/sshd
  2275. chmod u+x /etc/init.d/sshd
  2276. echo -e "\e[1;35m==========================修改sshd配置文件================================\e[0m"
  2277. cp /etc/init.d/sshd /data/opensshbak/sshdnewbk
  2278. sed -i '/SSHD=/c\SSHD=\/usr\/local\/openssh\/sbin\/sshd' /etc/init.d/sshd
  2279. sed -i '/\/usr\/bin\/ssh-keygen/c\ \/usr\/local\/openssh\/bin\/ssh-keygen -A' /etc/init.d/sshd
  2280. sed -i '/ssh_host_rsa_key.pub/i\ \/sbin\/restorecon \/etc\/ssh\/ssh_host_key.pub' /etc/init.d/sshd
  2281. sed -i '/$SSHD $OPTIONS && success || failure/i\ \ OPTIONS="-f /etc/ssh/sshd_config"' /etc/rc.d/init.d/sshd
  2282. echo -e "\e[1;35m=======================修改sshd_config配置文件=============================\e[0m\n"
  2283. echo -e "\n\e[1;35m修改sshd_config配置文件\e[0m"
  2284. sed -i '/PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config
  2285. sed -i '/X11Forwarding/c\X11Forwarding yes' /etc/ssh/sshd_config
  2286. sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  2287. cp -arp /usr/local/openssh/bin/* /usr/bin/
  2288. service sshd restart
  2289. [ $? -eq 0 ] && echo -e "\e[1;35m [ OK ] \e[0m" || echo -e "\e[1;31m false \e[0m"
  2290. echo -e "\n\e[1;35m配置开机项\e[0m"
  2291. chkconfig --add sshd
  2292. chkconfig --level 2345 sshd on
  2293. chkconfig --list
  2294. echo -e "\e[1;35m=========================更新后openssh版本=================================\e[0m"
  2295. ssh -V
  2296. }
  2297. install_openssh1(){
  2298. echo -e "\e[1;34m作废\e[0m"
  2299. exit
  2300. if [ ! -d /home/data ];then
  2301. mkdir /home/data
  2302. fi
  2303. cd /home/data
  2304. yum install wget -y
  2305. #wget -O openssh-8.6p1.tar.gz https://ftp.riken.jp/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
  2306. #wget -O zlib-1.2.11.tar.gz https://zlib.net/zlib-1.2.11.tar.gz
  2307. #wget -O openssl-1.1.1j.tar.gz https://www.openssl.org/source/openssl-1.1.1j.tar.gz
  2308. ######保证下载的文件在/home/data里,且文件名相同
  2309. tar -zxf openssl-1.1.1q.tar.gz
  2310. tar -zxf zlib-1.2.13.tar.gz
  2311. tar -zxf openssh-9.1p1.tar.gz
  2312. chown -R root:root /home/data
  2313. #######################0end----------############################
  2314. ##1---配置Telnet,以防SSH配置过程中出现问题,可以使用Telnet登录----
  2315. setenforce 0
  2316. #关闭selinux
  2317. systemctl stop firewalld
  2318. #关闭
  2319. systemctl disable firewalld
  2320. #yum install telnet telnet-server xinetd -y
  2321. ##vi /etc/xinetd.conf
  2322. ##修改disabled = no ,即可以使用telnet服务
  2323. #cp /etc/xinetd.conf /home/data/xinetd.comfbk
  2324. #sed -i '14a disabled = no ' /etc/xinetd.conf
  2325. ##在第14行增加 disabled = no
  2326. #echo -e 'pts/0\npts/1\npts/2\npts/3' >>/etc/securetty
  2327. #systemctl start telnet.socket #开启服务
  2328. #systemctl start xinetd #开启服务
  2329. #systemctl enable telnet.socket #开机自起服务
  2330. #systemctl enable xinetd
  2331. ##1end---------------------------------------------------------------
  2332. ##2 升级 OpenZlib-----------------------------------------
  2333. yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
  2334. yum install -y pam* zlib*
  2335. cd /home/data/zlib-1.2.13/
  2336. ./configure --prefix=/usr/local/zlib
  2337. make && make install
  2338. ##2end---------------------
  2339. ##3升级openssl-------------
  2340. cd /home/data/openssl-1.1.1q//
  2341. ./config --prefix=/usr/local/openssl -d shared
  2342. make && make install
  2343. echo '/usr/local/openssl/lib' >> /etc/ld.so.conf
  2344. ldconfig
  2345. mv /usr/bin/openssl /home/data/opensslbk
  2346. ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
  2347. ##3end--and start update SSH------------------------
  2348. ##4-----安装OpenSSH 8.6p1-------
  2349. cd /home/data/openssh-9.1p1/
  2350. ./configure --prefix=/usr/local/openssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-pam --without-openssl-header-check
  2351. make && make install
  2352. mv /etc/ssh/sshd_config /home/data/sshd_config.bak
  2353. cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
  2354. mv /usr/sbin/sshd /home/data/sshd.bak
  2355. cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
  2356. mv /usr/bin/ssh /home/data/ssh.bak
  2357. cp /usr/local/openssh/bin/ssh /usr/bin/ssh
  2358. mv /usr/bin/ssh-keygen /home/data/ssh-keygen.bak
  2359. cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
  2360. mv /etc/ssh/ssh_host_ecdsa_key.pub /home/data/ssh_host_ecdsa_key.pub.bak
  2361. cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
  2362. for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done
  2363. #mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config
  2364. mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config
  2365. cp /home/data/openssh-9.1p1/contrib/redhat/sshd.init /etc/init.d/sshd
  2366. chmod u+x /etc/init.d/sshd
  2367. #-------------修改配置文件------------
  2368. cp /etc/init.d/sshd /home/data/sshdnewbk
  2369. sed -i '/SSHD=/c\SSHD=\/usr\/local\/openssh\/sbin\/sshd' /etc/init.d/sshd
  2370. sed -i '/\/usr\/bin\/ssh-keygen/c\ \/usr\/local\/openssh\/bin\/ssh-keygen -A' /etc/init.d/sshd
  2371. sed -i '/ssh_host_rsa_key.pub/i\ \/sbin\/restorecon \/etc\/ssh\/ssh_host_key.pub' /etc/init.d/sshd
  2372. sed -i '/$SSHD $OPTIONS && success || failure/i\ \ OPTIONS="-f /etc/ssh/sshd_config"' /etc/rc.d/init.d/sshd
  2373. #---------操作sshd_config-------
  2374. sed -i '/PasswordAuthentication/c\PasswordAuthentication yes' /etc/ssh/sshd_config
  2375. sed -i '/X11Forwarding/c\X11Forwarding yes' /etc/ssh/sshd_config
  2376. sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
  2377. cp -arp /usr/local/openssh/bin/* /usr/bin/
  2378. service sshd restart
  2379. ##3end------------------------------------------
  2380. #----------配置开机项---------------
  2381. chkconfig --add sshd
  2382. chkconfig --level 2345 sshd on
  2383. chkconfig --list
  2384. #----------关闭Telnet服务---------------
  2385. #systemctl stop telnet.socket
  2386. #systemctl stop xinetd
  2387. #systemctl disable xinetd.service
  2388. #systemctl disable telnet.socket
  2389. #--------清理安装过程文件---------------------
  2390. #rm -fr /home/data
  2391. }
  2392. c7_yum_docker(){
  2393. local VERSION=20.10.23-3.el7
  2394. echo -e "\n\e[1;35m此方法更换了所有源\e[0m"
  2395. echo -e "\n\e[1;35m本次安装版本为20.10.23-3.el7\e[0m"
  2396. echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  2397. for i in {5..1}
  2398. do
  2399. echo -n "${i} "
  2400. echo -ne "\r"
  2401. sleep 1
  2402. done
  2403. echo -e "\n\e[1;35m使用阿里云的yum源安装docker-ce\e[0m"
  2404. local DIR1=$(date +%F)
  2405. mkdir -p /data/yumbak-$DIR1
  2406. echo -e "\n\e[1;35m备份原有的yum源,备份文件在/data/下\e[0m"
  2407. mv /etc/yum.repos.d/* /data/yumbak-$DIR1
  2408. echo -e "\n\e[1;35m开启linux内核流量转发\e[0m"
  2409. #开启linux内核流量转发
  2410. cat > /etc/sysctl.d/docker.conf <<EOF
  2411. net.bridge.bridge-nf-call-ip6tables = 1
  2412. net.bridge.bridge-nf-call-iptables = 1
  2413. net.ipv4.conf.default.rp_filter = 0
  2414. net.ipv4.conf.all.rp_filter = 0
  2415. net.ipv4.ip_forward = 1
  2416. EOF
  2417. modprobe br_netfilter
  2418. sysctl -p /etc/sysctl.d/docker.conf
  2419. cat > /etc/yum.repos.d/CentOS-Base.repo <<EOF
  2420. # CentOS-Base.repo
  2421. #
  2422. # The mirror system uses the connecting IP address of the client and the
  2423. # update status of each mirror to pick mirrors that are updated to and
  2424. # geographically close to the client. You should use this for CentOS updates
  2425. # unless you are manually picking other mirrors.
  2426. #
  2427. # If the mirrorlist= does not work for you, as a fall back you can try the
  2428. # remarked out baseurl= line instead.
  2429. #
  2430. #
  2431. [base]
  2432. name=CentOS-\$releasever - Base - mirrors.aliyun.com
  2433. failovermethod=priority
  2434. baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
  2435. http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
  2436. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
  2437. gpgcheck=1
  2438. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  2439. #released updates
  2440. [updates]
  2441. name=CentOS-\$releasever - Updates - mirrors.aliyun.com
  2442. failovermethod=priority
  2443. baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
  2444. http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/
  2445. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/
  2446. gpgcheck=1
  2447. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  2448. #additional packages that may be useful
  2449. [extras]
  2450. name=CentOS-\$releasever - Extras - mirrors.aliyun.com
  2451. failovermethod=priority
  2452. baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
  2453. http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/
  2454. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/
  2455. gpgcheck=1
  2456. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  2457. #additional packages that extend functionality of existing packages
  2458. [centosplus]
  2459. name=CentOS-\$releasever - Plus - mirrors.aliyun.com
  2460. failovermethod=priority
  2461. baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
  2462. http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
  2463. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
  2464. gpgcheck=1
  2465. enabled=0
  2466. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  2467. #contrib - packages by Centos Users
  2468. [contrib]
  2469. name=CentOS-\$releasever - Contrib - mirrors.aliyun.com
  2470. failovermethod=priority
  2471. baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/
  2472. http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
  2473. http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
  2474. gpgcheck=1
  2475. enabled=0
  2476. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  2477. EOF
  2478. cat > /etc/yum.repos.d/docker-ce.repo <<EOF
  2479. [docker-ce-stable]
  2480. name=Docker CE Stable - \$basearch
  2481. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/stable
  2482. enabled=1
  2483. gpgcheck=1
  2484. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2485. [docker-ce-stable-debuginfo]
  2486. name=Docker CE Stable - Debuginfo \$basearch
  2487. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/stable
  2488. enabled=0
  2489. gpgcheck=1
  2490. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2491. [docker-ce-stable-source]
  2492. name=Docker CE Stable - Sources
  2493. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/stable
  2494. enabled=0
  2495. gpgcheck=1
  2496. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2497. [docker-ce-test]
  2498. name=Docker CE Test - \$basearch
  2499. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/test
  2500. enabled=0
  2501. gpgcheck=1
  2502. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2503. [docker-ce-test-debuginfo]
  2504. name=Docker CE Test - Debuginfo \$basearch
  2505. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/test
  2506. enabled=0
  2507. gpgcheck=1
  2508. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2509. [docker-ce-test-source]
  2510. name=Docker CE Test - Sources
  2511. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/test
  2512. enabled=0
  2513. gpgcheck=1
  2514. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2515. [docker-ce-nightly]
  2516. name=Docker CE Nightly - \$basearch
  2517. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/nightly
  2518. enabled=0
  2519. gpgcheck=1
  2520. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2521. [docker-ce-nightly-debuginfo]
  2522. name=Docker CE Nightly - Debuginfo \$basearch
  2523. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/debug-\$basearch/nightly
  2524. enabled=0
  2525. gpgcheck=1
  2526. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2527. [docker-ce-nightly-source]
  2528. name=Docker CE Nightly - Sources
  2529. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/source/nightly
  2530. enabled=0
  2531. gpgcheck=1
  2532. gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  2533. EOF
  2534. cat >/etc/yum.repos.d/epel.repo <<EOF
  2535. [epel]
  2536. name=Extra Packages for Enterprise Linux 7 - \$basearch
  2537. baseurl=http://mirrors.aliyun.com/epel/7/\$basearch
  2538. failovermethod=priority
  2539. enabled=1
  2540. gpgcheck=0
  2541. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  2542. [epel-debuginfo]
  2543. name=Extra Packages for Enterprise Linux 7 - \$basearch - Debug
  2544. baseurl=http://mirrors.aliyun.com/epel/7/\$basearch/debug
  2545. failovermethod=priority
  2546. enabled=0
  2547. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  2548. gpgcheck=0
  2549. [epel-source]
  2550. name=Extra Packages for Enterprise Linux 7 - \$basearch - Source
  2551. baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
  2552. failovermethod=priority
  2553. enabled=0
  2554. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  2555. EOF
  2556. yum clean all
  2557. yum -y install docker-ce-${VERSION} docker-ce-cli-$VERSION
  2558. [ $? -eq 0 ] && echo -e "\e[1;35m安装完成 \e[0m" || echo -e "\e[1;31m安装失败 \e[0m"
  2559. #使用阿里做镜像加速
  2560. echo -e "\n\e[1;35m阿里镜像加速\e[0m"
  2561. [ -d /etc/docker ] || mkdir -p /etc/docker
  2562. cat > /etc/docker/daemon.json <<EOF
  2563. {
  2564. "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
  2565. }
  2566. EOF
  2567. systemctl enable --now docker
  2568. [ $? -eq 0 ] && echo -e "\e[1;35m启动成功\e[0m" || echo -e "\e[1;31m启动失败 \e[0m"
  2569. echo -e "\n\e[1;35m安装的docker版本\e[0m"
  2570. docker version
  2571. }
  2572. c7_yum2_docker(){
  2573. DOCKER_VERSION="-20.10.9-3.el7"
  2574. echo -e "\n\e[1;35m此方法只添加了docker.repo,不想使用此方法请在五秒内终止脚本\e[0m"
  2575. echo -e "\n\e[1;35m安装完没有server端不知道原因\e[0m"
  2576. echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  2577. for i in {5..1}
  2578. do
  2579. echo -n "${i} "
  2580. echo -ne "\r"
  2581. sleep 1
  2582. done
  2583. cat >/etc/yum.repos.d/docker.repo <<EOF
  2584. [docker]
  2585. name=docker
  2586. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7.9/x86_64/stable/
  2587. gpgcheck=0
  2588. EOF
  2589. yum clean all
  2590. yum repolist
  2591. #yum list docker-ce* --showduplicates | sort -r
  2592. yum -y install docker-ce${DOCKER_VERSION} docker-ce-cli${DOCKER_VERSION}
  2593. #使用阿里做镜像加速
  2594. echo -e "\n\e[1;35m配置阿里镜像加速\e[0m"
  2595. [ -d /etc/docker ] || mkdir -p /etc/docker
  2596. cat > /etc/docker/daemon.json <<EOF
  2597. {
  2598. "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"]
  2599. }
  2600. EOF
  2601. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2602. systemctl daemon-reload
  2603. systemctl enable --now docker
  2604. echo -e "\n\e[1;35m查看安装版本信息\e[0m"
  2605. docker version
  2606. systemctl restart docker
  2607. echo -e "\n\e[1;35m验证镜像拉取是否正常\e[0m"
  2608. docker run hello-world &>/dev/null
  2609. docker images
  2610. }
  2611. c8_yum_docker(){
  2612. local DOCKER_VERSION="-20.10.23-3.el8"
  2613. echo -e "\n\e[1;35m本次安装的版本是docker-ce${DOCKER_VERSION}\e[0m"
  2614. echo -e "\n\e[1;35m此方法只添加了docker.repo\e[0m"
  2615. echo -e "\n\e[1;35m不想安装请在五秒内终止脚本\e[0m\n"
  2616. for i in {5..1}
  2617. do
  2618. echo -n "${i} "
  2619. echo -ne "\r"
  2620. sleep 1
  2621. done
  2622. cat >/etc/yum.repos.d/docker.repo <<EOF
  2623. [docker]
  2624. name=docker
  2625. baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/
  2626. https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/8/x86_64/stable/
  2627. gpgcheck=0
  2628. EOF
  2629. yum clean all
  2630. yum repolist
  2631. #yum list docker-ce* --showduplicates | sort -r
  2632. yum -y install docker-ce${DOCKER_VERSION} docker-ce-cli${DOCKER_VERSION}
  2633. #使用阿里做镜像加速
  2634. echo -e "\n\e[1;35m配置阿里镜像加速\e[0m"
  2635. [ -d /etc/docker ] || mkdir -p /etc/docker
  2636. cat > /etc/docker/daemon.json <<EOF
  2637. {
  2638. "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"]
  2639. }
  2640. EOF
  2641. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2642. systemctl daemon-reload
  2643. systemctl enable --now docker
  2644. echo -e "\n\e[1;35m查看安装版本信息\e[0m"
  2645. docker version
  2646. systemctl restart docker
  2647. echo -e "\n\e[1;35m验证镜像拉取是否正常\e[0m"
  2648. docker run hello-world &>/dev/null
  2649. docker images
  2650. }
  2651. offline_install_docker(){
  2652. local DOCKER_VERSION=20.10.9
  2653. local URL=https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-20.10.9.tgz
  2654. echo -e "\n\e[1;35m现在安装的版本是docker-${DOCKER_VERSION},若不想安装此版本请在五秒内终止脚本运行\e[0m"
  2655. echo -e "\e[1;35mcentos7,rocky8上测试正常\e[0m\n"
  2656. for i in {5..1}
  2657. do
  2658. echo -n "${i} "
  2659. echo -ne "\r"
  2660. sleep 1
  2661. done
  2662. if [ -e docker-${DOCKER_VERSION}.tgz ];then
  2663. echo -e "\n\e[1;32m文件已存在,开始安装\e[0m"
  2664. else
  2665. echo -e "\n\e[1;33m文件不存在,开始下载\e[0m"
  2666. wget $URL && echo -e "\e[1;32m下载成功\e[0m" || { echo -e "\e[1;31m下载失败,请检查下载链接是否失效\e[0m" ;exit; }
  2667. fi
  2668. echo -e "\n\e[1;35m解压源文件,拷贝docker文件到bin下\e[0m"
  2669. tar xvf docker-${DOCKER_VERSION}.tgz -C /usr/local/
  2670. cp /usr/local/docker/* /usr/bin/
  2671. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2672. echo -e "\n\e[1;35m写入service文件\e[0m"
  2673. cat > /lib/systemd/system/docker.service <<EOF
  2674. [Unit]
  2675. Description=Docker Application Container Engine
  2676. Documentation=https://docs.docker.com
  2677. After=network-online.target firewalld.service
  2678. Wants=network-online.target
  2679. [Service]
  2680. Type=notify
  2681. # the default is not to use systemd for cgroups because the delegate issues still
  2682. # exists and systemd currently does not support the cgroup feature set required
  2683. # for containers run by docker
  2684. ExecStart=/usr/bin/dockerd -H unix://var/run/docker.sock
  2685. ExecReload=/bin/kill -s HUP \$MAINPID
  2686. # Having non-zero Limit*s causes performance problems due to accounting overhead
  2687. # in the kernel. We recommend using cgroups to do container-local accounting.
  2688. LimitNOFILE=infinity
  2689. LimitNPROC=infinity
  2690. LimitCORE=infinity
  2691. # Uncomment TasksMax if your systemd version supports it.
  2692. # Only systemd 226 and above support this version.
  2693. #TasksMax=infinity
  2694. TimeoutStartSec=0
  2695. # set delegate yes so that systemd does not reset the cgroups of docker containers
  2696. Delegate=yes
  2697. # kill only the docker process, not all processes in the cgroup
  2698. KillMode=process
  2699. # restart the docker process if it exits prematurely
  2700. Restart=on-failure
  2701. StartLimitBurst=3
  2702. StartLimitInterval=60s
  2703. [Install]
  2704. WantedBy=multi-user.target
  2705. EOF
  2706. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2707. echo -e "\n\e[1;35m启动\e[0m"
  2708. systemctl daemon-reload
  2709. systemctl enable --now docker &>/dev/null
  2710. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2711. #使用阿里做镜像加速
  2712. echo -e "\n\e[1;35m配置阿里镜像加速\e[0m"
  2713. [ -d /etc/docker ] || mkdir -p /etc/docker
  2714. cat > /etc/docker/daemon.json <<EOF
  2715. {
  2716. "registry-mirrors": ["https://252ml0bu.mirror.aliyuncs.com"]
  2717. }
  2718. EOF
  2719. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  2720. systemctl daemon-reload
  2721. systemctl restart docker
  2722. echo -e "\n\e[1;35m查看安装版本信息\e[0m"
  2723. docker version
  2724. echo -e "\n\e[1;35m拉取hello-world,验证镜像拉取是否正常\e[0m"
  2725. docker run hello-world &>/dev/null
  2726. docker images
  2727. }
  2728. redhat_install_clickhouse(){
  2729. sudo yum install -y yum-utils
  2730. sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
  2731. sudo yum install -y clickhouse-server clickhouse-client
  2732. sudo /etc/init.d/clickhouse-server start
  2733. clickhouse-client
  2734. # or "clickhouse-client --password" if you set up a password.
  2735. }
  2736. debian_install_clickhouse(){
  2737. #安装环境配置和安装软件更新
  2738. sudo apt-get install -y apt-transport-https ca-certificates dirmngr
  2739. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
  2740. echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
  2741. /etc/apt/sources.list.d/clickhouse.list
  2742. sudo apt-get update
  2743. #安装clickhouse
  2744. sudo apt-get install -y clickhouse-server clickhouse-client
  2745. #启动clickhouse服务
  2746. sudo service clickhouse-server start
  2747. #启动客户端
  2748. clickhouse-client
  2749. # or "clickhouse-client --password" if you've set up a password.
  2750. exit
  2751. }
  2752. tgz_install_clickhouse(){
  2753. #获取最后一个版本号
  2754. LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
  2755. grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
  2756. export LATEST_VERSION
  2757. case $(uname -m) in
  2758. x86_64) ARCH=amd64 ;;
  2759. aarch64) ARCH=arm64 ;;
  2760. *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
  2761. esac
  2762. #下载对应版本号的tgz安装包
  2763. for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
  2764. do
  2765. curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
  2766. || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
  2767. done
  2768. #解压压缩包并执行对应的脚本
  2769. tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  2770. || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
  2771. #生成ClickHouse编译的二进制文件
  2772. sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"
  2773. tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  2774. || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
  2775. #生成带有调试信息的ClickHouse二进制文件
  2776. sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
  2777. tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  2778. || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
  2779. #创建clickhouse-server软连接,并安装默认配置服务
  2780. sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
  2781. #启动服务
  2782. sudo /etc/init.d/clickhouse-server start
  2783. tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  2784. || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
  2785. #创建clickhouse-client客户端工具软连接,并安装客户端配置文件
  2786. sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
  2787. }
  2788. compile_install_clickhouse(){
  2789. #gcc 10安装
  2790. # base centos 7
  2791. yum update
  2792. yum install -y gcc gcc-c++
  2793. yum install -y bzip2
  2794. wget -P /home https://mirrors.aliyun.com/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz
  2795. cd /home && tar -xzvf /home/gcc-10.2.0.tar.gz
  2796. cd /home/gcc-10.2.0 && ./contrib/download_prerequisites
  2797. #这一步看网速,需要挺久的
  2798. mkdir /usr/lib/gcc/x86_64-redhat-linux/10.2.0
  2799. mkdir /home/gcc-build-10.2.0
  2800. cd /home/gcc-build-10.2.0
  2801. ../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
  2802. make && make install
  2803. mv /usr/bin/gcc /usr/bin/gcc-4.8.5
  2804. mv /usr/bin/g++ /usr/bin/g++-4.8.5
  2805. alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 88 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8.5
  2806. 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++
  2807. alternatives --config gcc
  2808. #输入2回车
  2809. # 安装re2c
  2810. yum -y install git automake libtool
  2811. git clone https://github.com.cnpmjs.org/skvadrik/re2c.git re2c
  2812. cd re2c
  2813. mkdir -p m4
  2814. ./autogen.sh && ./configure --prefix=/usr && make
  2815. make install
  2816. # 安装ninja
  2817. ## 编译安装cmake3.15以上,此教程举例安装3.21
  2818. yum install -y openssl-devel
  2819. wget https://cmake.org/files/v3.21/cmake-3.21.0-rc1.tar.gz
  2820. tar -zxvf cmake-3.21.0-rc1.tar.gz
  2821. cd cmake-3.21.0-rc1/
  2822. ./bootstrap
  2823. gmake
  2824. gamke install
  2825. ## 安装ninja
  2826. git clone https://github.com/ninja-build/ninja.git ninja
  2827. cd ninja
  2828. cmake -Bbuild-cmake -H.
  2829. cmake --build build-cmake
  2830. cp ninja /usr/bin/
  2831. ninja --version
  2832. #安装python3
  2833. yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
  2834. yum -y install python-pip
  2835. yum install libffi-devel -y
  2836. mv /usr/bin/python /usr/bin/python.bak
  2837. wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
  2838. tar -zxvf Python-3.7.9.tgz
  2839. ./configure prefix=/usr/local/python3
  2840. make && make install
  2841. ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
  2842. #修改yum配置
  2843. vi /usr/bin/yum
  2844. #! /usr/bin/python修改为#! /usr/bin/python2
  2845. #
  2846. vi /usr/libexec/urlgrabber-ext-down
  2847. #把#! /usr/bin/python修改为#! /usr/bin/python2
  2848. #安装clickhouse
  2849. # 替换github的源(因为墙的原因)
  2850. git config --global url."https://hub.fastgit.org".insteadOf https://github.com
  2851. git clone https://github.com/ClickHouse/ClickHouse
  2852. cd ClickHouse
  2853. # 切换到指定版本
  2854. git tag -l
  2855. git checkout -b v21.7.5.29-stable
  2856. git submodule sync
  2857. git submodule update --init --recursive #等吧
  2858. mkdir build
  2859. cd build
  2860. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/clickhouse ../
  2861. ninja clickhouse #也是需要等很久,最好用screen
  2862. }
  2863. compile_install_redis(){
  2864. local VERSION=6.2.4
  2865. local URL=http://download.redis.io/releases/redis-6.2.4.tar.gz
  2866. local INSTALL_DIR=/apps/redis
  2867. local PASSWORD=123456
  2868. echo -e "\n\e[1;35m 安装的版本是redis-${VERSION},如果不想安装此版本请在5秒内停止运行脚本 \e[0m"
  2869. echo -e "\e[1;35m redis密码是123456 \e[0m"
  2870. echo -e "\e[1;35m 安装目录是${INSTALL_DIR} \e[0m"
  2871. echo -e "\e[1;35m 官网下载很慢建议提前下载好放在root目录下 \e[0m\n"
  2872. for i in {5..1}
  2873. do
  2874. echo -n "${i} "
  2875. echo -ne "\r"
  2876. sleep 1
  2877. done
  2878. echo -e "\n\e[1;35m 消除redis安装启动后的warning \e[0m"
  2879. #消除三个warning
  2880. #Tcp backlog
  2881. #overcommit_memory
  2882. cat >> /etc/sysctl.conf <<EOF
  2883. net.core.somaxconn = 1024
  2884. vm.overcommit_memory = 1
  2885. EOF
  2886. sysctl -p
  2887. #transparent hugepage
  2888. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  2889. echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local
  2890. chmod +x /etc/rc.d/rc.local
  2891. else
  2892. #ubuntu
  2893. echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
  2894. chmod +x /etc/rc.local
  2895. fi
  2896. echo -e "\n\e[1;35m 安装依赖包 \e[0m"
  2897. #安装依赖包 支持systemd
  2898. if [ $ID = 'centos' -o $ID = rocky ];then
  2899. #yum -y install gcc jemalloc-devel systemd-devel
  2900. software=("gcc"
  2901. "jemalloc-devel"
  2902. "systemd-devel"
  2903. )
  2904. for i in ${software[@]}
  2905. do
  2906. 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" ; }
  2907. done
  2908. #ubuntu
  2909. else
  2910. #apt -y install make gcc libjemalloc-dev libsystemd-dev
  2911. software=("make"
  2912. "gcc"
  2913. "libjemalloc-dev"
  2914. "libsystemd-dev"
  2915. )
  2916. for i in ${software[@]}
  2917. do
  2918. 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" ; }
  2919. done
  2920. fi
  2921. #下载源码
  2922. if [ -e /root/redis-${VERSION}.tar.gz ];then
  2923. echo -e "\n\e[1;35m 文件存在,开始安装\e[0m"
  2924. else
  2925. echo -e "\n\e[1;33m 文件不存在,开始下载\e[0m"
  2926. wget ${URL} && echo -e "\n\e[1;32m 下载成功\e[0m" || echo -e "\n\e[1;31m 下载失败,请检查下载链接\e[0m"
  2927. fi
  2928. echo -e "\n\e[1;35m 解压 \e[0m"
  2929. tar xvf /root/redis-${VERSION}.tar.gz
  2930. #编译安装 支持systemd
  2931. echo -e "\n\e[1;35m 编译安装 \e[0m"
  2932. cd /root/redis-${VERSION}
  2933. #指定redis安装目录
  2934. make -j 2 USE_SYSTEMD=yes PREFIX=${INSTALL_DIR} install
  2935. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2936. ln -s ${INSTALL_DIR}/bin/redis-* /usr/bin/
  2937. #配置环境变量
  2938. echo -e "\n\e[1;35m 配置环境变量\e[0m"
  2939. echo 'PATH=/apps/redis/bin:$PATH' > /etc/profile.d/redis.sh
  2940. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2941. #准备相关目录和配置文件
  2942. #创建配置文件、日志、数据等目录
  2943. echo -e "\n\e[1;35m 创建配置文件、日志、数据等目录\e[0m"
  2944. mkdir -p ${INSTALL_DIR}/{etc,log,data,run}
  2945. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2946. cp redis.conf ${INSTALL_DIR}/etc/
  2947. 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
  2948. #前台启动 redis
  2949. #redis-server /apps/redis/etc/redis.conf
  2950. echo -e "\n\e[1;35m 创建redis用户\e[0m"
  2951. #创建redis用户
  2952. if id redis &> /dev/null;then
  2953. echo -e "\n\e[1;35m 用户已存在 \e[0m"
  2954. else
  2955. groupadd -g 679 -r redis && useradd -g redis -r -s /sbin/nologin -d /data/redis -u 679 redis
  2956. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2957. fi
  2958. #设置目录权限
  2959. chown -R redis.redis ${INSTALL_DIR}
  2960. #创建 Redis 服务 Service 文件
  2961. #可以复制CentOS8利用yum安装Redis生成的redis.service文件,进行修改
  2962. #cp /lib/systemd/system/redis.service /lib/systemd/system/
  2963. echo -e "\n\e[1;35m 配置service文件 \e[0m"
  2964. cat >> /lib/systemd/system/redis.service <<EOF
  2965. [Unit]
  2966. Description=Redis persistent key-value database
  2967. After=network.target
  2968. [Service]
  2969. ExecStart=${INSTALL_DIR}/bin/redis-server ${INSTALL_DIR}/etc/redis.conf --supervised systemd
  2970. ExecStop=/bin/kill -s QUIT \$MAINPID
  2971. #如果支持systemd可以启用此行
  2972. Type=notify
  2973. User=redis
  2974. Group=redis
  2975. RuntimeDirectory=redis
  2976. RuntimeDirectoryMode=0755
  2977. LimitNOFILE=1000000
  2978. #指定此值才支持更大的maxclients值
  2979. [Install]
  2980. WantedBy=multi-user.target
  2981. EOF
  2982. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2983. echo -e "\n\e[1;35m 启动redis \e[0m"
  2984. systemctl daemon-reload
  2985. systemctl enable --now redis
  2986. [ $? -eq 0 ] && echo -e "\n\e[1;32m ok \e[0m" || echo -e "\n\e[1;31m false\e[0m"
  2987. systemctl status redis
  2988. #验证客户端连接redis
  2989. #${INSTALL_DIR}/bin/redis-cli -h IP/HOSTNAME -p PORT -a PASSWORD
  2990. echo -e "\n\e[1;35m 连接redis命令 \e[0m"
  2991. echo -e "\n\e[1;35m redis-cli -h IP/HOSTNAME -p PORT -a PASSWORD \e[0m"
  2992. echo -e "\n\e[1;35m redis-cli -a PASSWORD \e[0m"
  2993. }
  2994. compile_install_keepalived(){
  2995. local VERSION=2.2.7
  2996. local URL=https://keepalived.org/software/keepalived-${VERSION}.tar.gz
  2997. echo -e "\n\e[1;35m安装的版本是keepalived-${VERSION},如果不想安装此版本请在5秒内停止运行脚本 \e[0m\n"
  2998. for i in {5..1}
  2999. do
  3000. echo -n "${i} "
  3001. echo -ne "\r"
  3002. sleep 1
  3003. done
  3004. if [ $ID = centos -o $ID = rocky ];then
  3005. yum -y install gcc curl openssl-devel libnl3-devel net-snmp-devel
  3006. else
  3007. apt update
  3008. 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
  3009. fi
  3010. if [ -e keepalived-${VERSION}.tar.gz ];then
  3011. echo -e "\n\e[1;35m文件存在,开始安装\e[0m"
  3012. else
  3013. wget ${URL} && echo -e "\n\e[1;32m下载成功,开始解压安装\e[0m" || echo -e "\n\e[1;31m下载失败,检查下载路径\e[0m"
  3014. fi
  3015. [ -d /usr/local/src ] || mkdir -p /usr/local/src
  3016. echo -e "\n\e[1;35m开始解压\e[0m"
  3017. tar xvf keepalived-${VERSION}.tar.gz -C /usr/local/src
  3018. echo -e "\n\e[1;35m开始编译\e[0m"
  3019. cd /usr/local/src/keepalived-${VERSION}/
  3020. ./configure --prefix=/usr/local/keepalived --disable-fwmark
  3021. make && make install
  3022. echo -e "\n\e[1;35m拷贝配置文件\e[0m"
  3023. mkdir /etc/keepalived
  3024. cp /usr/local/keepalived/etc/keepalived/keepalived.conf.sample /etc/keepalived/keepalived.conf
  3025. systemctl enable --now keepalived.service
  3026. echo -e "\n\e[1;35m修改配置文件\e[0m"
  3027. sed -i 's/vrrp_strict/#vrrp_strict/' /etc/keepalived/keepalived.conf
  3028. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false\e[0m"
  3029. echo -e "\n\e[1;35m重启进程,等待10秒查看服务状态\e[0m"
  3030. killall keepalived
  3031. for i in {10..1}
  3032. do
  3033. echo -n "${i} "
  3034. echo -ne "\r"
  3035. sleep 1
  3036. done
  3037. systemctl restart keepalived.service
  3038. echo -e "\n\e[1;35m查看运行状态\e[0m"
  3039. systemctl status keepalived.service | awk "NR==3"
  3040. }
  3041. install_jumpserver(){
  3042. echo -e "\n\e[1;35m官方在线部署\e[0m"
  3043. curl -sSL https://github.com/jumpserver/jumpserver/releases/download/v3.9.2/quick_start.sh | bash
  3044. }
  3045. install_dns(){
  3046. DOMAIN=wang.org
  3047. HOST=www
  3048. HOST_IP=10.0.0.100
  3049. LOCALHOST=`hostname -I | awk '{print $1}'`
  3050. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  3051. yum install -y bind bind-utils
  3052. elif [ $ID = 'ubuntu' ];then
  3053. apt update
  3054. apt install -y bind9 bind9-utils bind9-host
  3055. else
  3056. color "不支持此操作系统,退出!" 1
  3057. exit
  3058. fi
  3059. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  3060. sed -i -e '/listen-on/s/127.0.0.1/localhost/' -e '/allow-query/s/localhost/any/' -e 's/dnssec-enable yes/dnssec-enable no/' -e 's/dnssec-validation yes/dnssec-validation no/' /etc/named.conf
  3061. cat >> /etc/named.rfc1912.zones <<EOF
  3062. zone "$DOMAIN" IN {
  3063. type master;
  3064. file "$DOMAIN.zone";
  3065. };
  3066. EOF
  3067. cat > /var/named/$DOMAIN.zone <<EOF
  3068. \$TTL 1D
  3069. @ IN SOA master admin (
  3070. 1 ; serial
  3071. 1D ; refresh
  3072. 1H ; retry
  3073. 1W ; expire
  3074. 3H ) ; minimum
  3075. NS master
  3076. master A ${LOCALHOST}
  3077. $HOST A $HOST_IP
  3078. EOF
  3079. chmod 640 /var/named/$DOMAIN.zone
  3080. chgrp named /var/named/$DOMAIN.zone
  3081. elif [ $ID = 'ubuntu' ];then
  3082. sed -i 's/dnssec-validation auto/dnssec-validation no/' /etc/bind/named.conf.options
  3083. cat >> /etc/bind/named.conf.default-zones <<EOF
  3084. zone "$DOMAIN" IN {
  3085. type master;
  3086. file "/etc/bind/$DOMAIN.zone";
  3087. };
  3088. EOF
  3089. cat > /etc/bind/$DOMAIN.zone <<EOF
  3090. \$TTL 1D
  3091. @ IN SOA master admin (
  3092. 1 ; serial
  3093. 1D ; refresh
  3094. 1H ; retry
  3095. 1W ; expire
  3096. 3H ) ; minimum
  3097. NS master
  3098. master A ${LOCALHOST}
  3099. $HOST A $HOST_IP
  3100. EOF
  3101. chgrp bind /etc/bind/$DOMAIN.zone
  3102. else
  3103. color "不支持此操作系统,退出!" 1
  3104. exit
  3105. fi
  3106. systemctl enable named
  3107. systemctl restart named
  3108. systemctl is-active named.service
  3109. if [ $? -eq 0 ] ;then
  3110. color "DNS 服务安装成功!" 0
  3111. else
  3112. color "DNS 服务安装失败!" 1
  3113. exit 1
  3114. fi
  3115. }
  3116. install_rocky8_zabbix6(){
  3117. echo -e "\e[1;35m=============================================================zabbix安装=============================================================\e[0m\n"
  3118. echo -e "\n\e[1;35m安装zabbix6版本\e[0m"
  3119. echo -e "\n\e[1;35mYUM仓库配置\e[0m"
  3120. [[ -e "/etc/yum.repos.d/zabbix.repo" && -e "/etc/yum.repos.d/zabbix-agent2-plugins.repo" ]] && echo -e "\n\e[1;35m检测到已配置\e[0m" || rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
  3121. echo -e "\n\e[1;35mYUM仓库配置修改为清华大学源\e[0m"
  3122. sed -i.bak 's#https://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/yum.repos.d/zabbix.repo
  3123. cat /etc/yum.repos.d/zabbix.repo | grep mirror.tuna.tsinghua.edu.cn
  3124. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3125. dnf clean all
  3126. echo -e "\n\e[1;35m安装软件\e[0m"
  3127. #dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2 -y
  3128. software=("zabbix-server-mysql"
  3129. "zabbix-web-mysql"
  3130. "zabbix-nginx-conf"
  3131. "zabbix-sql-scripts"
  3132. "zabbix-selinux-policy"
  3133. "zabbix-agent2"
  3134. "zabbix-get"
  3135. )
  3136. for i in ${software[@]}
  3137. do
  3138. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  3139. done
  3140. echo -e "\n\e[1;35m安装数据库\e[0m"
  3141. #yum -y install mysql mysql-server
  3142. software=("mysql"
  3143. "mysql-server"
  3144. )
  3145. for i in ${software[@]}
  3146. do
  3147. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  3148. done
  3149. systemctl enable --now mysqld
  3150. [ $? -eq 0 ] && color "安装启动成功" 0 || color "安装启动失败" 1
  3151. echo -e "\n\e[1;35m创建zabbix用户\e[0m"
  3152. cat << EOF | mysql
  3153. create database zabbix character set utf8mb4 collate utf8mb4_bin;
  3154. create user zabbix@localhost identified by '123456';
  3155. grant all privileges on zabbix.* to zabbix@localhost;
  3156. EOF
  3157. [ $? -eq 0 ] && color "创建成功" 0 || color "创建失败" 1
  3158. echo -e "\n\e[1;35m导入初始架构和数据\e[0m"
  3159. cat << EOF | mysql
  3160. set global log_bin_trust_function_creators = 1;
  3161. EOF
  3162. zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p123456 zabbix
  3163. cat << EOF | mysql
  3164. set global log_bin_trust_function_creators = 0;
  3165. EOF
  3166. [ $? -eq 0 ] && color "导入成功" 0 || color "导入失败" 1
  3167. mysql -uzabbix -p123456 zabbix -e 'show tables;'
  3168. echo -e "\n\e[1;35m修改配置\e[0m"
  3169. sed -i.bak '/# DBPassword/a DBPassword=123456' /etc/zabbix/zabbix_server.conf
  3170. #sed -i.bak '/^server/a\ listen 80;\n server_name zabbix.wang.org;' /etc/nginx/conf.d/zabbix.conf
  3171. sed -i.bak '/^server/a\ listen 8080;' /etc/nginx/conf.d/zabbix.conf
  3172. cat >> /etc/php-fpm.d/zabbix.conf <<EOF
  3173. php_value[date.timezone] = Asia/Shanghai
  3174. EOF
  3175. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3176. echo -e "\n\e[1;35m修改字体\e[0m"
  3177. #wget https://files.cnblogs.com/files/blogs/764021/graphfont.rar
  3178. wget https://files.cnblogs.com/files/blogs/764021/SIMHEI.tar.gz
  3179. mv /root/SIMHEI.tar.gz /usr/share/zabbix/assets/fonts/
  3180. tar zxf /usr/share/zabbix/assets/fonts/SIMHEI.tar.gz -C /usr/share/zabbix/assets/fonts/
  3181. mv /usr/share/zabbix/assets/fonts/graphfont.ttf /usr/share/zabbix/assets/fonts/graphfont.ttf.bak
  3182. cp /usr/share/zabbix/assets/fonts/SIMHEI.TTF /usr/share/zabbix/assets/fonts/graphfont.ttf
  3183. echo -e "\n\e[1;35m重启服务\e[0m"
  3184. systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
  3185. systemctl enable zabbix-server zabbix-agent2 nginx php-fpm
  3186. systemctl is-enabled zabbix-agent2.service zabbix-server.service nginx php-fpm
  3187. echo -e "\e[1;35m===========================================================================================================================================\e[0m"
  3188. echo -e "\e[1;32mhttp://`hostname -I`:8080进入配置页面\e[0m"
  3189. echo -e "\n\e[1;32m探测被监控端状态zabbix_get -s 被监控端IP -k agent.ping\e[0m"
  3190. echo -e "\e[1;35m===========================================================================================================================================\e[0m"
  3191. echo -e "\n\e[1;32m中文乱码问题,脚本已经替换了一种字体,如果想替换别的字体按下面步骤操作\e[0m"
  3192. echo -e "\e[1;32m将windows上的字体放在此目录/usr/share/zabbix/assets/fonts\e[0m"
  3193. #echo -e "\e[1;35m执行命令修改sed -i 's/graphfont/新字体名字/g' /usr/share/zabbix/include/defines.inc.php\e[0m"
  3194. echo -e "\e[1;32m新字体改名成graphfont.ttf\e[0m"
  3195. echo -e "\e[1;32mcd /usr/share/zabbix/assets/fonts\e[0m"
  3196. echo -e "\e[1;32mmv graphfont.ttf graphfont.ttf.bak\e[0m"
  3197. echo -e "\e[1;32mcp MSYHBD.TTC graphfont.ttf\e[0m"
  3198. echo -e "\e[1;35m===========================================================================================================================================\e[0m"
  3199. exit
  3200. }
  3201. install_rocky8_zabbix6_agent2(){
  3202. echo -e "\e[1;35m=============================================================zabbix_agent2安装=============================================================\e[0m"
  3203. echo -e "\e[1;35m安装的agent2对应的是zabbix6版本\e[0m\n"
  3204. echo -e "\e[1;35mExample: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com\e[0m"
  3205. read -p "输入SERVER端IP: " ZABBIX_SERVER
  3206. #ZABBIX_SERVER=10.0.0.82
  3207. echo -e "\n\e[1;35mYUM仓库配置\e[0m"
  3208. [[ -e "/etc/yum.repos.d/zabbix.repo" && -e "/etc/yum.repos.d/zabbix-agent2-plugins.repo" ]] && echo -e "\n\e[1;35m检测到已配置\e[0m" || rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
  3209. echo -e "\n\e[1;35mYUM仓库配置修改为清华大学源\e[0m"
  3210. sed -i.bak 's#https://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/yum.repos.d/zabbix.repo
  3211. cat /etc/yum.repos.d/zabbix.repo | grep mirror.tuna.tsinghua.edu.cn
  3212. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3213. echo -e "\n\e[1;35m安装agent2\e[0m"
  3214. yum -y install zabbix-agent2
  3215. #rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-agent2-6.0.5-1.el8.x86_64.rpm
  3216. echo -e "\n\e[1;35m修改配置\e[0m"
  3217. sed -i -e "/^Server=127.0.0.1/c Server=$ZABBIX_SERVER" -e "/^Hostname=Zabbix server/c Hostname=`hostname -I`" /etc/zabbix/zabbix_agent2.conf
  3218. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3219. echo -e "\n\e[1;35m重启服务\e[0m"
  3220. systemctl enable zabbix-agent2.service
  3221. systemctl restart zabbix-agent2.service
  3222. systemctl is-active zabbix-agent2.service
  3223. exit
  3224. }
  3225. install_rocky8_zabbix5(){
  3226. echo -e "\e[1;35m=============================================================zabbix安装=============================================================\e[0m\n"
  3227. echo -e "\e[1;35m安装zabbix5版本\e[0m"
  3228. echo -e "\n\e[1;35mYUM仓库配置\e[0m"
  3229. [ -e /etc/yum.repos.d/zabbix.repo ] && echo -e "\n\e[1;35m检测到已配置\e[0m" || rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
  3230. echo -e "\n\e[1;35mYUM仓库配置修改为清华大学源\e[0m"
  3231. sed -i.bak 's#http://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/yum.repos.d/zabbix.repo
  3232. cat /etc/yum.repos.d/zabbix.repo | grep mirror.tuna.tsinghua.edu.cn
  3233. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3234. dnf clean all
  3235. echo -e "\n\e[1;35m安装软件\e[0m"
  3236. dnf -y install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-agent2 zabbix-get
  3237. yum -y install langpacks-zh_CN
  3238. echo -e "\n\e[1;35m安装,启动数据库\e[0m"
  3239. dnf -y install mysql-server
  3240. systemctl enable --now mysqld
  3241. echo -e "\n\e[1;35m创建zabbix用户\e[0m"
  3242. cat << EOF | mysql
  3243. create database zabbix character set utf8 collate utf8_bin;
  3244. create user zabbix@localhost identified by '123456';
  3245. grant all privileges on zabbix.* to zabbix@localhost;
  3246. set global log_bin_trust_function_creators = 1;
  3247. EOF
  3248. #set global innodb_large_prefix = 1;
  3249. [ $? -eq 0 ] && color "创建成功" 0 || color "创建失败" 1
  3250. echo -e "\n\e[1;35m导入初始架构和数据\e[0m"
  3251. zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
  3252. [ $? -eq 0 ] && color "导入成功" 0 || color "导入失败" 1
  3253. echo 'DBPassword=123456' >> /etc/zabbix/zabbix_server.conf
  3254. echo -e "\n\e[1;35m修改端口号和时区\e[0m"
  3255. #listen 80;
  3256. #server_name example.com;
  3257. #/etc/nginx/conf.d/zabbix.conf
  3258. #sed -ri 's/^#(\ +listen\ +80;)$/\1/' /etc/nginx/conf.d/zabbix.conf
  3259. #sed -ri 's/^# +listen +80(;)$/ +listen +8080\1/' /etc/nginx/conf.d/zabbix.conf
  3260. sed -ri '/# +listen +80;/a \ listen 8080;' /etc/nginx/conf.d/zabbix.conf
  3261. #php_value[date.timezone] = Asia/Shanghai/ /etc/php-fpm.d/zabbix.conf
  3262. #sed -ri 's/^.*Europe\/Riga$/php_value[date.timezone] = Asia\/Shanghai/' /etc/php-fpm.d/zabbix.conf
  3263. #sed -ri 's/Europe\/Riga/Asia\/Shanghai/' /etc/php-fpm.d/zabbix.conf
  3264. sed -ri '/.*Europe\/Riga/a\php_value[date.timezone] = Asia\/Shanghai' /etc/php-fpm.d/zabbix.conf
  3265. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3266. echo -e "\n\e[1;35m修改字体\e[0m"
  3267. #wget https://files.cnblogs.com/files/blogs/764021/graphfont.rar
  3268. wget https://files.cnblogs.com/files/blogs/764021/SIMHEI.tar.gz
  3269. mv /root/SIMHEI.tar.gz /usr/share/zabbix/assets/fonts/
  3270. tar zxf /usr/share/zabbix/assets/fonts/SIMHEI.tar.gz -C /usr/share/zabbix/assets/fonts/
  3271. mv /usr/share/zabbix/assets/fonts/graphfont.ttf /usr/share/zabbix/assets/fonts/graphfont.ttf.bak
  3272. cp /usr/share/zabbix/assets/fonts/SIMHEI.TTF /usr/share/zabbix/assets/fonts/graphfont.ttf
  3273. echo -e "\n\e[1;35m重启服务\e[0m"
  3274. systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
  3275. systemctl enable zabbix-server zabbix-agent2 nginx php-fpm
  3276. echo -e "\e[1;35m===========================================================================================================================================\e[0m"
  3277. echo -e "\e[1;32mhttp://`hostname -I`:8080进入配置页面\e[0m"
  3278. echo -e "\n\e[1;32m探测被监控端状态zabbix_get -s 被监控端IP -k agent.ping\e[0m"
  3279. echo -e "\e[1;32m===========================================================================================================================================\e[0m"
  3280. echo -e "\n\e[1;36m中文乱码问题,脚本已经替换了一种字体,如果想替换别的字体按下面步骤操作\e[0m"
  3281. echo -e "\e[1;32m将windows上的字体放在此目录/usr/share/zabbix/assets/fonts\e[0m"
  3282. #echo -e "\e[1;35m执行命令修改sed -i 's/graphfont/新字体名字/g' /usr/share/zabbix/include/defines.inc.php\e[0m"
  3283. echo -e "\e[1;32m新字体改名成graphfont.ttf\e[0m"
  3284. echo -e "\e[1;32mcd /usr/share/zabbix/assets/fonts\e[0m"
  3285. echo -e "\e[1;32mmv graphfont.ttf graphfont.ttf.bak\e[0m"
  3286. echo -e "\e[1;32mcp MSYHBD.TTC graphfont.ttf\e[0m"
  3287. echo -e "\e[1;35m===========================================================================================================================================\e[0m"
  3288. exit
  3289. }
  3290. install_rocky8_zabbix5_agent2(){
  3291. echo -e "\e[1;35m=============================================================zabbix_agent2安装=============================================================\e[0m"
  3292. echo -e "\e[1;35m安装的agent2对应的是zabbix5版本\e[0m\n"
  3293. echo -e "\e[1;35mExample: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com\e[0m"
  3294. read -p "输入SERVER端IP: " ZABBIX_SERVER
  3295. #ZABBIX_SERVER=10.0.0.82
  3296. echo -e "\n\e[1;35mYUM仓库配置\e[0m"
  3297. [ -e /etc/yum.repos.d/zabbix.repo ] && echo -e "\n\e[1;35m检测到已配置\e[0m" || rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
  3298. echo -e "\n\e[1;35mYUM仓库配置修改为清华大学源\e[0m"
  3299. sed -i.bak 's#http://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#' /etc/yum.repos.d/zabbix.repo
  3300. cat /etc/yum.repos.d/zabbix.repo | grep mirror.tuna.tsinghua.edu.cn
  3301. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3302. echo -e "\n\e[1;35m安装agent2\e[0m"
  3303. yum -y install zabbix-agent2
  3304. #rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-agent2-5.0.5-1.el8.x86_64.rpm
  3305. echo -e "\n\e[1;35m修改配置\e[0m"
  3306. sed -i -e "/^Server=127.0.0.1/c Server=$ZABBIX_SERVER" -e "/^Hostname=Zabbix server/c Hostname=`hostname -I`" /etc/zabbix/zabbix_agent2.conf
  3307. [ $? -eq 0 ] && color "修改成功" 0 || color "修改失败" 1
  3308. echo -e "\n\e[1;35m重启服务\e[0m"
  3309. systemctl enable zabbix-agent2.service
  3310. systemctl restart zabbix-agent2.service
  3311. [ $? -eq 0 ] && color "启动完成" 0 || color "启动失败" 1
  3312. systemctl is-active zabbix-agent2.service
  3313. exit
  3314. }
  3315. install_kubernetes_radhat_master(){
  3316. hostnamectl set-hostname k8s-master
  3317. cat >>/etc/hosts <<EOF
  3318. 10.0.0.11 k8s-master
  3319. 10.0.0.12 k8s-node1
  3320. 10.0.0.13 k8s-node2
  3321. EOF
  3322. sed -i.bak '/swap/s@^@#@' /etc/fstab
  3323. swapoff -a
  3324. cat > /etc/sysctl.d/k8s.conf<<EOF
  3325. net.ipv4.ip_forward=1
  3326. net.bridge.bridge-nf-call-ip6tables = 1
  3327. net.bridge.bridge-nf-call-iptables = 1
  3328. EOF
  3329. sysctl -p
  3330. yum install -y yum-utils
  3331. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3332. yum -y install docker-ce-20.10.7-3.el7 docker-ce-cli-20.10.7-3.el7 containerd.io docker-compose-plugin
  3333. systemctl enable --now docker
  3334. cat > /etc/docker/daemon.json <<EOF
  3335. {
  3336. "exec-opts": ["native.cgroupdriver=systemd"],
  3337. "log-driver": "json-file",
  3338. "log-opts": {
  3339. "max-size": "100m"
  3340. },
  3341. "storage-driver": "overlay2"
  3342. }
  3343. EOF
  3344. systemctl daemon-reload;systemctl restart docker
  3345. cat >/etc/yum.repos.d/kubernetes.repo <<EOF
  3346. [kubernetes]
  3347. name=Kubernetes
  3348. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  3349. enabled=1
  3350. gpgcheck=1
  3351. repo_gpgcheck=0
  3352. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  3353. EOF
  3354. yum install -y kubeadm-1.23.6-0 kubectl-1.23.6-0 kubelet-1.23.6-0 --disableexcludes=kubernetes
  3355. kubeadm init --apiserver-advertise-address=10.0.0.11 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.6 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
  3356. exec bash
  3357. }
  3358. install_kubernetes_redhat_node1(){
  3359. hostnamectl set-hostname k8s-node1
  3360. cat >>/etc/hosts <<EOF
  3361. 10.0.0.11 k8s-master
  3362. 10.0.0.12 k8s-node1
  3363. 10.0.0.13 k8s-node2
  3364. EOF
  3365. sed -i.bak '/swap/s@^@#@' /etc/fstab
  3366. swapoff -a
  3367. cat > /etc/sysctl.d/k8s.conf<<EOF
  3368. net.ipv4.ip_forward=1
  3369. net.bridge.bridge-nf-call-ip6tables = 1
  3370. net.bridge.bridge-nf-call-iptables = 1
  3371. EOF
  3372. sysctl -p
  3373. yum install -y yum-utils
  3374. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3375. yum -y install docker-ce-20.10.7-3.el7 docker-ce-cli-20.10.7-3.el7 containerd.io docker-compose-plugin
  3376. systemctl enable --now docker
  3377. cat > /etc/docker/daemon.json <<EOF
  3378. {
  3379. "exec-opts": ["native.cgroupdriver=systemd"],
  3380. "log-driver": "json-file",
  3381. "log-opts": {
  3382. "max-size": "100m"
  3383. },
  3384. "storage-driver": "overlay2"
  3385. }
  3386. EOF
  3387. systemctl daemon-reload;systemctl restart docker
  3388. cat >/etc/yum.repos.d/kubernetes.repo <<EOF
  3389. [kubernetes]
  3390. name=Kubernetes
  3391. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  3392. enabled=1
  3393. gpgcheck=1
  3394. repo_gpgcheck=0
  3395. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  3396. EOF
  3397. yum install -y kubeadm-1.23.6-0 kubectl-1.23.6-0 kubelet-1.23.6-0 --disableexcludes=kubernetes
  3398. exec bash
  3399. }
  3400. install_kubernetes_redhat_node2(){
  3401. hostnamectl set-hostname k8s-node2
  3402. cat >>/etc/hosts <<EOF
  3403. 10.0.0.11 k8s-master
  3404. 10.0.0.12 k8s-node1
  3405. 10.0.0.13 k8s-node2
  3406. EOF
  3407. sed -i.bak '/swap/s@^@#@' /etc/fstab
  3408. swapoff -a
  3409. cat > /etc/sysctl.d/k8s.conf<<EOF
  3410. net.ipv4.ip_forward=1
  3411. net.bridge.bridge-nf-call-ip6tables = 1
  3412. net.bridge.bridge-nf-call-iptables = 1
  3413. EOF
  3414. sysctl -p
  3415. yum install -y yum-utils
  3416. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  3417. yum -y install docker-ce-20.10.7-3.el7 docker-ce-cli-20.10.7-3.el7 containerd.io docker-compose-plugin
  3418. systemctl enable --now docker
  3419. cat > /etc/docker/daemon.json <<EOF
  3420. {
  3421. "exec-opts": ["native.cgroupdriver=systemd"],
  3422. "log-driver": "json-file",
  3423. "log-opts": {
  3424. "max-size": "100m"
  3425. },
  3426. "storage-driver": "overlay2"
  3427. }
  3428. EOF
  3429. systemctl daemon-reload;systemctl restart docker
  3430. cat >/etc/yum.repos.d/kubernetes.repo <<EOF
  3431. [kubernetes]
  3432. name=Kubernetes
  3433. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  3434. enabled=1
  3435. gpgcheck=1
  3436. repo_gpgcheck=0
  3437. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  3438. EOF
  3439. yum install -y kubeadm-1.23.6-0 kubectl-1.23.6-0 kubelet-1.23.6-0 --disableexcludes=kubernetes
  3440. exec bash
  3441. }
  3442. install_kubernetes_ubuntu_master(){
  3443. #CIR_DOCKER_VERSION=0.3.0
  3444. #CIR_DOCKER_URL="https://github.com/Mirantis/cri-dockerd/releases/download/v${CIR_DOCKER_VERSION}/cri-dockerd_${CIR_DOCKER_VERSION}.3-0.ubuntu-${UBUNTU_CODENAME}_amd64.deb"
  3445. #"https://github.com/Mirantis/cri-dockerd/releases/download/v${CIR_DOCKER_VERSION}/cri-dockerd_${CIR_DOCKER_VERSION}.3-0.ubuntu-${UBUNTU_CODENAME}_amd64.deb"
  3446. #hostnamectl set-hostname k8s-master01.he.com
  3447. echo -e "\e[1;32m更换apt源\e[0m"
  3448. cat > /etc/apt/sources.list <<EOF
  3449. deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3450. deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3451. deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  3452. deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  3453. deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  3454. deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  3455. # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  3456. # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  3457. deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  3458. deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  3459. EOF
  3460. cat >> /etc/hosts <<EOF
  3461. 10.0.0.100 k8s-master01.he.com k8s-master01 kubeapi.he.com k8sapi.he.com kubeapi
  3462. 10.0.0.101 k8s-node01.he.com k8s-node01
  3463. 10.0.0.102 k8s-node02.he.com k8s-node02
  3464. 10.0.0.103 k8s-node03.he.com k8s-node03
  3465. EOF
  3466. echo -e "\e[1;32m关闭swap\e[0m"
  3467. swapoff -a
  3468. echo -e "\e[1;32m关闭防火墙\e[0m"
  3469. ufw disable
  3470. sudo apt-get update
  3471. echo -e "\e[1;32m安装必要的一些系统工具\e[0m"
  3472. #安装必要的一些系统工具
  3473. sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
  3474. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3475. echo -e "\e[1;32m安装GPG证书\e[0m"
  3476. #安装GPG证书
  3477. curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
  3478. echo -e "\e[1;32m写入软件源信息\e[0m"
  3479. #写入软件源信息
  3480. sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  3481. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3482. echo -e "\e[1;32m更新并安装Docker-CE\e[0m"
  3483. #更新并安装Docker-CE
  3484. sudo apt-get -y update
  3485. sudo apt-get -y install docker-ce
  3486. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3487. echo -e "\e[1;32mdocker镜像加速\e[0m"
  3488. cat > /etc/docker/daemon.json <<EOF
  3489. {
  3490. "registry-mirrors": [
  3491. "https://docker.mirrors.ustc.edu.cn",
  3492. "https://hub-mirror.c.163.com",
  3493. "https://reg-mirror.qiniu.com",
  3494. "https://registry.docker-cn.com"
  3495. ],
  3496. "exec-opts": ["native.cgroupdriver=systemd"],
  3497. "log-driver": "json-file",
  3498. "log-opts": {
  3499. "max-size": "200m"
  3500. },
  3501. "storage-driver": "overlay2"
  3502. }
  3503. EOF
  3504. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3505. systemctl daemon-reload
  3506. systemctl enable --now docker.service
  3507. systemctl restart docker.service
  3508. echo -e "\e[1;32m安装cri-docker\e[0m"
  3509. #curl -LO https://github.com/Mirantis/cri-dockerd/releases/tag/v0.2.5
  3510. if [ -e cri-dockerd_0.3.0.3-0.ubuntu-focal_amd64.deb ];then
  3511. dpkg -i cri-dockerd_0.3.0.3-0.ubuntu-focal_amd64.deb
  3512. else
  3513. echo -e "\e[1;32mcri-docker,尝试下载\e[0m"
  3514. #curl -LO https://github.com/Mirantis/cri-dockerd/releases/tag/v0.2.5
  3515. curl -LO https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.0/cri-dockerd_0.3.0.3-0.ubuntu-focal_amd64.deb
  3516. if [ $? -eq 0 ];then
  3517. echo -e "\e[1;32m下载成功\e[0m"
  3518. dpkg -i cri-dockerd_0.2.5.3-0.ubuntu-focal_amd64.deb
  3519. else
  3520. echo -e "\e[1;31m下载失败\e[0m"
  3521. exit
  3522. fi
  3523. fi
  3524. echo -e "\e[1;32m在各个节点安装工具kubelet、kubeadm和kubectl\e[0m"
  3525. #在各个节点安装工具kubelet、kubeadm和kubectl
  3526. curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
  3527. cat >/etc/apt/sources.list.d/kubernetes.list <<EOF
  3528. deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
  3529. EOF
  3530. #apt-get update && apt-get install -y kubelet-1.24.3 kubeadm-1.24.3 kubectl-1.24.3
  3531. #dpkg -i kubeadm_1.24.3.deb kubectl_1.24.3.deb kubelet_1.24.3.deb
  3532. apt-get update && apt install -y kubeadm=1.24.3-00 kubelet=1.24.3-00 kubectl=1.24.3-00
  3533. #cat > /usr/lib/systemd/system/cri-docker.service <<EOF
  3534. #[Service]
  3535. #Type=notify
  3536. #ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// #添加下面一行
  3537. #ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/cni/cache --cni-conf-dir=/etc/cni/net.d
  3538. #EOF
  3539. sed -i "s/^ExecStart/#&/" /usr/lib/systemd/system/cri-docker.service
  3540. sed -i '11iExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/cni/cache --cni-conf-dir=/etc/cni/net.d' /usr/lib/systemd/system/cri-docker.service
  3541. systemctl daemon-reload && systemctl restart cri-docker.service
  3542. echo -e "\e[1;32m配置kubelet,为其指定cri-dockerd在本地打开的Unix Sock文件的路径\e[0m"
  3543. #配置kubelet,为其指定cri-dockerd在本地打开的Unix Sock文件的路径
  3544. mkdir /etc/sysconfig
  3545. cat > /etc/sysconfig/kubelet <<EOF
  3546. KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime-endpoint=/run/cri-dockerd.sock"
  3547. EOF
  3548. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3549. cat >>/etc/containerd/config.toml << EOF
  3550. [plugins."io.containerd.grpc.v1.cri"]
  3551. # sandbox_image = "k8s.gcr.io/pause:3.6"
  3552. sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"
  3553. EOF
  3554. systemctl start containerd
  3555. systemctl enable containerd
  3556. #在master节点导入
  3557. #docker load -i k8s-master-components.tar
  3558. #在node节点导入
  3559. #docker load -i k8s-worker-components.tar
  3560. #在master和node都导入
  3561. #docker load -i calico-components.tar
  3562. echo -e "\e[1;32m初始化\e[0m"
  3563. kubeadm init \
  3564. --control-plane-endpoint="kubeapi.he.com" \
  3565. --kubernetes-version=v1.24.3 \
  3566. --pod-network-cidr=192.168.0.0/16 \
  3567. --service-cidr=10.96.0.0/12 \
  3568. --token-ttl=0 \
  3569. --cri-socket unix:///run/cri-dockerd.sock \
  3570. --upload-certs \
  3571. --image-repository=registry.aliyuncs.com/google_containers
  3572. }
  3573. install_kubernetes_ubuntu_master1(){
  3574. echo -e "\e[1;32m安装kubernetes1.22.7版本\e[0m"
  3575. echo -e "\e[1;32m更换apt源\e[0m"
  3576. cat > /etc/apt/sources.list <<EOF
  3577. deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3578. deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3579. deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  3580. deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  3581. deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  3582. deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  3583. # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  3584. # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  3585. deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  3586. deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  3587. EOF
  3588. echo -e "\e[1;32m关闭swap\e[0m"
  3589. swapoff -a
  3590. sed -i '/swap/s/^/#/' /etc/fstab
  3591. echo -e "\e[1;32m关闭防火墙\e[0m"
  3592. ufw disable
  3593. sudo apt-get update
  3594. echo -e "\e[1;32m时间同步\e[0m"
  3595. apt -y install ntpdate
  3596. ntpdate time2.aliyun.com
  3597. echo -e "\e[1;32m安装必要的一些系统工具\e[0m"
  3598. sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
  3599. echo -e "\e[1;32m更新并安装Docker-io\e[0m"
  3600. apt update && apt -y install docker.io
  3601. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3602. echo -e "\e[1;32m配置docker镜像加速\e[0m"
  3603. cat > /etc/docker/daemon.json <<EOF
  3604. {
  3605. "registry-mirrors": [
  3606. "https://docker.mirrors.ustc.edu.cn",
  3607. "https://hub-mirror.c.163.com",
  3608. "https://reg-mirror.qiniu.com",
  3609. "https://registry.docker-cn.com"
  3610. ],
  3611. "exec-opts": ["native.cgroupdriver=systemd"],
  3612. "log-driver": "json-file",
  3613. "log-opts": {
  3614. "max-size": "200m"
  3615. },
  3616. "storage-driver": "overlay2"
  3617. }
  3618. EOF
  3619. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3620. echo -e "\e[1;32m加载docker配置并重启服务\e[0m"
  3621. systemctl daemon-reload && systemctl restart docker.service
  3622. echo -e "\e[1;32m在各个节点安装工具kubelet、kubeadm和kubectl\e[0m"
  3623. curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
  3624. cat >/etc/apt/sources.list.d/kubernetes.list <<EOF
  3625. deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
  3626. EOF
  3627. apt-get update && apt install -y kubeadm=1.22.7-00 kubelet=1.22.7-00 kubectl=1.22.7-00
  3628. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3629. cat > /etc/default/kubelet <<EOF
  3630. KUBELET_EXTRA_ARGS="--fail-swap-on=false"
  3631. EOF
  3632. systemctl daemon-reload && systemctl restart kubelet
  3633. echo -e "\e[1;32m master节点执行\e[0m\n"
  3634. echo -e "\e[1;31mkubeadm init --kubernetes-version=v1.22.7 --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.24.0.0/16 --ignore-preflight-errors=Swap\e[0m"
  3635. echo -e "\e[1;32mcurl https://projectcalico.docs.tigera.io/archive/v3.24/manifests/calico.yaml -O\e[0m"
  3636. echo -e "\e[1;31mkubectl apply -f calico.yaml\e[0m"
  3637. }
  3638. install_kubernetes_ubuntu_master2(){
  3639. echo -e "\e[1;31mload\e[0m"
  3640. }
  3641. install_kubernetes_radhat_master(){
  3642. echo -e "\e[1;32m安装kubernetes1.27.4版本\e[0m"
  3643. #echo -e "\e[1;32m配置yum源\e[0m"
  3644. #[ ! -d /data/bak ] && mkdir -p /data/bak
  3645. #判断文件夹是否有文件
  3646. # if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
  3647. # mv /etc/yum.repos.d/* /data/bak
  3648. # else
  3649. # echo ""
  3650. # fi
  3651. #[ -d /mnt/cdrom ] || mkdir /mnt/cdrom
  3652. #mount /dev/sr0 /mnt/cdrom
  3653. #cat > /etc/yum.repos.d/base.repo <<EOF
  3654. #[base]
  3655. #name=CentOS
  3656. #baseurl=file:///mnt/cdrom/BaseOS
  3657. # https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
  3658. # https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
  3659. # https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
  3660. # https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
  3661. #gpgcheck=0
  3662. #[extras]
  3663. #name=extras
  3664. #baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
  3665. # https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
  3666. # https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
  3667. # https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
  3668. #
  3669. #gpgcheck=0
  3670. #enabled=1
  3671. #[epel]
  3672. #name=EPEL
  3673. #baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
  3674. # https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
  3675. # https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
  3676. # https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
  3677. # http://mirrors.aliyun.com/epel/\$releasever/\$basearch
  3678. #gpgcheck=0
  3679. #enabled=1
  3680. #EOF
  3681. # yum clean all
  3682. # yum makecache
  3683. # yum repolist
  3684. #cat >> /etc/fstab << EOF
  3685. #/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  3686. #EOF
  3687. #[ $? -eq 0 ] && color 已配置 0 || { color 写入失败 1;exit; }
  3688. echo -e "\e[1;32m关闭swap\e[0m"
  3689. swapoff -a
  3690. sed -i '/swap/s/^/#/' /etc/fstab
  3691. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3692. #echo -e "\e[1;32m关闭防火墙\e[0m"
  3693. #systemctl disable --now firewalld
  3694. #echo -e "\e[1;32m时间同步\e[0m"
  3695. #yum -y install ntpdate
  3696. #ntpdate time2.aliyun.com
  3697. # 加入到crontab
  3698. #*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
  3699. echo -e "\e[1;32m修改主机名\e[0m"
  3700. hostnamectl set-hostname k8s-master01
  3701. cat <<EOF >> /etc/hosts
  3702. 10.0.0.21 k8s-master01
  3703. 10.0.0.22 k8s-node01
  3704. 10.0.0.23 k8s-node02
  3705. EOF
  3706. echo -e "\e[1;32m修改Linux内核参数,添加网桥过滤器和地址转发功能\e[0m"
  3707. cat >> /etc/sysctl.d/kubernetes.conf <<EOF
  3708. net.bridge.bridge-nf-call-ip6tables = 1
  3709. net.bridge.bridge-nf-call-iptables = 1
  3710. net.ipv4.ip_forward = 1
  3711. EOF
  3712. modprobe br_netfilter
  3713. sysctl -p /etc/sysctl.d/kubernetes.conf
  3714. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3715. echo -e "\e[1;32m配置ipvs功能\e[0m"
  3716. yum -y install ipset ipvsadm
  3717. cat > /etc/sysconfig/modules/ipvs.modules <<EOF
  3718. modprobe -- ip_vs
  3719. modprobe -- ip_vs_rr
  3720. modprobe -- ip_vs_wrr
  3721. modprobe -- ip_vs_sh
  3722. modprobe -- nf_conntrack_ipv4
  3723. EOF
  3724. chmod +x /etc/sysconfig/modules/ipvs.modules
  3725. /etc/sysconfig/modules/ipvs.modules
  3726. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3727. echo -e "\e[1;32m安装Docker容器\e[0m"
  3728. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  3729. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  3730. yum makecache
  3731. yum install -y yum-utils
  3732. yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3733. yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 -y
  3734. mkdir /etc/docker
  3735. cat <<EOF > /etc/docker/daemon.json
  3736. {
  3737. "registry-mirrors": [
  3738. "https://docker.mirrors.ustc.edu.cn",
  3739. "https://hub-mirror.c.163.com",
  3740. "https://reg-mirror.qiniu.com",
  3741. "https://registry.docker-cn.com"
  3742. ],
  3743. "exec-opts": ["native.cgroupdriver=systemd"],
  3744. "log-driver": "json-file",
  3745. "log-opts": {
  3746. "max-size": "200m"
  3747. },
  3748. "storage-driver": "overlay2"
  3749. }
  3750. EOF
  3751. systemctl enable --now docker
  3752. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3753. echo -e "\e[1;32m安装cri-dockerd-0.3.1插件\e[0m"
  3754. if [ -e cri-dockerd-0.3.1-3.el7.x86_64.rpm ];then
  3755. echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
  3756. else
  3757. echo -e "\e[1;31m开始下载\e[0m"
  3758. wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3759. if [ $? -eq 0 ];then
  3760. echo -e "\e[1;32m下载成功\e[0m"
  3761. else
  3762. echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
  3763. exit
  3764. fi
  3765. fi
  3766. #wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3767. rpm -ivh cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3768. sed -i "s/^ExecStart/#&/" /usr/lib/systemd/system/cri-docker.service
  3769. sed -i '10iExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7' /usr/lib/systemd/system/cri-docker.service
  3770. systemctl daemon-reload && systemctl restart docker cri-docker.socket cri-docker
  3771. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3772. echo -e "\e[1;32m配置国内yum源,安装 kubeadm、kubelet、kubectl\e[0m"
  3773. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
  3774. [kubernetes]
  3775. name=Kubernetes
  3776. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  3777. enabled=1
  3778. gpgcheck=0
  3779. EOF
  3780. yum install -y kubelet-1.27.4 kubeadm-1.27.4 kubectl-1.27.4
  3781. systemctl enable kubelet.service --now
  3782. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3783. echo -e "\e[1;32m安装runc-1.1.10\e[0m"
  3784. if [ -e runc.amd64 ];then
  3785. echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
  3786. else
  3787. echo -e "\e[1;31m开始下载\e[0m"
  3788. wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64
  3789. if [ $? -eq 0 ];then
  3790. echo -e "\e[1;32m下载成功\e[0m"
  3791. else
  3792. echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
  3793. exit
  3794. fi
  3795. fi
  3796. sudo install -m 755 runc.amd64 /usr/local/bin/runc
  3797. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3798. runc -v
  3799. echo -e "\e[1;32m初始化\e[0m"
  3800. kubeadm init --node-name=k8s-master01 --image-repository=registry.aliyuncs.com/google_containers --cri-socket=unix:///var/run/cri-dockerd.sock --apiserver-advertise-address=10.0.0.21 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
  3801. mkdir -p $HOME/.kube
  3802. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3803. sudo chown $(id -u):$(id -g) $HOME/.kube/config
  3804. echo -e "\e[1;32m部署flannel\e[0m"
  3805. if [ -e kube-flannel.yml ];then
  3806. echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
  3807. else
  3808. echo -e "\e[1;31m开始下载\e[0m"
  3809. wget https://github.com/flannel-io/flannel/releases/download/v0.22.0/kube-flannel.yml
  3810. if [ $? -eq 0 ];then
  3811. echo -e "\e[1;32m下载成功\e[0m"
  3812. else
  3813. echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
  3814. exit
  3815. fi
  3816. fi
  3817. kubectl apply -f kube-flannel.yml
  3818. exec bash
  3819. }
  3820. install_kubernetes_radhat_node(){
  3821. echo -e "\e[1;32m安装kubernetes1.27.4版本\e[0m"
  3822. #echo -e "\e[1;32m配置yum源\e[0m"
  3823. #[ ! -d /data/bak ] && mkdir -p /data/bak
  3824. #判断文件夹是否有文件
  3825. # if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
  3826. # mv /etc/yum.repos.d/* /data/bak
  3827. # else
  3828. # echo ""
  3829. # fi
  3830. #[ -d /mnt/cdrom ] || mkdir /mnt/cdrom
  3831. #mount /dev/sr0 /mnt/cdrom
  3832. #cat > /etc/yum.repos.d/base.repo <<EOF
  3833. #[base]
  3834. #name=CentOS
  3835. #baseurl=file:///mnt/cdrom/BaseOS
  3836. # https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
  3837. # https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
  3838. # https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
  3839. # https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
  3840. #gpgcheck=0
  3841. #[extras]
  3842. #name=extras
  3843. #baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
  3844. # https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
  3845. # https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
  3846. # https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
  3847. #
  3848. #gpgcheck=0
  3849. #enabled=1
  3850. #[epel]
  3851. #name=EPEL
  3852. #baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
  3853. # https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
  3854. # https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
  3855. # https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
  3856. # http://mirrors.aliyun.com/epel/\$releasever/\$basearch
  3857. #gpgcheck=0
  3858. #enabled=1
  3859. #EOF
  3860. # yum clean all
  3861. # yum makecache
  3862. # yum repolist
  3863. #cat >> /etc/fstab << EOF
  3864. #/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
  3865. #EOF
  3866. #[ $? -eq 0 ] && color 已配置 0 || { color 写入失败 1;exit; }
  3867. echo -e "\e[1;32m关闭swap\e[0m"
  3868. swapoff -a
  3869. sed -i '/swap/s/^/#/' /etc/fstab
  3870. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3871. #echo -e "\e[1;32m关闭防火墙\e[0m"
  3872. #systemctl disable --now firewalld
  3873. #echo -e "\e[1;32m时间同步\e[0m"
  3874. #yum -y install ntpdate
  3875. #ntpdate time2.aliyun.com
  3876. # 加入到crontab
  3877. #*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
  3878. echo -e "\e[1;32m修改主机名\e[0m"
  3879. hostnamectl set-hostname k8s-node02
  3880. cat <<EOF >> /etc/hosts
  3881. 10.0.0.21 k8s-master01
  3882. 10.0.0.22 k8s-node01
  3883. 10.0.0.23 k8s-node02
  3884. EOF
  3885. echo -e "\e[1;32m修改Linux内核参数,添加网桥过滤器和地址转发功能\e[0m"
  3886. cat >> /etc/sysctl.d/kubernetes.conf <<EOF
  3887. net.bridge.bridge-nf-call-ip6tables = 1
  3888. net.bridge.bridge-nf-call-iptables = 1
  3889. net.ipv4.ip_forward = 1
  3890. EOF
  3891. modprobe br_netfilter
  3892. sysctl -p /etc/sysctl.d/kubernetes.conf
  3893. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3894. echo -e "\e[1;32m配置ipvs功能\e[0m"
  3895. yum -y install ipset ipvsadm
  3896. cat > /etc/sysconfig/modules/ipvs.modules <<EOF
  3897. modprobe -- ip_vs
  3898. modprobe -- ip_vs_rr
  3899. modprobe -- ip_vs_wrr
  3900. modprobe -- ip_vs_sh
  3901. modprobe -- nf_conntrack_ipv4
  3902. EOF
  3903. chmod +x /etc/sysconfig/modules/ipvs.modules
  3904. /etc/sysconfig/modules/ipvs.modules
  3905. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3906. echo -e "\e[1;32m安装Docker容器\e[0m"
  3907. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  3908. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  3909. yum makecache
  3910. yum install -y yum-utils
  3911. yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3912. yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 -y
  3913. mkdir /etc/docker
  3914. cat <<EOF > /etc/docker/daemon.json
  3915. {
  3916. "registry-mirrors": [
  3917. "https://docker.mirrors.ustc.edu.cn",
  3918. "https://hub-mirror.c.163.com",
  3919. "https://reg-mirror.qiniu.com",
  3920. "https://registry.docker-cn.com"
  3921. ],
  3922. "exec-opts": ["native.cgroupdriver=systemd"],
  3923. "log-driver": "json-file",
  3924. "log-opts": {
  3925. "max-size": "200m"
  3926. },
  3927. "storage-driver": "overlay2"
  3928. }
  3929. EOF
  3930. systemctl enable --now docker
  3931. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3932. echo -e "\e[1;32m安装cri-dockerd-0.3.1插件\e[0m"
  3933. if [ -e cri-dockerd-0.3.1-3.el7.x86_64.rpm ];then
  3934. echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
  3935. else
  3936. echo -e "\e[1;31m开始下载\e[0m"
  3937. wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3938. if [ $? -eq 0 ];then
  3939. echo -e "\e[1;32m下载成功\e[0m"
  3940. else
  3941. echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
  3942. exit
  3943. fi
  3944. fi
  3945. #wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3946. rpm -ivh cri-dockerd-0.3.1-3.el7.x86_64.rpm
  3947. sed -i "s/^ExecStart/#&/" /usr/lib/systemd/system/cri-docker.service
  3948. sed -i '10iExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7' /usr/lib/systemd/system/cri-docker.service
  3949. systemctl daemon-reload && systemctl restart docker cri-docker.socket cri-docker
  3950. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3951. echo -e "\e[1;35m============================================================================================================================================\e[0m"
  3952. echo -e "\e[1;32m配置国内yum源,安装 kubeadm、kubelet、kubectl\e[0m"
  3953. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
  3954. [kubernetes]
  3955. name=Kubernetes
  3956. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  3957. enabled=1
  3958. gpgcheck=0
  3959. EOF
  3960. yum install -y kubelet-1.27.4 kubeadm-1.27.4 kubectl-1.27.4
  3961. systemctl enable kubelet.service --now
  3962. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3963. echo -e "\e[1;35m==============================================================================================================================================\e[0m"
  3964. echo -e "\e[1;32m安装runc-1.1.10\e[0m"
  3965. if [ -e runc.amd64 ];then
  3966. echo -e "\e[1;35m 文件已存在,开始安装\e[0m"
  3967. else
  3968. echo -e "\e[1;31m开始下载\e[0m"
  3969. wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64
  3970. if [ $? -eq 0 ];then
  3971. echo -e "\e[1;32m下载成功\e[0m"
  3972. else
  3973. echo -e "\e[1;32m下载失败,检查下载链接\e[0m"
  3974. exit
  3975. fi
  3976. fi
  3977. sudo install -m 755 runc.amd64 /usr/local/bin/runc
  3978. [ $? -eq 0 ] && color "成功 " 0 || color "失败 " 1
  3979. runc -v
  3980. #echo -e "\e[1;35m=============================================================================================================================================\e[0m"
  3981. #echo -e "\e[1;32m初始化\e[0m"
  3982. #kubeadm init --node-name=k8s-master01 --image-repository=registry.aliyuncs.com/google_containers --cri-socket=unix:///var/run/cri-dockerd.sock --apiserver-advertise-address=10.0.0.21 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
  3983. echo -e "\e[1;32mkubeadm join 结尾加上一下命令\e[0m"
  3984. echo "echo "--cri-socket unix:///var/run/cri-dockerd.sock""
  3985. echo -e "\e[1;35m==========================================================================================================================================================================================================================================\e[0m"
  3986. echo -e "\e[1;32m部署flannel\e[0m"
  3987. echo -e "\e[1;32mwget https://github.com/flannel-io/flannel/releases/download/v0.22.0/kube-flannel.yml\e[0m"
  3988. echo -e "\e[1;32mkubectl apply -f kube-flannel.yml\e[0m"
  3989. exec bash
  3990. }
  3991. reset_kubenetes(){
  3992. kubeadm reset -f --cri-socket unix:///run/cri-dockerd.sock
  3993. rm -rf /etc/kubernetes/ /var/lib/kubelet/
  3994. }
  3995. install_kubernetes_ubuntu(){
  3996. while :;do
  3997. echo -e "\E[$[RANDOM%7+31];1m"
  3998. cat << EOF
  3999. ************************************************************
  4000. ************************************************************
  4001. ************************************************************
  4002. ********** **********
  4003. ********** 安装kubernetes **********
  4004. ********** for ubuntu **********
  4005. ********** **********
  4006. ********** 1.返回上一目录 **********
  4007. ********** **********
  4008. ********** 2.1.25.0 **********
  4009. ********** 3.1.22.7 **********
  4010. ********** **********
  4011. ********** 0.退出 **********
  4012. ********** **********
  4013. ************************************************************
  4014. ************************************************************
  4015. ************************************************************
  4016. EOF
  4017. echo -e "\E[0m"
  4018. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4019. case $Menu in
  4020. 1) break
  4021. ;;
  4022. 2) install_kubernetes_ubuntu_master
  4023. ;;
  4024. 3) install_kubernetes_ubuntu_master1
  4025. ;;
  4026. 0) set_et
  4027. ;;
  4028. esac
  4029. done
  4030. }
  4031. install_kubernetes_radhat(){
  4032. while :;do
  4033. echo -e "\E[$[RANDOM%7+31];1m"
  4034. cat << EOF
  4035. ************************************************************
  4036. ************************************************************
  4037. ************************************************************
  4038. ********** **********
  4039. ********** 安装kubernetes **********
  4040. ********** for radhat **********
  4041. ********** **********
  4042. ********** 1.返回上一目录 **********
  4043. ********** **********
  4044. ********** 2.安装master01(1.27.4) **********
  4045. ********** 3.安装node(1.27.4) **********
  4046. ********** **********
  4047. ********** 0.退出 **********
  4048. ********** **********
  4049. ************************************************************
  4050. ************************************************************
  4051. ************************************************************
  4052. EOF
  4053. echo -e "\E[0m"
  4054. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4055. case $Menu in
  4056. 1) break
  4057. ;;
  4058. 2) install_kubernetes_radhat_master
  4059. ;;
  4060. 3) install_kubernetes_radhat_node
  4061. ;;
  4062. 0) set_et
  4063. ;;
  4064. esac
  4065. done
  4066. }
  4067. install_kubernetes(){
  4068. while :;do
  4069. echo -e "\E[$[RANDOM%7+31];1m"
  4070. cat << EOF
  4071. ************************************************************
  4072. ************************************************************
  4073. ************************************************************
  4074. ********** **********
  4075. ********** 安装kubernetes **********
  4076. ********** **********
  4077. ********** 1.返回上一目录 **********
  4078. ********** **********
  4079. ********** 2.redhat **********
  4080. ********** 3.ubuntu **********
  4081. ********** 4.重置 **********
  4082. ********** **********
  4083. ********** 0.退出 **********
  4084. ********** **********
  4085. ************************************************************
  4086. ************************************************************
  4087. ************************************************************
  4088. EOF
  4089. echo -e "\E[0m"
  4090. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4091. case $Menu in
  4092. 1) break
  4093. ;;
  4094. 2) install_kubernetes_radhat
  4095. ;;
  4096. 3) install_kubernetes_ubuntu
  4097. ;;
  4098. 4) reset_kubenetes
  4099. ;;
  4100. 0) set_et
  4101. ;;
  4102. esac
  4103. done
  4104. }
  4105. ubuntu_docker(){
  4106. ${PURPLE} 占坑 $END
  4107. }
  4108. install_podman(){
  4109. ${PURPLE} 占坑 $END
  4110. }
  4111. install_lvs(){
  4112. ${PURPLE} lvs $END
  4113. }
  4114. install_tomcat(){
  4115. ${PURPLE} tomcat $END
  4116. }
  4117. install_haproxy(){
  4118. ${PURPLE} haproxy $END
  4119. }
  4120. install_jenkins(){
  4121. ${PURPLE} jenkins $END
  4122. }
  4123. install_halo(){
  4124. ${PURPLE} halo $END
  4125. }
  4126. install_lua(){
  4127. ${PURPLE} lua $END
  4128. }
  4129. install_gitlab(){
  4130. ${PURPLE} gitlab $END
  4131. }
  4132. install_git(){
  4133. ${PURPLE} git $END
  4134. }
  4135. install_wordpress(){
  4136. ${PURPLE} wordpress $END
  4137. }
  4138. install_apache(){
  4139. ${PURPLE} apache $END
  4140. }
  4141. install_jdk(){
  4142. ${PURPLE} jdk $END
  4143. }
  4144. install_php(){
  4145. ${PURPLE} php $END
  4146. }
  4147. install_phpadmin(){
  4148. ${PURPLE} phpadmin $END
  4149. }
  4150. install_memcached(){
  4151. ${PURPLE} memcached $END
  4152. }
  4153. install_zabbix(){
  4154. while :;do
  4155. echo -e "\E[$[RANDOM%7+31];1m"
  4156. cat << EOF
  4157. ************************************************************
  4158. ************************************************************
  4159. ************************************************************
  4160. ********** **********
  4161. ********** 安装zabbix **********
  4162. ********** **********
  4163. ********** 1.返回上一目录 **********
  4164. ********** ================== **********
  4165. ********** zabbix6安装 zabbix6-agent2安装 **********
  4166. ********** **********
  4167. ********** 2.rocky8安装 8.rocky8安装 **********
  4168. ********** 3.ubuntu2204安装 9.ubuntu2204安装 **********
  4169. ********** 4.centos7安装 10.centos7安装 **********
  4170. ********** ================== **********
  4171. ********** zabbix5安装 zabbix5-agent2安装 **********
  4172. ********** **********
  4173. ********** 5.rocky8安装 11.rocky8安装 **********
  4174. ********** 6.ubuntu2204安装 12.ubuntu2204安装 **********
  4175. ********** 7.centos7安装 13.centos7安装 **********
  4176. ********** ================== **********
  4177. ********** 0.退出 **********
  4178. ********** **********
  4179. ************************************************************
  4180. ************************************************************
  4181. ************************************************************
  4182. EOF
  4183. echo -e "\E[0m"
  4184. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4185. case $Menu in
  4186. 1) break
  4187. ;;
  4188. 2) install_rocky8_zabbix6
  4189. ;;
  4190. 3) install_ubuntu2204_zabbix6
  4191. ;;
  4192. 4) install_centos7_zabbix6
  4193. ;;
  4194. 5) install_rocky8_zabbix5
  4195. ;;
  4196. 6) install_ubuntu2204_zabbix5
  4197. ;;
  4198. 7) install_centos7_zabbix5
  4199. ;;
  4200. 8) install_rocky8_zabbix6_agent2
  4201. ;;
  4202. 9) install_ubuntu2204_zabbix6_agent2
  4203. ;;
  4204. 10) install_centos7_zabbix6_agent2
  4205. ;;
  4206. 11) install_rocky8_zabbix5_agent2
  4207. ;;
  4208. 12) install_ubuntu2204_zabbix5_agent2
  4209. ;;
  4210. 13) install_centos7_zabbix5_agent2
  4211. ;;
  4212. 0) set_et
  4213. ;;
  4214. esac
  4215. done
  4216. }
  4217. install_keepalived(){
  4218. while :;do
  4219. echo -e "\E[$[RANDOM%7+31];1m"
  4220. cat << EOF
  4221. ************************************************************
  4222. ************************************************************
  4223. ************************************************************
  4224. ********** **********
  4225. ********** 安装keepalived **********
  4226. ********** **********
  4227. ********** 1.返回上一目录 **********
  4228. ********** **********
  4229. ********** 2.编译安装 **********
  4230. ********** **********
  4231. ********** 0.退出 **********
  4232. ********** **********
  4233. ************************************************************
  4234. ************************************************************
  4235. ************************************************************
  4236. EOF
  4237. echo -e "\E[0m"
  4238. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4239. case $Menu in
  4240. 1) break
  4241. ;;
  4242. 2) compile_install_keepalived
  4243. ;;
  4244. 0) set_et
  4245. ;;
  4246. esac
  4247. done
  4248. }
  4249. install_redis(){
  4250. while :;do
  4251. echo -e "\E[$[RANDOM%7+31];1m"
  4252. cat << EOF
  4253. ************************************************************
  4254. ************************************************************
  4255. ************************************************************
  4256. ********** **********
  4257. ********** 安装Redis **********
  4258. ********** **********
  4259. ********** 1.返回上一目录 **********
  4260. ********** **********
  4261. ********** 2.编译安装 **********
  4262. ********** **********
  4263. ********** 0.退出 **********
  4264. ********** **********
  4265. ************************************************************
  4266. ************************************************************
  4267. ************************************************************
  4268. EOF
  4269. echo -e "\E[0m"
  4270. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4271. case $Menu in
  4272. 1) break
  4273. ;;
  4274. 2) compile_install_redis
  4275. ;;
  4276. 0) set_et
  4277. ;;
  4278. esac
  4279. done
  4280. }
  4281. install_clickhouse(){
  4282. while :;do
  4283. echo -e "\E[$[RANDOM%7+31];1m"
  4284. cat << EOF
  4285. ========================================================
  4286. RedHat系列是直接yum下载安装
  4287. Debian系列是直接apt下载安装
  4288. 包安装是自动下载官网tgz包再安装
  4289. ========================================================
  4290. ************************************************************
  4291. ************************************************************
  4292. ************************************************************
  4293. ********** **********
  4294. ********** 安装clickhouse **********
  4295. ********** **********
  4296. ********** 1.返回上一目录 **********
  4297. ********** **********
  4298. ********** 2.RedHat系列 **********
  4299. ********** 3.Debian系列 **********
  4300. ********** 4.包安装 **********
  4301. ********** 5.源码编译 **********
  4302. ********** **********
  4303. ********** 0.退出 **********
  4304. ********** **********
  4305. ************************************************************
  4306. ************************************************************
  4307. ************************************************************
  4308. EOF
  4309. echo -e "\E[0m"
  4310. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4311. case $Menu in
  4312. 1) break
  4313. ;;
  4314. 2) redhat_install_clickhouse
  4315. ;;
  4316. 3) debian_install_clickhouse
  4317. ;;
  4318. 4) tgz_install_clickhouse
  4319. ;;
  4320. 5) compile_install_clickhouse
  4321. ;;
  4322. 0) set_et
  4323. ;;
  4324. esac
  4325. done
  4326. }
  4327. install_docker(){
  4328. while :;do
  4329. echo -e "\E[$[RANDOM%7+31];1m"
  4330. cat << EOF
  4331. ========================================================
  4332. CentOS7yum源安装,只不过选项3用起来有点问题
  4333. Ubuntu安装还没写
  4334. 安装podman还没写
  4335. 二进制安装可在线可离线
  4336. ========================================================
  4337. ************************************************************
  4338. ************************************************************
  4339. ************************************************************
  4340. ********** **********
  4341. ********** 安装docker **********
  4342. ********** **********
  4343. ********** 1.返回上一目录 **********
  4344. ********** **********
  4345. ********** 2.CentOS7yum源安装 **********
  4346. ********** 3.CentOS7yum源安装 **********
  4347. ********** 4.CentOS8yum源版本 **********
  4348. ********** 5.Ubuntu安装 **********
  4349. ********** 6.二进制安装 **********
  4350. ********** 7.安装podman **********
  4351. ********** **********
  4352. ********** 0.退出 **********
  4353. ********** **********
  4354. ************************************************************
  4355. ************************************************************
  4356. ************************************************************
  4357. EOF
  4358. echo -e "\E[0m"
  4359. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4360. case $Menu in
  4361. 1) break
  4362. ;;
  4363. 2) c7_yum_docker
  4364. ;;
  4365. 3) c7_yum2_docker
  4366. ;;
  4367. 4) c8_yum_docker
  4368. ;;
  4369. 5) ubuntu_docker
  4370. ;;
  4371. 6) offline_install_docker
  4372. ;;
  4373. 7) install_podman
  4374. ;;
  4375. 0) set_et
  4376. ;;
  4377. esac
  4378. done
  4379. }
  4380. reset_PS1(){
  4381. while :;do
  4382. echo -e "\E[$[RANDOM%7+31];1m"
  4383. cat << EOF
  4384. ************************************************************
  4385. ************************************************************
  4386. ************************************************************
  4387. ********** **********
  4388. ********** 修改主机名颜色 **********
  4389. ********** **********
  4390. ********** 1.返回上一目录 **********
  4391. ********** **********
  4392. ********** 2.Redhat7以上或Ubuntu **********
  4393. ********** 3.Redhat6 **********
  4394. ********** **********
  4395. ********** 0.退出 **********
  4396. ********** **********
  4397. ************************************************************
  4398. ************************************************************
  4399. ************************************************************
  4400. EOF
  4401. echo -e "\E[0m"
  4402. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4403. case $Menu in
  4404. 2) set_PS1
  4405. ;;
  4406. 3) set_c6_PS1
  4407. ;;
  4408. 1) break
  4409. ;;
  4410. 0) set_et
  4411. ;;
  4412. esac
  4413. done
  4414. }
  4415. set_net(){
  4416. while :;do
  4417. echo -e "\E[$[RANDOM%7+31];1m"
  4418. cat << EOF
  4419. ************************************************************
  4420. ************************************************************
  4421. ************************************************************
  4422. ********** **********
  4423. ********** 网卡配置 **********
  4424. ********** **********
  4425. ********** 1.返回上一目录 **********
  4426. ********** **********
  4427. ********** 2.配置Redhat7以上系列网卡文件 **********
  4428. ********** 3.配置Redhat6版本网卡文件 **********
  4429. ********** 4.配置Ubuntu网卡文件 **********
  4430. ********** ============================ **********
  4431. ********** 5.Redhat系列修改网卡名为eth0 **********
  4432. ********** 6.Ubuntu修改网卡名为eth0 **********
  4433. ********** **********
  4434. ********** 0.退出 **********
  4435. ********** **********
  4436. ************************************************************
  4437. ************************************************************
  4438. ************************************************************
  4439. EOF
  4440. echo -e "\E[0m"
  4441. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4442. case $Menu in
  4443. 2) configure_redhat_IP_address
  4444. ;;
  4445. 3) configure_redhat6_IP_address
  4446. ;;
  4447. 4) configure_ubuntu_IP_address
  4448. ;;
  4449. 5) set_redhat_netname
  4450. ;;
  4451. 6) set_ubuntu_netname
  4452. ;;
  4453. 1) break
  4454. ;;
  4455. 0) set_et
  4456. ;;
  4457. esac
  4458. done
  4459. }
  4460. ubuntu_source(){
  4461. while :;do
  4462. echo -e "\E[$[RANDOM%7+31];1m"
  4463. cat << EOF
  4464. ************************************************************
  4465. ************************************************************
  4466. ************************************************************
  4467. ********** **********
  4468. ********** ubuntu源配置 **********
  4469. ********** **********
  4470. ********** 1.返回上一目录 **********
  4471. ********** **********
  4472. ********** 2.阿里云源 **********
  4473. ********** 3.清华大学源 **********
  4474. ********** 4.中科大源 **********
  4475. ********** 5.ubuntu2004阿里源 **********
  4476. ********** 6.ubuntu1804阿里源 **********
  4477. ********** 7.ubuntu1604阿里源 **********
  4478. ********** **********
  4479. ********** 0.退出 **********
  4480. ********** **********
  4481. ************************************************************
  4482. ************************************************************
  4483. ************************************************************
  4484. EOF
  4485. echo -e "\E[0m"
  4486. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4487. case $Menu in
  4488. 2) ubuntu_aliyun_source
  4489. ;;
  4490. 3) ubuntu_tuna_source
  4491. ;;
  4492. 4) ubuntu_ustc_source
  4493. ;;
  4494. 5) ubuntu2004_aliyun_source
  4495. ;;
  4496. 6) ubuntu1804_aliyun_source
  4497. ;;
  4498. 7) ubuntu1604_aliyun_source
  4499. ;;
  4500. 1) break
  4501. ;;
  4502. 0) set_et
  4503. ;;
  4504. esac
  4505. done
  4506. }
  4507. set_yum(){
  4508. while :;do
  4509. echo -e "\E[$[RANDOM%7+31];1m"
  4510. cat << EOF
  4511. ============================================================
  4512. 选项7无挂载光盘,只有清华源
  4513. 选项8有挂载光盘,有清华,华为,阿里,腾讯源。建议用8
  4514. Rocky8.7建议用3选项
  4515. 2选项是没有挂载光盘
  4516. 3选项是附带挂载光盘
  4517. ============================================================
  4518. ************************************************************
  4519. ************************************************************
  4520. ************************************************************
  4521. ********** **********
  4522. ********** 配置yum源 **********
  4523. ********** **********
  4524. ********** 1.返回上一目录 **********
  4525. ********** **********
  4526. ********** 2.配置Rocky8 yum源 **********
  4527. ********** 3.配置Rocky8 yum源 **********
  4528. ********** 4.配置Rocky8 EPEL源 **********
  4529. ********** ======================= **********
  4530. ********** 5.配置centos7 阿里源 **********
  4531. ********** 6.配置centos7 EPEL源 **********
  4532. ********** 7.配置centos7.9 清华源 **********
  4533. ********** 8.配置centos7.9 清华源 **********
  4534. ********** ======================= **********
  4535. ********** 9.配置centos6.10 yum源 **********
  4536. ********** 10.配置centos6 EPEL源 **********
  4537. ********** 11.配置centos6.5 yum源 **********
  4538. ********** 12.配置centos6.6 yum源 **********
  4539. ********** ======================= **********
  4540. ********** 13.配置ubuntu apt源 **********
  4541. ********** **********
  4542. ********** 0.退出 **********
  4543. ********** **********
  4544. ************************************************************
  4545. ************************************************************
  4546. ************************************************************
  4547. EOF
  4548. echo -e "\E[0m"
  4549. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4550. case $Menu in
  4551. 2) set_yum2_rocky8
  4552. ;;
  4553. 3) set_yum_rocky8
  4554. ;;
  4555. 4) set_epel_rocky8
  4556. ;;
  4557. 5) set_yum_centos7
  4558. ;;
  4559. 6) set_epel_centos7
  4560. ;;
  4561. 7) set_yum1_centos7
  4562. ;;
  4563. 8) set_yum2_centos7
  4564. ;;
  4565. 9) set_yum_centos610
  4566. ;;
  4567. 10) set_epel_centos6
  4568. ;;
  4569. 11) set_yum_centos65
  4570. ;;
  4571. 12) set_yum_centos66
  4572. ;;
  4573. 13) ubuntu_source
  4574. ;;
  4575. 1) break
  4576. ;;
  4577. 0) set_et
  4578. ;;
  4579. esac
  4580. done
  4581. }
  4582. set_firewalld(){
  4583. while :;do
  4584. echo -e "\E[$[RANDOM%7+31];1m"
  4585. cat << EOF
  4586. ************************************************************
  4587. ************************************************************
  4588. ************************************************************
  4589. ********** **********
  4590. ********** 关闭防火墙 **********
  4591. ********** **********
  4592. ********** 1.返回上一目录 **********
  4593. ********** **********
  4594. ********** 2.Redhat7以上版本 **********
  4595. ********** 3.Redhat6版本 **********
  4596. ********** **********
  4597. ********** 0.退出 **********
  4598. ********** **********
  4599. ************************************************************
  4600. ************************************************************
  4601. ************************************************************
  4602. EOF
  4603. echo -e "\E[0m"
  4604. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4605. case $Menu in
  4606. 1) break
  4607. ;;
  4608. 2) disable_firewalld
  4609. ;;
  4610. 3) stop_centos6_firewalld
  4611. ;;
  4612. 0) set_et
  4613. ;;
  4614. esac
  4615. done
  4616. }
  4617. software(){
  4618. while :;do
  4619. echo -e "\E[$[RANDOM%7+31];1m"
  4620. cat << EOF
  4621. ========================================
  4622. Ubuntu和redhat安装的软件多少不一样
  4623. ========================================
  4624. ************************************************************
  4625. ************************************************************
  4626. ************************************************************
  4627. ********** **********
  4628. ********** 安装初始化软件 **********
  4629. ********** **********
  4630. ********** 1.返回上一目录 **********
  4631. ********** **********
  4632. ********** 2.Redhat7,8系列 **********
  4633. ********** 3.Redhat6系列 **********
  4634. ********** 4.Ubuntu系列 **********
  4635. ********** **********
  4636. ********** 0.退出 **********
  4637. ********** **********
  4638. ************************************************************
  4639. ************************************************************
  4640. ************************************************************
  4641. EOF
  4642. echo -e "\E[0m"
  4643. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4644. case $Menu in
  4645. 1) break
  4646. ;;
  4647. 2) c7_software
  4648. ;;
  4649. 3) c6_software
  4650. ;;
  4651. 4) Ubuntu_software
  4652. ;;
  4653. 0) set_et
  4654. ;;
  4655. esac
  4656. done
  4657. }
  4658. time1(){
  4659. clock -s
  4660. }
  4661. time2(){
  4662. clock -w
  4663. }
  4664. set_all(){
  4665. while :;do
  4666. echo -e "\E[$[RANDOM%7+31];1m"
  4667. cat << EOF
  4668. ************************************************************
  4669. ************************************************************
  4670. ************************************************************
  4671. ********** **********
  4672. ********** 系统设置 **********
  4673. ********** **********
  4674. ********** 1.返回上一目录 **********
  4675. ********** **********
  4676. ********** 2.关闭防火墙 3.关闭SELINUX **********
  4677. ********** 4.安装初始化软件 5.配置yum,apt源 **********
  4678. ********** ==================== **********
  4679. ********** 6.网卡配置 7.修改别名 **********
  4680. ********** 8.修改主机名颜色 9.修改主机名 **********
  4681. ********** ==================== **********
  4682. ********** 10.设置vim 11.设置时区 **********
  4683. ********** 12.设置登录显示 13.矫正软件时间 **********
  4684. ********** ==================== **********
  4685. ********** 14.矫正硬件时间 15.垃圾桶 **********
  4686. ********** 16.设置邮箱 17.优化ulimit **********
  4687. ********** ==================== **********
  4688. ********** 18.禁用swap 19.启用swap **********
  4689. ********** 20.修改ssh端口号 21.ubuntu远程登录**********
  4690. ********** **********
  4691. ********** 0.退出 **********
  4692. ************************************************************
  4693. ************************************************************
  4694. ************************************************************
  4695. EOF
  4696. echo -e "\E[0m"
  4697. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4698. case $Menu in
  4699. 2) set_firewalld
  4700. ;;
  4701. 3) disable_selinux
  4702. ;;
  4703. 4) software
  4704. ;;
  4705. 5) set_yum
  4706. ;;
  4707. 6) set_net
  4708. ;;
  4709. 7) set_alias
  4710. ;;
  4711. 8) reset_PS1
  4712. ;;
  4713. 9) set_hostname
  4714. ;;
  4715. 10) set_vim
  4716. ;;
  4717. 11) set_timezone
  4718. ;;
  4719. 12) set_motd1
  4720. ;;
  4721. 13) time1
  4722. ;;
  4723. 14) time2
  4724. ;;
  4725. 15) set_rm
  4726. ;;
  4727. 16) set_mail
  4728. ;;
  4729. 17) set_ulimit
  4730. ;;
  4731. 18) stop_swap
  4732. ;;
  4733. 19) start_swap
  4734. ;;
  4735. 20) set_ssh
  4736. ;;
  4737. 21) ubuntu_root_login
  4738. ;;
  4739. 1) break
  4740. ;;
  4741. 0) set_et
  4742. ;;
  4743. esac
  4744. done
  4745. }
  4746. rpm_install_mysql(){
  4747. while :;do
  4748. echo -e "\E[$[RANDOM%7+31];1m"
  4749. cat << EOF
  4750. ************************************************************
  4751. ************************************************************
  4752. ************************************************************
  4753. ********** **********
  4754. ********** 安装MySQL社区版 **********
  4755. ********** **********
  4756. ********** 1.返回上一目录 **********
  4757. ********** **********
  4758. ********** 2.MySQL5.7 **********
  4759. ********** 3.MySQL8.0 **********
  4760. ********** **********
  4761. ********** 0.退出 **********
  4762. ********** **********
  4763. ************************************************************
  4764. ************************************************************
  4765. ************************************************************
  4766. EOF
  4767. echo -e "\E[0m"
  4768. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4769. case $Menu in
  4770. 1) break
  4771. ;;
  4772. 2) rpm_install_mysql57
  4773. ;;
  4774. 3) rpm_install_mysql8
  4775. ;;
  4776. 0) set_et
  4777. ;;
  4778. esac
  4779. done
  4780. }
  4781. install_Database(){
  4782. while :;do
  4783. echo -e "\E[$[RANDOM%7+31];1m"
  4784. cat << EOF
  4785. ************************************************************
  4786. ************************************************************
  4787. ************************************************************
  4788. ********** **********
  4789. ********** 安装数据库 **********
  4790. ********** **********
  4791. ********** 1.返回上一目录 **********
  4792. ********** **********
  4793. ********** 2.二进制安装MySQL **********
  4794. ********** 3.yum源安装MySQL **********
  4795. ********** 4.二进制安装MariaDB **********
  4796. ********** 5.yum源安装MariaDB **********
  4797. ********** **********
  4798. ********** 0.退出 **********
  4799. ********** **********
  4800. ************************************************************
  4801. ************************************************************
  4802. ************************************************************
  4803. EOF
  4804. echo -e "\E[0m"
  4805. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4806. case $Menu in
  4807. 1) break
  4808. ;;
  4809. 2) install_mysql
  4810. ;;
  4811. 3) rpm_install_mysql
  4812. ;;
  4813. 4) install_mariadb
  4814. ;;
  4815. 5) yum_mariadb
  4816. ;;
  4817. 0) set_et
  4818. ;;
  4819. esac
  4820. done
  4821. }
  4822. install_NGINX(){
  4823. while :;do
  4824. echo -e "\E[$[RANDOM%7+31];1m"
  4825. cat << EOF
  4826. ************************************************************
  4827. ************************************************************
  4828. ************************************************************
  4829. ********** **********
  4830. ********** 安装NGINX **********
  4831. ********** **********
  4832. ********** 1.返回上一目录 **********
  4833. ********** **********
  4834. ********** 2.编译安装Nginx **********
  4835. ********** 3.升级Nginx **********
  4836. ********** 4.升级srun-Nginx **********
  4837. ********** 5.升级旧版本srun-Nginx **********
  4838. ********** **********
  4839. ********** 0.退出 **********
  4840. ********** **********
  4841. ************************************************************
  4842. ************************************************************
  4843. ************************************************************
  4844. EOF
  4845. echo -e "\E[0m"
  4846. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4847. case $Menu in
  4848. 1) break
  4849. ;;
  4850. 2) install_nginx1
  4851. ;;
  4852. 3) update_nginx
  4853. ;;
  4854. 4) update_srunnginx
  4855. ;;
  4856. 5) update_srunnginx2
  4857. ;;
  4858. 0) set_et
  4859. ;;
  4860. esac
  4861. done
  4862. }
  4863. install_SSHSSL(){
  4864. while :;do
  4865. echo -e "\E[$[RANDOM%7+31];1m"
  4866. cat << EOF
  4867. ========================================
  4868. 升级openssh openssl在centos7.9测试正常
  4869. ========================================
  4870. ************************************************************
  4871. ************************************************************
  4872. ************************************************************
  4873. ********** **********
  4874. ********** 升级安装openssl,openssh **********
  4875. ********** **********
  4876. ********** 1.返回上一目录 **********
  4877. ********** **********
  4878. ********** 2.升级安装openssl **********
  4879. ********** 3.升级安装openssh **********
  4880. ********** 4.同时升级openssl,openssh **********
  4881. ********** **********
  4882. ********** 0.退出 **********
  4883. ********** **********
  4884. ************************************************************
  4885. ************************************************************
  4886. ************************************************************
  4887. EOF
  4888. echo -e "\E[0m"
  4889. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4890. case $Menu in
  4891. 1) break
  4892. ;;
  4893. 2) update_openssl
  4894. ;;
  4895. 3) update_openssh
  4896. ;;
  4897. 4) update_sshssl
  4898. ;;
  4899. 0) set_et
  4900. ;;
  4901. esac
  4902. done
  4903. }
  4904. install_service(){
  4905. while :;do
  4906. echo -e "\E[$[RANDOM%7+31];1m"
  4907. cat << EOF
  4908. ************************************************************
  4909. ************************************************************
  4910. ************************************************************
  4911. ************************************************************
  4912. ********** **********
  4913. ********** 安装服务 **********
  4914. ********** **********
  4915. ********** 1.返回上一目录 **********
  4916. ********** **********
  4917. ********** 2.安装Database **********
  4918. ********** 3.安装Nginx **********
  4919. ********** 4.升级安装openssl,openssh **********
  4920. ********** 5.安装docker **********
  4921. ********** 6.安装clickhouse **********
  4922. ********** 7.安装Redis **********
  4923. ********** 8.安装keepalived **********
  4924. ********** 9.安装jumpserver **********
  4925. ********** 10.安装zabbix **********
  4926. ********** 11.安装DNS **********
  4927. ********** 12.安装kubernetes **********
  4928. ********** **********
  4929. ********** 0.退出 **********
  4930. ********** **********
  4931. ************************************************************
  4932. ************************************************************
  4933. ************************************************************
  4934. EOF
  4935. echo -e "\E[0m"
  4936. read -p "$(echo -e '\e[1;36m请输入序号: \e[0m')" Menu
  4937. case $Menu in
  4938. 2) install_Database
  4939. ;;
  4940. 3) install_NGINX
  4941. ;;
  4942. 4) install_SSHSSL
  4943. ;;
  4944. 5) install_docker
  4945. ;;
  4946. 6) install_clickhouse
  4947. ;;
  4948. 7) install_redis
  4949. ;;
  4950. 8) install_keepalived
  4951. ;;
  4952. 9) install_jumpserver
  4953. ;;
  4954. 10) install_zabbix
  4955. ;;
  4956. 11) install_dns
  4957. ;;
  4958. 12) install_kubernetes
  4959. ;;
  4960. 39) install_haproxy
  4961. ;;
  4962. 40) install_jenkins
  4963. ;;
  4964. 41) install_halo
  4965. ;;
  4966. 42) install_lua
  4967. ;;
  4968. 43) install_gitlab
  4969. ;;
  4970. 44) install_git
  4971. ;;
  4972. 45) install_wordpress
  4973. ;;
  4974. 46) install_apache
  4975. ;;
  4976. 47) install_jdk
  4977. ;;
  4978. 48) install_php
  4979. ;;
  4980. 49) install_phpadmin
  4981. ;;
  4982. 50) install_memcached
  4983. ;;
  4984. 1) break
  4985. ;;
  4986. 0) set_et
  4987. ;;
  4988. esac
  4989. done
  4990. }
  4991. update_log(){
  4992. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  4993. echo "2023-5-26 version:csh"
  4994. echo "新增zabbix,dns"
  4995. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  4996. echo "2023-2-17 version:csh"
  4997. echo "新增keepalived"
  4998. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  4999. echo "2023-2-15 version:csh"
  5000. echo "新增redis"
  5001. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5002. echo "2023-2-3 version:csh"
  5003. echo "新增clickhouse"
  5004. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5005. echo "2023-2-2 version:csh"
  5006. echo "新增docker"
  5007. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5008. echo "2023-1-27 version:csh"
  5009. echo "升级nginx,升级openssl"
  5010. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5011. echo "2022-12-27 version:csh-v1.0"
  5012. echo "改进网卡配置流程"
  5013. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5014. echo "2022-12-07 version:csh-v9.7.7.06"
  5015. echo "添加编译升级安装openssh,openssl"
  5016. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5017. echo "2022-11-28 version:csh-v9.7.7.04"
  5018. echo "完善一些功能"
  5019. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5020. echo "2022-11-27 version:csh-v9.7.7.02"
  5021. echo "添加mariadb,yum安装,二进制安装"
  5022. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5023. echo "2022-11-26 version:csh-v9.7.7.01"
  5024. echo "修改centos7yum源,"
  5025. echo -e "\e[1;$[RANDOM%7+31]m=================================================================================================== \e[0m"
  5026. }
  5027. re(){
  5028. init 6
  5029. }
  5030. shut(){
  5031. init 0
  5032. #shutdown -r now
  5033. }
  5034. set_reset(){
  5035. echo -e "\e[1;35m====================================================================================================================================\e[0m"
  5036. echo -e "\e[1;35m一键初始化\e[0m"
  5037. echo -e "\e[1;35m支持openEuler2203,centos7.9,rocky8.5,kylinV10\e[0m"
  5038. echo -e "\e[1;35m初始化内容:更新yum源,安装软件,关闭防火墙,关闭selinux,优化limits,添加别名\e[0m"
  5039. echo -e "\e[1;35m====================================================================================================================================\e[0m"
  5040. echo -e "\n\e[1;35m============================================================1.更新yum源============================================================\e[0m"
  5041. yum clean all
  5042. yum makecache
  5043. echo -e "\n\e[1;35m============================================================2.安装软件=============================================================\e[0m"
  5044. if [ $ID = 'rocky' -o $ID = 'centos' ];then
  5045. software=("lrzsz"
  5046. "vim"
  5047. "tree"
  5048. "wget"
  5049. "tcpdump"
  5050. "psmisc"
  5051. "rsync"
  5052. "mlocate"
  5053. "bzip2"
  5054. "zip"
  5055. "unzip"
  5056. "lsof"
  5057. "telnet"
  5058. "libpcap"
  5059. "tar"
  5060. "libtalloc"
  5061. "net-tools"
  5062. "httpd-tools"
  5063. "bash-completion"
  5064. )
  5065. for i in ${software[@]}
  5066. do
  5067. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  5068. done
  5069. else
  5070. software=("lrzsz"
  5071. "vim"
  5072. "tree"
  5073. "wget"
  5074. "tcpdump"
  5075. "psmisc"
  5076. "rsync"
  5077. "mlocate"
  5078. "bzip2"
  5079. "zip"
  5080. "unzip"
  5081. "lsof"
  5082. "telnet"
  5083. "libpcap"
  5084. "tar"
  5085. "libtalloc"
  5086. "net-tools"
  5087. "httpd-tools"
  5088. "bash-completion"
  5089. "libpcap-devel"
  5090. "libtalloc-devel"
  5091. "bridge-utils.x86_64"
  5092. )
  5093. for i in ${software[@]}
  5094. do
  5095. rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
  5096. done
  5097. fi
  5098. #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
  5099. sleep 2
  5100. echo -e "\n\e[1;35m=============================================================3.关闭防火墙=============================================================\e[0m"
  5101. systemctl disable --now firewalld
  5102. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5103. sleep 2
  5104. echo -e "\n\e[1;35m=============================================================4.添加别名===============================================================\e[0m"
  5105. echo -e "\n\e[1;35m添加的别名有:cdnet='cd /etc/sysconfig/network-scripts/',vi='vim'\e[0m"
  5106. cat >>~/.bashrc <<EOF
  5107. alias cdnet='cd /etc/sysconfig/network-scripts/'
  5108. alias vi='vim'
  5109. EOF
  5110. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5111. sleep 2
  5112. echo -e "\n\e[1;35m=============================================================5.关闭selinux=============================================================\e[0m"
  5113. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  5114. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5115. sleep 2
  5116. echo -e "\n\e[1;35m=============================================================6.优化limits==============================================================\e[0m"
  5117. cat >> /etc/security/limits.conf << EOF
  5118. * soft nofile 65535
  5119. * hard nofile 65535
  5120. * soft noproc 65535
  5121. * hard noproc 65535
  5122. EOF
  5123. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5124. sleep 2
  5125. echo -e "\n\e[1;35m=============================================================7.主机名颜色=============================================================\e[0m"
  5126. #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
  5127. #[ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5128. if [ $ID = 'centos' -o $ID = 'rocky' ];then
  5129. 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
  5130. #echo "PS1='\[\e[1;36m\][\[\e[34m\]\u\[\e[35m\]@\[\e[32m\]\h\[\e[31m\]\W\[\e[36m\]]\\$\[\e[0m\]'" >> /etc/bashrc
  5131. #color "修改成功 " 0
  5132. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5133. else
  5134. 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
  5135. #echo "PS1='\[\e[1;35m\][\[\e[35m\]\u\[\e[35m\]@\[\e[35m\]\h \[\e[36m\]\W\[\e[35m\]]\\$\[\e[0m\]'" >> ~/.bashrc
  5136. #color "修改成功 " 0
  5137. [ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
  5138. fi
  5139. sed -i "/HISTSIZE=/c\HISTSIZE=10000" /etc/profile
  5140. echo export HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \" >> /etc/profile
  5141. #echo HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \" >> /etc/profile
  5142. source /etc/profile
  5143. #CPU=`grep -c processor /proc/cpuinfo`
  5144. echo -e "\n\e[1;35m=============================================================8.硬件配置信息=============================================================\e[0m"
  5145. local INFO=`cat /proc/cpuinfo | grep name | cut -d: -f2 |uniq -c | tr -s ' '`
  5146. local MEM=`free -h | head -n2 |tail -n1 | awk '{print $2}'`
  5147. local DISK=`lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4`
  5148. local SYSTEM=`uname -m`
  5149. local CPUCORES=`cat /proc/cpuinfo |grep 'cpu cores' | uniq`
  5150. local CPUNUMS=`grep 'physical id' /proc/cpuinfo | sort -u | wc -l`
  5151. echo -e "\n\e[1;35m逻辑cpu个数 cpu型号 系统架构:$INFO $SYSTEM\e[0m"
  5152. echo -e "\n\e[1;35mCPU核数:$CPUCORES\e[0m"
  5153. echo -e "\n\e[1;35m物理CPU个数:$CPUNUMS\e[0m"
  5154. echo -e "\n\e[1;35m内存总大小:$MEM\e[0m"
  5155. echo -e "\n\e[1;35m硬盘总大小:$DISK\e[0m"
  5156. sleep 2
  5157. echo -e "\n\e[1;35m===============================================================9.重启系统==============================================================\e[0m"
  5158. echo -e "\n\e[1;35m五秒后重启系统\e[0m"
  5159. for i in {5..1}
  5160. do
  5161. echo -n "${i} "
  5162. echo -ne "\r"
  5163. sleep 1
  5164. done
  5165. init 6
  5166. }
  5167. one_step(){
  5168. while :;do
  5169. echo -e "\n\e[1;$[RANDOM%7+31]m ^_^~~~^_^centos7一键初始化 ^_^~~~^_^\e[0m"
  5170. echo -e "\n\e[1;$[RANDOM%7+31]m1.关闭防火墙\e[0m"
  5171. echo -e "\n\e[1;$[RANDOM%7+31]m2.selinux\e[0m"
  5172. echo -e "\n\e[1;$[RANDOM%7+31]m3.优化limit\e[0m"
  5173. echo -e "\n\e[1;$[RANDOM%7+31]m4.修改centos7-yum源\e[0m"
  5174. echo -e "\n\e[1;$[RANDOM%7+31]m5.软件安装\e[0m"
  5175. echo -e "\n\e[1;$[RANDOM%7+31]m6.添加vim开头显示\e[0m"
  5176. echo -e "\n\e[1;$[RANDOM%7+31]m7.修改登录显示\e[0m"
  5177. echo -e "\n\e[1;$[RANDOM%7+31]m8.修改网卡名\e[0m"
  5178. echo -e "\n\e[1;$[RANDOM%7+31]m9.添加别名\e[0m"
  5179. echo -e "\n\e[1;$[RANDOM%7+31]m10.修改主机名颜色\e[0m"
  5180. echo -e "\n\e[1;$[RANDOM%7+31]m11.网卡配置\e[0m"
  5181. echo -e "\n\e[1;$[RANDOM%7+31]m0.退出\e[0m\n"
  5182. read -p "$(echo -e '\e[1;35m输入序号: \e[0m')" OOOO
  5183. case $OOOO in
  5184. 1) disable_firewalld
  5185. ;;
  5186. 2) disable_selinux
  5187. ;;
  5188. 3) set_ulimit
  5189. ;;
  5190. 4) set_yum2_centos7
  5191. ;;
  5192. 5) c7_software
  5193. ;;
  5194. 6) set_vim
  5195. ;;
  5196. 7) set_motd
  5197. ;;
  5198. 8) set_redhat_netname
  5199. ;;
  5200. 9) set_alias
  5201. ;;
  5202. 10) set_PS1
  5203. ;;
  5204. 11) configure_redhat_IP_address
  5205. ;;
  5206. 0) set_et
  5207. ;;
  5208. esac
  5209. done
  5210. }
  5211. while :;do
  5212. echo -e "\E[$[RANDOM%7+31];1m"
  5213. cat << EOF
  5214. ============================================================
  5215. 3.一键初始化,
  5216. 支持openEuler2203,centos7,rocky8,kylinV10
  5217. 初始化内容:更新yum源,安装软件,关闭防火墙,
  5218. 关闭selinux,优化limits,添加别名
  5219. 4.centos7配置初始化 有点问题,
  5220. ============================================================
  5221. ************************************************************
  5222. ************************************************************
  5223. ************************************************************
  5224. ********** **********
  5225. ********** Linux运维脚本 **********
  5226. ********** **********
  5227. ********** 1.系统设置 **********
  5228. ********** 2.安装服务 **********
  5229. ********** 3.一键初始化 **********
  5230. ********** 4.centos7配置初始化 **********
  5231. ********** 5.更新日志 **********
  5232. ********** 6.系统信息 **********
  5233. ********** 7.重启 **********
  5234. ********** 8.关机 **********
  5235. ********** **********
  5236. ********** 0.退出 **********
  5237. ********** **********
  5238. ************************************************************
  5239. ************************************************************
  5240. ************************************************************
  5241. EOF
  5242. echo -e "\E[0m"
  5243. read -p "$(echo -e '\e[1;34m输入选项: \e[0m')" option
  5244. case $option in
  5245. 1)
  5246. set_all
  5247. ;;
  5248. 2) install_service
  5249. ;;
  5250. 3) set_reset
  5251. ;;
  5252. 4) one_step
  5253. ;;
  5254. 5) update_log
  5255. ;;
  5256. 6) systeminfo
  5257. ;;
  5258. 7) re
  5259. ;;
  5260. 8) shut
  5261. ;;
  5262. 0) set_et
  5263. ;;
  5264. esac
  5265. done

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/261913
推荐阅读
相关标签
  

闽ICP备14008679号