下面为shell脚本编写的nginx的安装及修改nginx.conf的脚本,脚本比较简单:
#!/bin/bash
function yum_install(){
yum install epel-release -y
yum install nginx -y
}
yum_install
pw=/etc/nginx/nginx.conf
read -p "请输入组名:" zu
read -p "请输入第一个ip地址:" ip1
read -p "请输入第二个ip地址:" ip2
read -p "请输入第三个ip地址:" ip3
msg="upstream $zu { server $ip1;server $ip2;server $ip3}"
sed -ri "/^http/a $msg" $pw #增加upstream
processor=`cat /proc/cpuinfo | grep "processor" | wc -l` #获取cpu核数
sed -i "s/^w.*;$/worker_processes ${processor};/g" /etc/nginx/nginx.conf #将nginx.conf中的worker_processes值修改为cpu的核数
service nginx start