一、配置防火墙,开启80端口、3306端口,关闭SELINUX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@Zabbix ~]
# vim /etc/sysconfig/iptables
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
[root@Zabbix ~]
# vim /etc/selinux/config
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@Zabbix ~]
# reboot
|
二、软件包下载
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@Zabbix ~]
# cd /usr/local/src/
[root@Zabbix src]
# ls
cmake-3.0.2.
tar
.gz MySQL编译工具
libgd-2.1.0.
tar
.gz gd库安装包
libvpx-v1.3.0.
tar
.bz2 gd库需要
openssl-1.0.1j.
tar
.gz nginx扩展
t1lib-5.1.2.
tar
.gz php扩展
zlib-1.2.8.
tar
.gz nginx扩展
freetype-2.5.4.
tar
.gz gd库需要
libmcrypt-2.5.8.
tar
.gz php扩展
mysql-5.6.21.
tar
.gz
pcre-8.36.
tar
.gz 支持nginx伪静态
tiff-4.0.3.
tar
.gz gd库需要
jpegsrc.v9a.
tar
.gz gd库需要
libpng-1.6.7.
tar
.gz gd库需要
nginx-1.6.2.
tar
.gz
php-5.6.3.
tar
.gz
yasm-1.3.0.
tar
.gz php扩展
[root@Zabbix src]
#
|
三、安装编译工具及库文件
1
2
3
4
5
6
7
8
|
yum
install
-y apr* autoconf automake bison
bzip2
bzip2
* cloog-ppl compat*
cpp curl curl-devel fontconfig fontconfig-devel freetype freetype*
freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel
kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng
libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel
libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff*
make
mpfr
ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common
php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel
|
四、安装MySQL
1、安装cmake
1
2
3
4
|
[root@Zabbix src]
# tar zxvf cmake-3.0.2.tar.gz
[root@Zabbix src]
# cd cmake-3.0.2
[root@Zabbix cmake-3.0.2]
# ./configure
[root@Zabbix cmake-3.0.2]
# make && make install
|
2、安装MySQL
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
|
[root@Zabbix cmake-3.0.2]
# groupadd mysql
[root@Zabbix cmake-3.0.2]
# useradd -g mysql mysql -s /sbin/nologin
[root@Zabbix cmake-3.0.2]
# mkdir -p /opt/data/mysql #MySQL数据库存放目录
[root@Zabbix cmake-3.0.2]
# chown -R mysql:mysql /opt/data/mysql/
[root@Zabbix cmake-3.0.2]
# mkdir -p /app/mysql #MySQL安装目录
[root@Zabbix cmake-3.0.2]
# cd ..
[root@Zabbix src]
# tar zxvf mysql-5.6.21.tar.gz
[root@Zabbix src]
# cd mysql-5.6.21
[root@Zabbix mysql-5.6.21]
# cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/opt/data/mysql -DSYSCONFDIR=/etc
[root@Zabbix mysql-5.6.21]
# make && make install
[root@Zabbix mysql-5.6.21]
# rm -rf /etc/my.cnf #删除系统默认的配置文件
[root@Zabbix mysql-5.6.21]
# cd /app/mysql/ #进入MySQL安装目录
[root@Zabbix mysql]
# ./scripts/mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/opt/data/mysql #生成mysql系统数据库
[root@Zabbix mysql]
# ln -s /app/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接
[root@Zabbix mysql]
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
[root@Zabbix mysql]
# chmod 755 /etc/rc.d/init.d/mysqld
[root@Zabbix mysql]
# chkconfig mysqld on
[root@Zabbix mysql]
# vim /etc/rc.d/init.d/mysqld
basedir=
/app/mysql
datadir=
/opt/data/mysql
[root@Zabbix mysql]
# service mysqld start
Starting MySQL. [ OK ]
[root@Zabbix mysql]
#
[root@Zabbix mysql]
# vim /etc/profile
export
PATH=$PATH:
/app/mysql/bin
#把mysql服务加入系统环境变量:在最后添加下面这一行
[root@Zabbix mysql]
# source /etc/profile
#把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
[root@Zabbix mysql]
# ln -s /app/mysql/include/mysql /usr/include/mysql
[root@Zabbix mysql]
# ln -s /app/mysql/lib/mysql /usr/lib/mysql
[root@Zabbix mysql]
# mkdir /var/lib/mysql
[root@Zabbix mysql]
# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@Zabbix mysql]
# mysql_secure_installation #设置Mysql密码,根据提示回车、输入Y 回车输入2次密码,一路回车
[root@Zabbix mysql]
# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
[root@Zabbix mysql]
#
|
五、安装Nginx
1、安装pcre
1
2
3
4
5
6
|
[root@Zabbix mysql]
# cd /usr/local/src/
[root@Zabbix src]
# mkdir /app/pcre
[root@Zabbix src]
# tar zxvf pcre-8.36.tar.gz
[root@Zabbix src]
# cd pcre-8.36
[root@Zabbix pcre-8.36]
# ./configure --prefix=/app/pcre
[root@Zabbix pcre-8.36]
# make && make install
|
2、安装openssl
1
2
3
4
5
6
7
8
9
|
[root@Zabbix pcre-8.36]
# cd ..
[root@Zabbix src]
# mkdir /app/openssl
[root@Zabbix src]
# tar zxvf openssl-1.0.1j.tar.gz
[root@Zabbix src]
# cd openssl-1.0.1j
[root@Zabbix openssl-1.0.1j]
# ./config --prefix=/app/openssl/
[root@Zabbix openssl-1.0.1j]
# make && make install
[root@Zabbix openssl-1.0.1j]
# vim /etc/profile
export
PATH=$PATH:
/app/openssl/bin
[root@Zabbix openssl-1.0.1j]
# source /etc/profile
|
3、安装zlib
1
2
3
4
5
6
|
[root@Zabbix openssl-1.0.1j]
# cd /usr/local/src/
[root@Zabbix src]
# mkdir /app/zlib
[root@Zabbix src]
# tar zxvf zlib-1.2.8.tar.gz
[root@Zabbix src]
# cd zlib-1.2.8
[root@Zabbix zlib-1.2.8]
# ./configure --prefix=/app/zlib/
[root@Zabbix zlib-1.2.8]
# make && make install
|
4、安装Nginx
1
2
3
4
5
6
7
|
[root@Zabbix zlib-1.2.8]
# cd /usr/local/src/
[root@Zabbix src]
# groupadd www
[root@Zabbix src]
# useradd -g www www -s /sbin/nologin
[root@Zabbix src]
# tar zxvf nginx-1.6.2.tar.gz
[root@Zabbix src]
# cd nginx-1.6.2
[root@Zabbix nginx-1.6.2]
# ./configure --prefix=/app/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36
[root@Zabbix nginx-1.6.2]
# make && make install
|
注意:--with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@Zabbix nginx-1.6.2]
# cd /app/nginx/sbin/
[root@Zabbix sbin]
# ./nginx #启动
[root@Zabbix sbin]
# ps -ef|grep -i nginx
root 23408 1 0 12:21 ? 00:00:00 nginx: master process .
/nginx
www 23409 23408 0 12:21 ? 00:00:00 nginx: worker process
root 23411 2232 0 12:22 pts
/0
00:00:00
grep
-i nginx
[root@Zabbix sbin]
# ./nginx -s reload #重启
[root@Zabbix sbin]
# ./nginx -t -c /app/nginx/conf/nginx.conf #检查配置文件
nginx: the configuration
file
/app/nginx/conf/nginx
.conf syntax is ok
nginx: configuration
file
/app/nginx/conf/nginx
.conf
test
is successful
[root@Zabbix sbin]
# ./nginx -v #查版本号
nginx version: nginx
/1
.6.2
[root@Zabbix sbin]
# ./nginx -V #查编译配置
nginx version: nginx
/1
.6.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI support enabled
configure arguments: --prefix=
/app/nginx
--without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=
/usr/local/src/openssl-1
.0.1j --with-zlib=
/usr/local/src/zlib-1
.2.8 --with-pcre=
/usr/local/src/pcre-8
.36
[root@Zabbix sbin]
#
|
5、设置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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
[root@Zabbix sbin]
# vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /app/nginx/conf/nginx.conf
# pidfile: /app/nginx/logs/nginx.pid
# Source function library.
.
/etc/rc
.d
/init
.d
/functions
# Source networking configuration.
.
/etc/sysconfig/network
# Check that networking is up.
[
"$NETWORKING"
=
"no"
] &&
exit
0
nginx=
"/app/nginx/sbin/nginx"
prog=$(
basename
$nginx)
NGINX_CONF_FILE=
"/app/nginx/conf/nginx.conf"
[ -f
/etc/sysconfig/nginx
] && .
/etc/sysconfig/nginx
lockfile=
/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 |
grep
"configure arguments:"
|
sed
's/[^*]*--user=\([^ ]*\).*/\1/g'
-`
if
[ -z
"`grep $user /etc/passwd`"
];
then
useradd
-M -s
/bin/nologin
$user
fi
options=`$nginx -V 2>&1 |
grep
'configure arguments:'
`
for
opt
in
$options;
do
if
[ `
echo
$opt |
grep
'.*-temp-path'
` ];
then
value=`
echo
$opt |
cut
-d
"="
-f 2`
if
[ ! -d
"$value"
];
then
# echo "creating" $value
mkdir
-p $value &&
chown
-R $user $value
fi
fi
done
}
start() {
|