#!/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
原创
©著作权归作者所有:来自51CTO博客作者小白的希望的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
虚拟机安装CentOS7
本章节我们将学习如何安装创建一个Linux学习环境。
CentOS VMware 云计算 系统 运维 -
Centos7安装python3.12
centos7 安装高版本的python3.12的方法和过程;
python 软链接 python3 -
编译安装nginx centos7
centos7下编译安装nginx
centos7 nginx编译安装 -
nginx的编译安装 centos7
nginx 编译安装 centos7 简单 明了 献丑了
nginx; 编译安装 centos7 -
Centos7安装自动化运维Ansible
自动化运维Devops-AnsibleAnsible是新出现的自动化运维工具,基于开发,集合了众多运维工具(、cfengine、chef、func、fabric)
运维 自动化 ansible Ansible python -
Centos7上Nginx的编译安装
Centos7上Nginx的编译安装 添加第三方Nginx模块
Centos7上Nginx的编译安装