shell脚本多实例部署nginx的详细教程
时间:2026-01-11 02:45:12|栏目:其它服务器|点击: 次
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 <
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]#
栏 目:其它服务器
本文地址:https://zz.feitang.co/server/35339.html
您可能感兴趣的文章
- 01-12Docker部署rabbitmq遇到的两个问题
- 01-12最新虚拟机VMware 14安装教程
- 01-12使用docker compose安装harbor私有仓库的详细教程
- 01-12Windows下Docker安装各种软件的详细过程
- 01-12seata docker 高可用部署的详细介绍
- 01-12浅谈Tomcat多层容器的设计
- 01-12Gogs+Jenkins+Docker 自动化部署.NetCore的方法步骤
- 01-12解决vscode docker插件docker.socket权限问题
- 01-12Docker中运行PostgreSQL并推荐几款连接工具
- 01-12Docker核心原理之 Cgroup详解


阅读排行
推荐教程
- 12-07一文教你怎么选择Tomcat对应的JDK版本
- 12-23linux中ftp无法访问怎么办
- 12-11docker存储目录迁移示例教程
- 12-10docker start启动容器后仍然exit状态的解决
- 12-10Linux下如何安装Logstash
- 12-05Docker安装Jenkins全过程
- 01-05Shell脚本去重的几种方法实例
- 12-22kvm虚拟机配置NAT端口转发的实现方法
- 12-19Zabbix SAML SSO 登录绕过漏洞的操作流程
- 12-15Docker-Compose搭建Spark集群的实现方法




