centos7 下载nginx源码包的代码,有些地方可能会停下,重跑一次有可能解决问题
下文中的ip需要改成自己的。
#!/bin/bash
if test -e /etc/yum.repos.d/base.repo
then
echo "base.repo is existed"
else
wget -O /etc/yum.repos.d/base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
echo "base.repo is installing..."
fi
yum makecache &>/dev/null
if test $? -eq 0
then
echo "yum is ok"
else
echo "yum is not ready"
exit
fi
if yum -y install pcre-devel openssl-devel elinks gcc gcc-c++ make zlib-devel psmisc
then
echo "soft is ok "
else
echo "soft is bad"
exit
fi
ip=10.0.112.148
address=http://nginx.org/download/nginx-1.14.2.tar.gz
add=`echo $address| awk -F"/" '{print $NF}'`
name=nginx
echo ##################################
if ! id $name &>/dev/null
then
useradd $name
fi
mkdir -p /var/tmp/$name/{client,proxy,fastcgi,uwsgi,scgi}
chown nginx.nginx /var/tmp/$name/{client,proxy,fastcgi,uwsgi,scgi}
if test $? -eq 0 &>/dev/null
then
echo “文件建好了”
else
echo "文件创建出现问题"
exit
fi
echo #########################################
wget $address -P /usr/local/src/
cd /usr/local/src
tar xf $add
if test -d $dir &>/dev/null
then
echo "$name 包已解压完成"
else
echo "$name 包解压失败"
exit
fi
dir=`ls -l /usr/local/src/ |grep nginx |head -1|awk '{print $NF}'`
cd /usr/local/src/$dir
sh `cat <<EOF
configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_sub_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_realip_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-file-aio --with-http_secure_link_module
EOF`
if test $? -eq 0 &> /dev/null
then
echo "\./configure 完成"
else
echo "\./configure 失败"
exit
fi
echo #################################
make && make install
if test $? -eq 0 &> /dev/null
then
echo "make is ok"
else
echo "make is not"
exit
fi
echo ####################################
/usr/local/nginx/sbin/nginx
echo \/usr/local/nginx/sbin/nginx >> /etc/rc.d/rc.local
chmod a+x /etc/rc.d/rc.local
killall $name
while test $? -eq 0 &> /dev/null
do
killall $name
done
systemctl restart rc-local
systemctl enable rc-local
echo ############################333
ss -ant |grep :80 &>/dev/null
if test $? -eq 0 &> /dev/null
then
echo "nginx is ok"
else
echo "nginxis not"
exit
fi
echo welcome to $name > /usr/local/nginx/html/index.html
elinks --dump $ip