nginx安装脚本

 1 #!/bin/bash
 2 version=nginx-1.20.1.tar.gz
 3 name=nginx-1.20.1
 4 install_dir=/usr/local
 5 log=/var/log/nginx
 6 #解决依赖关系
 7 yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget gd-devel gcc gcc-c++
 8 yum -y groups mark install 'Development Tools'
 9 #创建用户
10 id nginx &>/dev/null
11 if [ $? -ne 0 ];then
12 useradd -s /sbin/nologin nginx
13 fi
14 #创建日志存放目录
15 if [ ! -d $log ];then
16 mkdir -p /var/log/nginx
17 chown -R nginx.nginx /var/log/nginx
18 fi
19 #下载nginx
20 cd /usr/src/
21 wget http://nginx.org/download/$version
22 #解压
23 tar xf $version
24 mv $name nginx
25 cd nginx/ && ./configure \
26 --prefix=$install_dir/nginx \
27 --user=nginx \
28 --group=nginx \
29 --with-debug \
30 --with-http_ssl_module \
31 --with-http_realip_module \
32 --with-http_image_filter_module \
33 --with-http_gunzip_module \
34 --with-http_gzip_static_module \
35 --with-http_stub_status_module \
36 --http-log-path=$log/access.log \
37 --error-log-path=$log/error.log
38  
39 make && make install
40 #配置环境变量
41 echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
42 source /etc/profile.d/nginx.sh
43  
44 #创建服务文件
45 cat > /usr/lib/systemd/system/nginx.service <
46  
47 [Unit]
48 Description=nginx
49 After=network.target
50  
51 [Service]
52 Type=forking
53 ExecStart=$install_dir/nginx/sbin/nginx
54 ExecReload=$install_dir/nginx/sbin/nginx -s reload
55 ExecStop=$install_dir/nginx/sbin/nginx -s quit
56 PrivateTmp= true
57  
58 [Install]
59 WantedBy=multi-user.target
60  
61 EOF
62 #开机自启
63 systemctl enable --now nginx

 

posted @ 2021-11-15 20:05  leiuk  阅读(71)  评论(0编辑  收藏  举报