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
|
#!/bin/bash
#判断是否是roo用户
if
[ $(id -u) !=
"0"
]; then
echo
"Error:You must be root to run this script"
fi
#每次使用只需修改自定义内容即可
#自定义用户名和组
User=
"nginx"
Group=
"nginx"
#自定义nginx变量
Install_Path=
"/usr/local/nginx"
Package_Type=
".tar.gz"
Version=
"nginx-1.9.8"
Package=
$Version
$Package_Type
Setup_path=
"/root/"
RPM=
"nginx"
#自定义/var/tmp/nginx目录
DIR=
"/var/tmp/nginx"
#安装依赖关系
yum group install
"Development Tools"
"Server Platform Deveopment"
yum install -y curl openssl-devel pcre-devel
#判断nginx组是否存在
egrep
"^$group"
/etc/group >& /dev/null
if
[ $? -ne 0 ]
then
groupadd
$group
else
echo
" The $Group user group already exists."
fi
#判断nginx用户是否存在
egrep
"^$user"
/etc/passwd >& /dev/null
if
[ $? -ne 0 ]
then
useradd -g
$group
$user
else
echo
" The $User user already exists."
fi
#创建/var/tmp/nginx目录
#mkdir /var/tmp/nginx
if
[ -e
$dir
]
then
echo
" $DIR Directory Already Exists."
else
mkdir
/var/tmp/nginx
fi
#判断文件是否存在
if
[ -e
$Setup_path
$Version
$Package_Type
]
then
echo
"$Package The Package exists."
else
echo
"$Package The package does not exist."
fi
#判断是否用RPM方式安装
function RPM_Install(){
rpm -qa | egrep
"$RPM"
>>/dev/null
if
[ $? -eq 0 ]
then
echo
"$RPM is install Yes."
else
echo
"$RPM is Not install."
fi
}
RPM_Install
#编译安装nginx
cd
$Setup_path
tar -zxvf
$Package
cd
$Version
configure_opts=(
--prefix=
$Install_Path
--sbin-path=
$Install_Path
/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-
log
-path=/var/
log
/nginx/error.
log
--http-
log
-path=/var/
log
/nginx/access.
log
--pid-path=/var/run/nginx/nginx.pid
--
lock
-path=/var/
lock
/nginx.
lock
--user=nginx
--group=nginx
--
with
-http_ssl_module
--
with
-http_flv_module
--
with
-http_stub_status_module
--
with
-http_gzip_static_module
--http-client-body-temp-path=/var/tmp/nginx/client
--http-proxy-temp-path=/var/tmp/nginx/proxy
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
--
with
-pcre
)
./configure ${configure_opts[@]}
if
[[ $? -eq 0 ]]
then
make && make install
else
echo
"编译失败,请重新编译"
&&
exit
1
fi
#添加Nginx命令到环境变量
cat >/etc/profile.d/nginx.sh
<<EOF
export PATH=/usr/local/nginx/sbin/:$PATH
EOF
#开机启动
chkconfig --add nginx
chkconfig nginx on
chkconfig --list |
grep
nginx
#启动服务
nginx
ss -tnlp |
grep
nginx
|
不足之处:没有启动文件,我是直接加了个环境变量用nginx回车启动的
看到此篇文章的大佬们,有启动文件的希望把启动文件加进来,希望给补充下,
有错误什么的,或者有更好的建议请留言
本文转自 zhangguangyi 51CTO博客,原文链接:http://blog.51cto.com/bosszhang/1967535