脚本自动部署构架集群和监控状态
shell脚本编写
自动部署、初始配置、并启动nginx反向代理服务
1 #!/bin/bash 2 systemctl disable firewalld 3 systemctl stop firewalld 4 setenforce 0 5 #### 6 yum install epel-release -y 7 yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 8 yum install nginx -y 9 echo ‘nginx 服务已经安装好‘ 10 #### 11 systemctl start nginx 12 read -p "please input the ip of the proxy:" proxy 13 echo "$proxy proxy" >> /etc/hosts 14 read -p "please input the ip of the web1:" web1 15 echo "$web1 web1" >> /etc/hosts 16 read -p "please input the ip of the web2:" web2 17 echo "$web2 web2" >> /etc/hosts 18 #### 19 sed -i -r ‘/http( )(\{)/a\upstream ruan {\nserver web1:80;\nserver web2:80;\n}‘ /etc/nginx/nginx.conf 20 sed -i -r ‘/(^ +)location( )(\/)/a\ proxy_pass http://ruan;‘ /etc/nginx/nginx.conf 21 22 echo "nginx配置完成" 23 systemctl restart nginx 24 echo ‘nginx 已经运行‘ 25 #### 26 yum install rpcbind nfs-utils -y 27 echo "nfs安装完成" 28 #### 29 if [ ! -d /share ];then 30 mkdir -p /share 31 chmod -R o+w /share 32 fi 33 #### 34 echo ‘/share 192.168.16.0/24(rw,sync,fsid=0)‘ > /etc/exports 35 systemctl enable rpcbind.service 36 systemctl enable nfs-server.service 37 systemctl start rpcbind.service 38 systemctl start nfs-server.service 39 echo "nfs已经启动" 40 ~
自动部署、初始配置、并启动三台web
1 #!/bin/bash 2 systemctl disable firewalld 3 systemctl stop firewalld 4 setenforce 0 5 #### 6 yum install epel-release -y 7 yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 8 yum install nginx -y 9 echo ‘nginx 服务已经安装好‘ 10 #### 11 systemctl start nginx 12 #read -p "please input the ip of the web1:" web1 13 #echo "$web1 web1" >> /etc/hosts 14 read -p "please input the ip of the proxy:" proxy 15 echo "$proxy proxy" >> /etc/hosts 16 #### 17 #sed -i -r ‘/http( )(\{)/a\upstream ruan {\nserver web1:80;\nserver web2:80;\n}‘ /etc/nginx/nginx.conf 18 sed -i -r ‘/(^ +)location( )(\/)/a\ root /var/www/html;\nindex index.html;‘ /etc/nginx/nginx.conf 19 mkdir -p /var/www/html 20 echo `hostname` > /var/www/html/index.html 21 echo "nginx配置完成" 22 systemctl restart nginx 23 echo ‘nginx 已经运行‘ 24 #### 25 yum install rpcbind nfs-utils -y 26 echo "nfs服务安装完成" 27 #### 28 systemctl enable rpcbind.service 29 systemctl enable nfs-server.service 30 systemctl start rpcbind.service 31 systemctl start nfs-server.service 32 mount -t nfs $proxy:/share /var/www/html/ 33 echo "welcome" > /var/www/html/index.html
编写监控脚本,监控集群中nginx、nfs以及机器运行状况。异常则发送报警邮件
时间: 2024-10-05 23:15:10