编写脚本自动部署反向代理、web、nfs

服务器端

#!/bin/bash

function nginx_install(){
	if [[ -f /usr/sbin/nginx ]]; then
		echo ‘Nginx has been installed.‘
		exit
	else
		flag1=3
		while [[ $flag1 -gt 0 ]]; do
			yum install epel-release -y && yum install nginx -y
			if [[ $? -ne 0 ]]; then
				((flag1--))
			else
				echo ‘Nginx has been installed.‘
				exit
			fi
		done
		echo ‘Nginx install failed.‘
	fi
	systemctl start nginx
}

function nginx_balancer(){
	msg1=‘upstream myapp1 { server 192.168.60.129; server 192.168.60.130; server 192.168.60.131; }‘
	msg2=‘proxy_pass http://myapp1;‘
	sed -ri "/^http/a $msg1" /etc/nginx/nginx.conf
	sed -ri "/^ *location \/ \{$/a $msg2" /etc/nginx/nginx.conf
	systemctl reload nginx
}

function nfs_install(){
	rpm -qa |grep rpcbind >> /dev/null
	if [[ $? -eq 0 ]]; then
		echo ‘RPCbind has been installed‘
	else
		flag2=3
		while [[ $flag2 -gt 0 ]]; do
			yum install rpcbind -y
			if [[ $? -ne 0 ]]; then
				((flag2--))
			else
				echo ‘RPCbind has been installed.‘
				exit
			fi
		done
		echo ‘RPCbind install failed.‘
	fi
	rpm -qa |grep nfs-utils >> /dev/null
	if [[ $? -eq 0 ]]; then
		echo ‘nfs-utils has been installed‘
	else
		flag3=3
		while [[ $flag3 -gt 0 ]]; do
			yum install nfs-utils -y
			if [[ $? -ne 0 ]]; then
				((flag3--))
			else
				echo ‘nfs-utils has been installed.‘
				exit
			fi
		done
		echo ‘nfs-utils install failed.‘
	fi
}

function nfs_server(){
	mkdir /share
	touch /share/index.html
	echo ‘---NFS---Hello---‘ > /share/index.html
	chmod -R o+w /share
	echo ‘/share 192.168.60.0/24(rw,sync,fsid=0)‘ >> /etc/exports
	systemctl start rpcbind.service && systemctl start nfs-server.service
	if [[ $? -eq 0 ]]; then
		echo ‘NFS server running.‘
	fi
	systemctl enable rpcbind.service && systemctl enable nfs-server.service
}

nginx_install
nginx_balancer
nfs_install
nfs_server

  

客户端

#!/bin/bash

function nginx_install(){
	if [[ -f /usr/sbin/nginx ]]; then
		echo ‘Nginx has been installed.‘
		exit
	else
		flag1=3
		while [[ $flag1 -gt 0 ]]; do
			yum install epel-release -y && yum install nginx -y
			if [[ $? -ne 0 ]]; then
				((flag1--))
			else
				echo ‘Nginx has been installed.‘
				exit
			fi
		done
		echo ‘Nginx install failed.‘
	fi
	systemctl start nginx
}

function nfs_install(){
	rpm -qa |grep rpcbind >> /dev/null
	if [[ $? -eq 0 ]]; then
		echo ‘RPCbind has been installed‘
	else
		flag2=3
		while [[ $flag2 -gt 0 ]]; do
			yum install rpcbind -y
			if [[ $? -ne 0 ]]; then
				((flag2--))
			else
				echo ‘RPCbind has been installed.‘
				exit
			fi
		done
		echo ‘RPCbind install failed.‘
	fi
	rpm -qa |grep nfs-utils >> /dev/null
	if [[ $? -eq 0 ]]; then
		echo ‘nfs-utils has been installed‘
	else
		flag3=3
		while [[ $flag3 -gt 0 ]]; do
			yum install nfs-utils -y
			if [[ $? -ne 0 ]]; then
				((flag3--))
			else
				echo ‘nfs-utils has been installed.‘
				exit
			fi
		done
		echo ‘nfs-utils install failed.‘
	fi
}

function nfs_client(){
	systemctl start rpcbind.service && systemctl start nfs-server.service
	systemctl enable rpcbind.service && systemctl enable nfs-server.service
	mount -t nfs 192.168.60.128:/share /usr/share/nginx/html/
	df |grep 192.168.60.128 >> /dev/null
	if [[ $? -eq 0 ]]; then
		echo ‘NFS client running.‘
	fi
}

nginx_install
nfs_install
nfs_client

  

时间: 2024-10-10 05:33:02

编写脚本自动部署反向代理、web、nfs的相关文章

Shell脚本-自动化部署反向代理、WEB、nfs

部署nginx反向代理三个web服务,调度算法使用加权轮询(由于物理原因只开启两台服务器) AutoNginxNfsService.sh #/bin/bash systemctl status nginx if(($?==4)) then yum install -y nginx if(($?==0)) then #echo 'Yes!' systemctl start nginx if(($?==0)) then echo "Congratulations!! Nginx start OK!!

十五.编写自动脚本部署web,反向代理,nfs服务

一.自动部署web,反向代理,加权轮询: 1.编写脚本自动部署反向代理,web,nfs. #!/bin/bash #author/dengsiyuan function nginx_check()  #配置nginx { ngx_status= 'ps aux|grep -v grep|grep -c nginx' #取运行nginx进程的进程数 if [ -f /etc/nginx/nginx.conf ];then   #判断是否存在正规文件nginx.conf以判断nginx是否安装 ec

Day11.开发脚本自动部署及监控

1.编写脚本自动部署反向代理.web.nfs:要求:I.部署nginx反向代理三个web服务,调度算法使用加权轮询: II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: 2.编写监控脚本,监控nginx,nfs存活状态,内存使用率检测,异常则发送报警邮件 准备发送邮件的工具: 监控脚本的编写: 继续编写刚才的脚本编写,加入邮件功能 3.编写计划任务,定时运行监控脚本,完成监控操作

开发脚本自动部署及监控

1.编写脚本自动部署反向代理.web.nfs: #!/bin/bash yum install epel-release -y yum install nginx -y ps aux |grep nginx |grep -v 'grep' if [ $? -ne 0 ] then systemctl start nginx fi sed -ri '/^http/a upstream xzhweb\{' /etc/nginx/nginx.conf sed -ri '/^upstream/a ser

linux开发脚本自动部署及监控

开发脚本自动部署及监控 1.编写脚本自动部署反向代理.web.nfs: 要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: #!/bin/sh ngxStatus=`ps aux | grep -v grep |grep -c nginx` function ngxProxyInstall() { if [ -e /usr/sbin/nginx ];then echo "nginx already installed" exit 110 else yum inst

开发脚本自动部署及监控作业

1.编写脚本自动部署反向代理.web.nfs: 要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: II.所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性: 2.编写监控脚本,监控集群内所有服务存活状态,内存.磁盘剩余率检测,异常则发送报警邮件 3.编写计划任务,定时运行监控脚本,完成监控操作

脚本自动部署构架集群和监控状态

脚本自动部署构架集群和监控状态 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

Shell脚本自动部署(编译)LAMP平台

Shell脚本自动部署(编译)LAMP平台 LAMP是当下非常流行的一套Web架构,我们可以在GNU/Linux下通过其他人打包的程序包来进行安装; 但是在生产环境中,很多时候都需要我们自己定制安装AMP,编译安装LAMP有以下几个优点 根据生产环境灵活定制程序 优化编译参数,提高性能 解决不必要的软件依赖 友情提示:对编译安装有疑问的朋友, 查看我以前写的博客:教你使用rpm.yum.编译等方式安装软件 点击此处获得更好的阅读体验 为什么要用脚本进行部署? 在很多情况下部署LAMP平台并不止一

shell脚本:nginx反向代理节点状态检查

lvs可以使用ipvsam -Ln 查看RS节点的情况,当RS宕机后剔除,当RS恢复后自动加入,nginx上面无法查看,需要安装插件或自己写脚本实现: 反向代理的配置如下:(server 去掉前面的空格,为了方便后面脚本使用sed做文本替换:) [[email protected] vhosts]# cat upstream01.conf upstream backend { server 192.168.20.10:80 weight=5; server 192.168.20.11:80 we