您的位置:首页 > 运维架构 > Nginx

ansible安装nginx脚本

2020-07-23 00:54 281 查看

要求:ansible结合shell自动部署nginx

[root@master ~]# cat auto_install_nginx.sh
#!/bin/bash

NGINX_P="/opt/nginx/"
NGINX_T="/usr/local/nginx/"

function nginx_evn(){
yum install gcc gcc-c++  pcre pcre-devel  zlib zlib-devel  mysql-devel curl-devle wget openssl openssl-devel -y

rm -rf ${NGINX_P}
mkdir -p ${NGINX_P}
wget -O ${NGINX_P}nginx-1.14.2.tar.gz http://nginx.org/download/nginx-1.14.2.tar.gz
sed -i '7s/enforcing/disabled/g' /etc/selinux/config
timedatectl set-timezone Asia/Shanghai >/dev/null
systemctl stop firewalld.service >/dev/null
systemctl disable firewalld.service >/dev/null
chmod 755 -R ${NGINX_P}
}

function install_nginx(){
rm -rf ${NGINX_T} >/dev/null
mkdir -p  ${NGINX_T}
tar -zxvf ${NGINX_P}`ls ${NGINX_P}|grep nginx` -C ${NGINX_T}
cd ${NGINX_T}`ls ${NGINX_T}`
./configure \
--prefix=${NGINX_T} \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module
declare -i n=`cat /proc/cpuinfo| grep "physical id"|sort|wc -l`
make -j ${n}
make install
}

function startup(){
cd ${NGINX_T}
cd sbin
./nginx -t
./nginx
echo "NGINX首页访问"
curl localhost
}

function auto_install(){
NUM="`ps -ef|grep "nginx"|grep -v grep|grep -v ${0}|wc -l`" #特别注意grep -v ${0}将脚本过滤,不然脚本名称包含NGINX会被统计进来
if [ $NUM -gt 0 ]; then
echo "nginx existed and seccessful to start"
exit
else
nginx_evn
install_nginx
startup
fi
}

function main(){
case $1 in
start)
auto_install
;;
*)
echo "Usage:$0 [start]"

esac
}

main $1
[root@master ~]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: