#!/bin/bash
#环境
echo -e "\e[1;32m 开始准备环境 \e[0m"
yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel nettools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
FILE='nginx-1.18.0.tar.gz'
FILE_DIR='nginx-1.18.0'
CPUS=`lscpu | grep "CPU(s):"|awk '{print $2}'|head -1`
tar -xvf $FILE -C /usr/local/src/
cd /usr/local/src/$FILE_DIR
#编译安装
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --pid-path=/apps/nginx/nginx.pid
wait
make -j $CPUS && make install
#添加用户
useradd nginx -s /sbin/nologin -u 2000
cat > /lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
EOF
echo -e "\e[1;32m service文件已生成 /lib/systemd/system/nginx.service\e[0m"
#添加环境
echo "PATH=/apps/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
. /etc/profile.d/nginx.sh
echo -e "\e[1;32m 已添加环境 /lib/systemd/system/nginx.service\e[0m"
#删除编译文件
rm -rf /usr/local/src/nginx-1.18.0/
echo -e "\e[1;32m 已删除编译文件 /lib/systemd/system/nginx.service\e[0m"