六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 978|回复: 0

Linux---centos6编译安装nginx1.8.1(附:安装脚本)

[复制链接]
 楼主| 发表于 2020-7-9 19:16:28 | 显示全部楼层 |阅读模式
Linux---centos6编译安装nginx1.8.1(附:安装脚本)
环境
系统环境:CentOS release 6.7 (Final)

需求
centos6.7编译安装nginx1.8.1

准备
安装依赖
yum install -y  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
1
下载安装包
cd /opt/software
1
#download nginx
wget -c http://nginx.org/download/nginx-1.8.1.tar.gz

#download pcre
wget -c https://sourceforge.net/projects ... 35/pcre-8.35.tar.gz

#download zlib
wget -c http://zlib.net/zlib-1.2.8.tar.gz

#download openssl
wget -c http://www.openssl.org/source/openssl-1.0.1i.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
解压包
tar zxvf nginx-1.8.1.tar.gz

tar zxvf pcre-8.35.tar.gz

tar zxvf zlib-1.2.8.tar.gz

tar zxvf openssl-1.0.1i.tar.gz
1
2
3
4
5
6
7
添加用户
groupadd -r nginx

useradd -r -g nginx nginx
1
2
3
编译安装
cd /opt/software/nginx-1.8.1
1
./configure \
--prefix=/opt/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/var/run/nginx.pid \
--with-pcre=/opt/software/pcre-8.35 \
--with-zlib=/opt/software/zlib-1.2.8 \
--with-openssl=/opt/software/openssl-1.0.1i

make

make install && echo OK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
启动nginx
正确性检查
#每次修改nginx配置文件后都要进行检查

/opt/nginx/sbin/nginx -t
1
2
3


启动nginx
/opt/nginx/sbin/nginx
1
reload nginx
/opt/nginx/sbin/nginx -s reload
1
一键安装脚本
将以上步骤整合到一个脚本中来编译安装nginx

vim nginx1.8.sh
1
#!/bin/bash
#install nginx-1.8.1

#安装目录
INSTALL_DIR=/opt/
SRC_DIR=/opt/software

[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}
[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1
fi

#安装依赖包
for Package in wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
do
    yum -y install $Package
done

Install_Nginx()
{
#更新版本信息
NGINX="nginx-1.8.1"
PCRE="pcre-8.35"
ZLIB="zlib-1.2.8"
OPENSSL="openssl-1.0.1i"

NGINXFEATURES="--prefix=${INSTALL_DIR}nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/var/run/nginx.pid \
--with-pcre=${SRC_DIR}/${PCRE} \
--with-zlib=${SRC_DIR}/${ZLIB} \
--with-openssl=${SRC_DIR}/${OPENSSL}
"

cd ${SRC_DIR}
#下载所需安装包
echo 'Downloading NGINX'
if [ ! -f ${NGINX}.tar.gz ]
then
  wget -c http://nginx.org/download/${NGINX}.tar.gz
else
  echo 'Skipping: NGINX already downloaded'
fi

echo 'Downloading PCRE'
if [ ! -f ${PCRE}.tar.gz ]
then
  wget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/${PCRE}.tar.gz
else
  echo 'Skipping: PCRE already downloaded'
fi

echo 'Downloading ZLIB'
if [ ! -f ${ZLIB}.tar.gz ]
then
  wget -c http://zlib.net/${ZLIB}.tar.gz
else
  echo 'Skipping: ZLIB already downloaded'
fi

echo 'Downloading OPENSSL'
if [ ! -f ${OPENSSL}.tar.gz ]
then
  wget -c http://www.openssl.org/source/${OPENSSL}.tar.gz
else
  echo 'Skipping: OPENSSL already downloaded'
fi

echo '----------Unpacking downloaded archives. This process may take serveral minutes---------'

echo "Extracting ${NGINX}..."
tar xzf ${NGINX}.tar.gz
echo 'Done.'

echo "Extracting ${PCRE}..."
tar xzf ${PCRE}.tar.gz
echo 'Done.'

echo "Extracting ${ZLIB}..."
tar xzf ${ZLIB}.tar.gz
echo 'Done.'

echo "Extracting ${OPENSSL}..."
tar xzf ${OPENSSL}.tar.gz
echo 'Done.'

#添加用户
groupadd -r nginx
useradd -r -g nginx nginx

#编译
echo '###################'
echo 'Compile NGINX'
echo '###################'
cd ${SRC_DIR}/${NGINX}
./configure ${NGINXFEATURES}
make
make install
cd ../

mkdir -p ${INSTALL_DIR}/nginx/conf/vhosts

}

Install_Nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
安装方式:
可将需下载的安装包一起上传至/opt/software后加快安装进度

在/opt/software中执行安装脚本


注意:如果将脚本复制到linux下,可能存在格式问题,通过 :set ff=unix 解决
————————————————
摘自:https://blog.csdn.net/loyachen/java/article/details/50904593

Linux---centos6编译安装nginx1.8.1(附:安装脚本)
该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表