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
#!/bin/sh
 
#安装yum的axel插件,使yum支持多线程下载:
#rpm -ivh http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm
#cp axelget.conf /etc/yum/pluginconf.d/
#cp axelget.py /usr/lib/yum-plugins/
 
#下载163 yum源:
#wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O CentOS-Base.repo
#cp -p /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#mv -f CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
 
#安装epel yum源:
#rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
#sed -i 's/^mirrorlist=https/mirrorlist=http/' /etc/yum.repos.d/epel.repo
 
 
#nginx的yum源(推荐编译安装,可以获得更好的性能):
#cat > /etc/yum.repos.d/nginx.repo << 'EOF'
#[nginx]
#name=nginx repo
#baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
#enabled=1
#gpgcheck=0
#EOF
 
yum install nginx -y
 
 
 
#安装Mysql的yum源(推荐编译安装,获得更好的性能):
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum install mysql-devel mysql-server
 
 
#安装php5.6 yum源(注意,这个需要先安装好原来的php各种插件,安装升级的php会卸载旧的php,
#如果发现有些插件没有安装,必须得先卸载掉高版本的php-common然后再安装php插件,最后再安装php-common)
#如果mysql不在本地,还需要安装mysqlnd(安装mysqlnd时需要先卸载php-mysql)
#wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
#rpm -ivh remi-release-6.rpm 
#yum install php-mysqlnd
#php -m   #查看安装的插件
 
#安装php 5.3
yum install php php-mysql php-fpm php-bcmath php-mbstring php-gd* libxml libxml-devel php-xml php-soap php-bcmath php-xml php-opcache php-gd php-mcrypt php-pdo php-mysql php-mbstring php-xmlrpc
 
#升级刚才安装的php到5.6
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install yum-plugin-replace -y
yum replace php-common --replace-with=php56w-common -y
 
 
 
#修改php配置:
PHP_INI="/etc/php.ini"
FPM_CONF="/etc/php-fpm.d/www.conf"
sed -i '/^;default_charset/cdefault_charset = "utf-8"' $PHP_INI
sed -i '/^expose_php/cexpose_php = Off' $PHP_INI 
sed -i '/^max_execution_time/cmax_execution_time = 600' $PHP_INI
sed -i '/^max_input_time/cmax_input_time = 600' $PHP_INI
sed -i '/^memory_limit/cmemory_limit = 256M'  $PHP_INI
sed -i '/^post_max_size/cpost_max_size = 32M' $PHP_INI
sed -i '/^upload_max_filesize/cupload_max_filesize = 300M' $PHP_INI
sed -i '/^max_file_uploads/cmax_file_uploads = 30' $PHP_INI
sed -i '/^;date.timezone/cdate.timezone = "Asia/Shanghai"'  $PHP_INI
sed -i '/^disable_functions/cdisable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source syslog,readlink,symlink,popepassthru,stream_socket_server'  $PHP_INI
sed -i 's/apache/nginx/g' $FPM_CONF
sed -i '/^pm = dynamic/cpm = static' $FPM_CONF
sed -i '/^pm.max_children/cpm.max_children = 10' $FPM_CONF
sed -i '/^;pm.status_path/cpm.status_path = /php-status' $FPM_CONF
sed -i '/^;request_terminate_timeout/crequest_terminate_timeout=600' $FPM_CONF
sed -i '/^;request_slowlog_timeout/crequest_slowlog_timeout=3' $FPM_CONF 
 
###################################
######编辑php.ini,修改如下一行####
always_populate_raw_post_data = -1
 
###################################
######zabbix安装页面无法next#######
setfacl -R -m u:nginx:rwx /var/lib/php
 
#启动php
/etc/init.d/php-fpm start
 
 
 
#修改/etc/nginx/nginx.conf
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
echo "
user  nginx;
worker_processes 4;
error_log  /var/logs/nginx/error.log  crit;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 51200;
}
http
{
    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    sendfile on;
    tcp_nopush     on;
    keepalive_timeout 60;
    tcp_nodelay on;
    proxy_buffer_size 16k;
    proxy_buffers  4 64k;
    proxy_busy_buffers_size 128k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 256k;
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types   text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    server_tokens off;
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log /usr/local/nginx/logs/access.log access;
    reset_timedout_connection on;
    include conf.d/*.conf;
}
" >>/etc/nginx/nginx.conf
 
 
#创建/etc/nginx/conf.d/zabbix.conf
 
echo "
server {
   listen       80;
   server_name  localhost.com; 
  
   location / {
       root /www/zabbix;
       index index.php;
   }
 
   location ~ \.php$ {
       root /www/zabbix;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params; 
   
}
" > /etc/nginx/conf.d/zabbix.conf
 
######################################################################
/etc/init.d/nginx start
 
 
#安装zabbix 3.2
#注意:这里centos6 yum安装3.2会有问题,这个需要编译安装。
yum install libcurl libcurl-devel -y
 
tar zxf zabbix-3.2.5.tar.gz
cd zabbix-3.2.5
./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --with-mysql=/usr/bin/mysql_config --with-net-snmp --enable-agent --enable-server --with-libcurl --enable-proxy
make install
 
#从zabbix-3.2.5安装包中复制启动文件:
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
 
#修改脚本中的基本路径,默认路径是/usr/local/,这里修改为/usr/local/zabbix/etc
vi /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
 
#修改配置文件:zabbix-server.conf
DBPass=zabbix
 
 
#部署zabbix前端代码: 
mkdir -p /www/zabbix/
cp -r zabbix-3.2.5/frontends/php//www/zabbix/
chown -R nginx.nginx www/zabbix
chmod 755 /www/zabbix
 
 
 
#启动mysql:
/etc/init.d/mysqld start
 
#设置mysql root密码:
mysqladmin -uroot password 'mysql'
 
#创建zabbix数据库和用户:
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
 
#初始化zabbix数据库:
cd zabbix-3.2.5/database/mysql/
mysql -uzabbix -pzabbix zabbix < schema.sql
mysql -uzabbix -pzabbix zabbix < images.sql 
mysql -uzabbix -pzabbix zabbix < data.sql
  
 
#启动zabbix server和agent:
/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agent start
 
#安装完毕,最后访问Zabbix:
http://127.0.0.1/
 
 
#设置开机启动:
#启动php-fpm:
/etc/init.d/php-fpm start
 
添加开机自启动:
chkconfig --add php-fpm
chkconfig mysqld on
chkconfig php-fpm on
chkconfig nginx on
chkconfig zabbix-server on
chkconfig zabbix-agent on