centos7自动化编译安装nginx
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7自动化编译安装nginx相关的知识,希望对你有一定的参考价值。
#!/bin/bash # auto install nginx nginx_src_dir=/data/nginx/ nginx_version=nginx-1.13.9 nginx_install_dir=/usr/local/nginx function install_nginx() { yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel autoconf automake wget -y if [ "$?" != "0" ];then echo "install dependent failed,please check" > /tmp/nginx_install.log exit 1 fi groupadd nginx useradd -s /sbin/nologin -g nginx -M nginx if [ ! -d ${nginx_src_dir} ];then mkdir -p ${nginx_src_dir} fi cd ${nginx_src_dir} wget http://nginx.org/download/${nginx_version}.tar.gz if [ "$?" != "0" ];then echo "download nginx failed, please check network" >>/tmp/nginx_install.log exit 2 fi tar xf ${nginx_version}.tar.gz cd ${nginx_version} ./configure --user=nginx --group=nginx --prefix=${nginx_install_dir} --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module if [ "$?" != "0" ];then echo "compile failed, please check error" >> /tmp/nginx_install.log exit 3 fi make && make install if [ "$?" != "0" ];then echo "make failed,please check make error" >> /tmp/nginx_install.log exit 4 fi cat >>/usr/lib/systemd/system/nginx.service <<EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=${nginx_install_dir}/logs/nginx.pid ExecStartPre=${nginx_install_dir}/sbin/nginx -t -c ${nginx_install_dir}/conf/nginx.conf ExecStart=${nginx_install_dir}/sbin/nginx -c ${nginx_install_dir}/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target EOF ln -s ${nginx_install_dir}/sbin/nginx /usr/bin/nginx systemctl start nginx.service if [ "$?" != "0" ];then echo "start failed,please check" >> /tmp/nginx_install.log exit 4 fi } install_nginx
以上是关于centos7自动化编译安装nginx的主要内容,如果未能解决你的问题,请参考以下文章