老样子安装包都拖到opt里!
脚本如下 source 执行!
#!/bin/bash #======编译安装nginx服务====== #安装所需开发包和编译环境、编译器 yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make #创建程序用户,便于准确控制访问 useradd -M -s /sbin/nologin nginx #解压安装包 cd /opt tar zxvf nginx-1.12.0.tar.gz -C /opt/ #指定安装路径、指定用户名、组名、启用模块以支持统计状态 cd nginx-1.12.0/ ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module #编译及安装 make && make install #软链接便于系统识别nginx操作命令 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #添加nginx系统服务 echo '[Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecrReload=/bin/kill -s HUP $MAINPID ExecrStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target' > /lib/systemd/system/nginx.service #赋权及开启服务、开启开机自启 chmod 754 /lib/systemd/system/nginx.service systemctl start nginx.service systemctl enable nginx.service