编写脚本自动部署反向代理webnfs

Posted 云中王

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编写脚本自动部署反向代理webnfs相关的知识,希望对你有一定的参考价值。

服务器端

#!/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

  

以上是关于编写脚本自动部署反向代理webnfs的主要内容,如果未能解决你的问题,请参考以下文章

linux基础 作业篇

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

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

开发脚本自动部署及监控

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

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