shell脚本源码安装nginx

[root@localhost ~]# vim nginx.sh 
[root@localhost ~]# cat nginx.sh 
#!/bin/bash
version=nginx-1.20.1.tar.gz
name=nginx-1.20.1
install_dir=/usr/local
log=/var/log/nginx
#解决依赖关系
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget gd-devel gcc gcc-c++
yum -y groups mark install 'Development Tools'
#创建用户
id nginx &>/dev/null
if [ $? -ne 0 ];then  
        useradd -s /sbin/nologin nginx 
fi
#创建日志存放目录
if [ ! -d $log ];then     
    mkdir -p /var/log/nginx
    chown -R nginx.nginx /var/log/nginx 
fi
#下载nginx
cd /usr/src/
wget   http://nginx.org/download/$version
#解压
tar xf $version 
mv $name nginx
cd nginx/ && ./configure \
--prefix=$install_dir/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=$log/access.log \
--error-log-path=$log/error.log

make && make install
#配置环境变量
echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
. /etc/profile.d/nginx.sh

#创建服务文件
cat > /usr/lib/systemd/system/nginx.service <<EOF

[Unit]
Description=nginx
After=network.target
   
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
   
[Install]
WantedBy=multi-user.target 

EOF

//测试
[root@localhost ~]# ./nginx.sh 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本
软件包 pcre-8.32-17.el7.x86_64 已安装并且是最新版本
软件包 pcre-devel-8.32-17.el7.x86_64 已安装并且是最新版本
软件包 zlib-1.2.7-19.el7_9.x86_64 已安装并且是最新版本
软件包 zlib-devel-1.2.7-19.el7_9.x86_64 已安装并且是最新版本
软件包 1:openssl-1.0.2k-22.el7_9.x86_64 已安装并且是最新版本
软件包 1:openssl-devel-1.0.2k-22.el7_9.x86_64 已安装并且是最新版本
软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本
软件包 gd-devel-2.0.35-27.el7_9.x86_64 已安装并且是最新版本
软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本
软件包 gcc-c++-4.8.5-44.el7.x86_64 已安装并且是最新版本
无须任何处理
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Marked install: Development Tools
--2021-10-25 12:15:53--  http://nginx.org/download/nginx-1.20.1.tar.gz
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1061461 (1.0M) [application/octet-stream]
正在保存至: “nginx-1.20.1.tar.gz.1”

100%[===================================================================================================================>] 1,061,461    670KB/s 用时 1.5s   

2021-10-25 12:15:55 (670 KB/s) - 已保存 “nginx-1.20.1.tar.gz.1” [1061461/1061461])

checking for OS
 + Linux 3.10.0-862.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
省略....
nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

make -f objs/Makefile
make[1]: 进入目录“/usr/local/nginx”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/nginx.o \
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/src/core/ngx_log.o \
        src/core/ngx_log.c
test -f '/usr/local/nginx/conf/nginx.conf' \
        || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/var/log/nginx' \
        || mkdir -p '/var/log/nginx'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/var/log/nginx' \
        || mkdir -p '/var/log/nginx'
make[1]: 离开目录“/usr/src/nginx”
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# ss -antl
State       Recv-Q Send-Q                                 Local Address:Port                                                Peer Address:Port              
LISTEN      0      128                                                *:80                                                             *:*                  
LISTEN      0      128                                                *:22                                                             *:*                  
LISTEN      0      100                                        127.0.0.1:25                                                             *:*                  
LISTEN      0      128                                               :::22                                                            :::*                  
LISTEN      0      100                                              ::1:25                                                            :::*              

shell脚本源码安装nginx

上一篇:大型DDoS攻击在全球肆虐,相应的DDoS防护将怎样应对?


下一篇:DDoS防护总是把握不到核心所在?带你详细剖析DDoS的攻击方法