温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

shell脚本多实例怎么部署nginx

发布时间:2021-10-26 09:11:07 来源:亿速云 阅读:130 作者:iii 栏目:开发技术

这篇文章主要讲解了“shell脚本多实例怎么部署nginx”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“shell脚本多实例怎么部署nginx”吧!

1. 创建一个目录,用来存放脚本和安装包

[root@localhost nginx]# tree
.
├── install.sh
└── packages
    └── nginx-1.20.1.tar.gz

1 directory, 2 files
[root@localhost nginx]#

2. 下载好对应的安装包

[root@localhost packages]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
[root@localhost packages]# ls
nginx-1.20.1.tar.gz
[root@localhost packages]#

3. 编写脚本

[root@localhost nginx]# cat install.sh 
#!/bin/bash

log_dir=/var/log
install_dir=/usr/local

id nginx &>/dev/null
if [ $? -ne 0 ];then
 useradd -r -M -s /sbin/nologin nginx
fi

yum -y install pcre-devel pcre gcc gcc-c++ openssl-devel zlib zlib-devel make vim wget openssl openssl-devel gd-devel

if [ ! -d $log_dir/nginx ];then
    mkdir -p $log_dir/nginx
    chown -R nginx.nginx $log_dir/nginx
fi


if [ ! -d $install_dir/nginx-1.20.1 ];then
    tar xf packages/nginx-1.20.1.tar.gz -C $install_dir
fi

cd $install_dir/nginx-1.20.1
if [ ! -d $install_dir/nginx ];then
    ./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=/var/log/nginx/access.log \
        --error-log-path=/var/log/nginx/error.log
    make && make install
fi

echo "export PATH=$install_dir/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh

cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=Nginx server daemon
After=network.target 

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx 
ExecStop=/usr/local/nginx/sbin/nginx -s quit
ExecReload=/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable --now nginx.service


[root@localhost nginx]#

4. 验证效果

[root@localhost nginx]# bash -x install.sh 
+ log_dir=/var/log
+ install_dir=/usr/local
+ id nginx
+ '[' 0 -ne 0 ']'
+ yum -y install pcre-devel pcre gcc gcc-c++ openssl-devel zlib zlib-devel make vim wget openssl openssl-devel gd-devel
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:1:03:20 前,执行于 2021年10月24日 星期日 20时57分26秒。
软件包 pcre-devel-8.42-4.el8.x86_64 已安装。
软件包 pcre-8.42-4.el8.x86_64 已安装。
软件包 gcc-8.4.1-1.el8.x86_64 已安装。
软件包 gcc-c++-8.4.1-1.el8.x86_64 已安装。
软件包 openssl-devel-1:1.1.1g-15.el8_3.x86_64 已安装。
软件包 zlib-1.2.11-17.el8.x86_64 已安装。
软件包 zlib-devel-1.2.11-17.el8.x86_64 已安装。
软件包 make-1:4.2.1-10.el8.x86_64 已安装。
软件包 vim-enhanced-2:8.0.1763-15.el8.x86_64 已安装。
软件包 wget-1.19.5-10.el8.x86_64 已安装。
软件包 openssl-1:1.1.1g-15.el8_3.x86_64 已安装。
软件包 gd-devel-2.2.5-7.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
+ '[' '!' -d /var/log/nginx ']'
+ '[' '!' -d /usr/local/nginx-1.20.1 ']'
+ cd /usr/local/nginx-1.20.1
+ '[' '!' -d /usr/local/nginx ']'
+ echo 'export PATH=/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin'
+ cat
+ systemctl daemon-reload
+ systemctl enable --now nginx.service
[root@localhost nginx]# 
[root@localhost nginx]# ss -antl
State            Recv-Q           Send-Q                     Local Address:Port                       Peer Address:Port           
LISTEN           0                128                              0.0.0.0:80                              0.0.0.0:*              
LISTEN           0                128                              0.0.0.0:22                              0.0.0.0:*              
LISTEN           0                128                                 [::]:22                                 [::]:*              
[root@localhost nginx]#

感谢各位的阅读,以上就是“shell脚本多实例怎么部署nginx”的内容了,经过本文的学习后,相信大家对shell脚本多实例怎么部署nginx这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI