#!/bin/bash
# Name:nginx-install.sh
# Version: 1.0
# Discription: To
nginx="nginx-1.24.0" #nginx版本
echo "################################## ${nginx} installation started ###################################"
#1.设置变量
workDir=$(pwd)
sslmodule=0 # nginx启用SSL(Https证书,默认不启用)
nginxlibs="./nginx.libs" # nginx依赖包
installDir="/usr/local/nginx" # nginx安装目录
mynginx=$installDir/sbin/nginx
myconf=$installDir/conf/nginx.conf
rely_software=(gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel make)
#2.下载nginx安装包
# wget -c https://nginx.org/download/$nginx.tar.gz
#3.安装依赖
#3.1 要求已管理员身份运行
if [ $USER != "root" ];then
echo "注意,请以管理员身份运行此程序!"
exit -1
fi
#3.2 检测安装包是否存在
if [ ! -f "${nginx}.tar.gz" ];then
echo "当前目录未找到nginx安装包${nginx}.tar.gz,安装程序已取消。"
exit -1
fi
#3.3 安装本地依赖项(ARM架构不需要安装此依赖)
if [ -d "$nginxlibs" ];then
rpm -Uvh $nginxlibs/*.rpm --nodeps --force
fi
#3.4 检测当前依赖项(ARM架构不需要安装此依赖)
for i in ${rely_software[*]}
do
rpm -q $i &>/dev/null
if [ $? -eq 0 ];then
echo "$i is installed"
else
yum -y install $i &>/dev/null
action "$i is installing" /usr/bin/true
fi
done
echo "依赖检测完成,进入安装..."
#4.编译安装
tar -zxvf $nginx.tar.gz
cd $nginx
if [ $sslmodule -eq 0 ];then
./configure --prefix=$installDir
else
./configure --prefix=$installDir --with-http_stub_status_module --with-http_ssl_module
fi
make
make install
whereis nginx
echo "编译安装已完成"
#5.执行配置
#5.1 添加静态文件压缩
line=33
sed -i "$((line++))G" $myconf
sed -i "$((line++))i gzip on;" $myconf
sed -i "$((line++))i gzip_vary on;" $myconf
sed -i "$((line++))i gzip_buffers 4 16K;" $myconf
sed -i "$((line++))i gzip_comp_level 6;" $myconf
sed -i "$((line++))i gzip_min_length 100k;" $myconf
sed -i "$((line++))i gzip_types text/plain text/css application/javascript;" $myconf
echo "已添加静态文件压缩配置"
#5.2 添加日志切割
if type logrotate >/dev/null 2>&1; then
cat >/etc/logrotate.d/nginx<<EOF
$installDir/logs/*log {
create 0644 root root
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
kill -USR1 \`cat $installDir/logs/nginx.pid 2>/dev/null\` 2>/dev/null || true
endscript
}
EOF
echo "0 0 * * * logrotate -vf /etc/logrotate.d/nginx" >> /var/spool/cron/root
echo "已添加日志切割配置"
fi
sleep 3s
#6.开机启动
cat >/etc/systemd/system/nginx.service<<EOF
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
# PIDFile=$installDir/logs/nginx.pid
ExecStartPre=$mynginx -t -c $myconf
ExecStart=$mynginx -c $myconf
ExecReload=$mynginx -s reload
ExecStop=$mynginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx.service
echo "已为nginx 添加开机启动服务"
#7.启动nginx
systemctl start nginx
systemctl status nginx
ps aux|grep nginx
echo "################################## ${nginx} installation success ###################################"
没有合适的资源?快使用搜索试试~ 我知道了~
nginx一键部署脚本
0 下载量 79 浏览量
2023-10-24
11:21:38
上传
评论
收藏 64.02MB GZ 举报
温馨提示
nginx一键部署脚本
资源推荐
资源详情
资源评论
收起资源包目录
Nginx.el7.tar.gz (41个子文件)
Nginx
nginx.install.sh 3KB
nginx-1.24.0.tar.gz 1.06MB
nginx.libs
keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm 37KB
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm 306KB
libsepol-devel-2.5-10.el7.x86_64.rpm 77KB
e2fsprogs-libs-1.42.9-19.el7.x86_64.rpm 168KB
libselinux-python-2.5-15.el7.x86_64.rpm 236KB
openssl-devel-1.0.2k-25.el7_9.x86_64.rpm 1.51MB
glibc-devel-2.17-55.el7.x86_64.rpm 1.01MB
libkadm5-1.15.1-54.el7_9.x86_64.rpm 179KB
libss-1.42.9-19.el7.x86_64.rpm 47KB
zlib-devel-1.2.7-20.el7_9.x86_64.rpm 50KB
libicu-50.2-4.el7_7.x86_64.rpm 6.87MB
libselinux-devel-2.5-15.el7.x86_64.rpm 187KB
glibc-common-2.17-55.el7.x86_64.rpm 11.19MB
cpp-4.8.2-16.el7.x86_64.rpm 5.93MB
libcom_err-1.42.9-19.el7.x86_64.rpm 42KB
libselinux-utils-2.5-15.el7.x86_64.rpm 151KB
pcre-8.32-17.el7.x86_64.rpm 422KB
libsepol-2.5-10.el7.x86_64.rpm 297KB
icu-50.2-4.el7_7.x86_64.rpm 187KB
openssl-libs-1.0.2k-25.el7_9.x86_64.rpm 1.2MB
pcre-devel-8.32-17.el7.x86_64.rpm 480KB
e2fsprogs-1.42.9-19.el7.x86_64.rpm 701KB
kernel-headers-3.10.0-123.el7.x86_64.rpm 1.42MB
gcc-4.8.5-44.el7.x86_64.rpm 16.18MB
glibc-utils-2.17-55.el7.x86_64.rpm 193KB
glibc-static-2.17-55.el7.x86_64.rpm 1.5MB
libmpc-1.0.1-3.el7.x86_64.rpm 51KB
krb5-libs-1.15.1-54.el7_9.x86_64.rpm 810KB
libcom_err-devel-1.42.9-19.el7.x86_64.rpm 32KB
libselinux-2.5-15.el7.x86_64.rpm 162KB
libverto-devel-0.2.5-4.el7.x86_64.rpm 12KB
openssl-1.0.2k-25.el7_9.x86_64.rpm 494KB
glibc-2.17-55.el7.x86_64.rpm 3.57MB
libstdc++-devel-4.8.5-36.el7.x86_64.rpm 1.51MB
gcc-c++-4.8.5-44.el7.x86_64.rpm 7.18MB
zlib-1.2.7-20.el7_9.x86_64.rpm 90KB
glibc-headers-2.17-55.el7.x86_64.rpm 650KB
krb5-devel-1.15.1-54.el7_9.x86_64.rpm 273KB
mpfr-3.1.1-4.el7.x86_64.rpm 203KB
共 41 条
- 1
资源评论
muzilee_001
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功