实验环境:
主机 | 主机名 | 操作系统 | IP地址 | 软件版本 |
zabbix监控端 | zabbix_server | Centos7.5 | 192.168.121.10 | zabbix-4.2.6 |
zabbix被监控端 | server01 | Centos7.5 | 192.168.121.11 | zabbix-4.2.6 |
zabbix监控端:192.168.121.11 #zabbix的服务端(若要监控本机,则需要配置本机的zabbix agent)。
Zabbix agent被监控主机:192.168.121.11 #zabbix的客户端(被监控端,需要配置Zabbix agent。
1.禁用SELINUX和关闭防火墙
两台虚拟机都需要执行关闭SELINUX和关闭防火墙
# service firewalld stop
# setenforce 0 //可以设置配置文件永久关闭
2、整个环境所需要的软件包
php-5.6.36
libmcrypt-2.5.7
mysql-5.7.26
nginx-1.10.3
zabbix-4.2.6
3.LAMP环境搭建
3.1、源码安装mysql-5.7.26
详情见本人的文章:源码安装mysql-5.7.26
3.2、安装php-5.6.36
3.2.1、安装依赖包
[root@zabbix_server ~]# yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel
3.2.2、安装libmcrypt
[root@zabbix_server ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@zabbix_server ~]# cd libmcrypt-2.5.7/
[root@zabbix_server libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install
3.2.3、安装php
[root@zabbix_server ~]# tar zxf php-5.6.36.tar.gz
[root@zabbix_server ~]# cd php-5.6.36/
[root@zabbix_server php-5.6.36]# ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt=/usr/local/libmcrypt --with-curl
[root@zabbix_server php-5.6.36]# make && make install
3.2.4、生成php.ini配置文件
[root@zabbix_server php-5.6.36]# cp php.ini-production /etc/php.ini
编辑配置文件/etc/php.ini ,修改后的内容如下:
找到:
;date.timezone =
修改为:
date.timezone = PRC #设置时区
找到:
expose_php = On
修改为:
expose_php = Off #禁止显示php版本的信息
找到:
short_open_tag = Off
修改为:
short_open_tag = On //支持php短标签
找到:
post_max_size = 8M
修改为:
post_max_size = 16M //上传文件大小
找到:
max_execution_time = 30
修改为:
max_execution_time = 300 //php脚本最大执行时间
找到:
max_input_time = 60
修改为:
max_input_time = 300 //以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
always_populate_raw_post_data = -1
mbstring.func_overload = 0
3.2.5、创建php-fpm服务启动脚本
[root@zabbix_server php-5.6.36]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@zabbix_server php-5.6.36]# chmod +x /etc/init.d/php-fpm
[root@zabbix_server php-5.6.36]# chkconfig --add php-fpm
[root@zabbix_server php-5.6.36]# chkconfig php-fpm on
3.2.6、提供php-fpm配置文件并编辑
[root@zabbix_server ~]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@zabbix_server ~]# useradd -M -s /sbin/nologin www
[root@zabbix_server ~]# vim /usr/local/php5.6/etc/php-fpm.conf
修改内容如下:
pid = run/php-fpm.pid
user = www
group = www
listen =127.0.0.1:9000
pm.max_children = 300
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers =50
3.2.7、启动php-fpm服务
[root@zabbix_server ~]# /etc/init.d/php-fpm start
[root@zabbix_server ~]# netstat -anplt | grep php-fpm
3.3、安装nginx
3.3.1、安装依赖包
[root@zabbix_server ~]# yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
3.3.2、编译安装
[root@zabbix_server ~]# tar zxf nginx-1.10.3.tar.gz
[root@zabbix_server ~]# cd nginx-1.10.3/
[root@zabbix_server nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
[root@zabbix_server nginx-1.10.3]# make && make install
3.3.3、启动nginx服务
[root@zabbix_server ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@zabbix_server ~]# nginx
[root@zabbix_server ~]# netstat -anplt | grep nginx
3.3.4、配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {