1.查看系统版本
命令:
cat /etc/redhat-release
CentOS6.9 LAMP环境下安装zabbix4.2

2.关闭防火墙
命令:
service iptables stop
chkconfig iptables off
CentOS6.9 LAMP环境下安装zabbix4.2_第1张图片

3.关闭selinux
临时关闭selinux,立即生效
命令:
setenforce 0
CentOS6.9 LAMP环境下安装zabbix4.2

永久关闭selinux,重新开机才生效
命令:
vi /etc/sysconfig/selinux
CentOS6.9 LAMP环境下安装zabbix4.2_第2张图片

4.安装epel源
命令:
yum -y install epel-release
CentOS6.9 LAMP环境下安装zabbix4.2

5.安装mysql 5.6
命令:
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum -y install mysql-server
CentOS6.9 LAMP环境下安装zabbix4.2

查看mysql安装的版本
rpm -qa | grep mysql
CentOS6.9 LAMP环境下安装zabbix4.2_第3张图片

6.数据库安全并设置root密码,创建zabbix数据库并授权
启动mysql数据库
service mysqld start
CentOS6.9 LAMP环境下安装zabbix4.2
设置root密码及安全性设置
mysql_secure_installation
CentOS6.9 LAMP环境下安装zabbix4.2_第4张图片
使用mysql的root用户登录数据库并为zabbix创建数据库zabbix,并对zabbix数据库创建用户和密码及授权
mysql -uroot -pa123456
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbixpwd';
flush privileges;
exit
CentOS6.9 LAMP环境下安装zabbix4.2_第5张图片

7.安装php5.6
命令:
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
yum -y install httpd php56w php56w-gd php56w-mysql php56w-bcmath php56w-mbstring php56w-xml php56w-ldap php56w-pdo php56w-fpm
CentOS6.9 LAMP环境下安装zabbix4.2_第6张图片

8.修改php.ini文件
命令:
vi /etc/php.ini
在php.ini找到相对应的并修改为如下的值
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1

9.修改apache配置
命令:
vi /etc/httpd/conf/httpd.conf
在http.conf文件中找到DirectoryIndex,添加index.php
ServerName 127.0.0.1
DirectoryIndex index.html index.html.var index.php
CentOS6.9 LAMP环境下安装zabbix4.2

启动httpd服务
命令:
service httpd start
CentOS6.9 LAMP环境下安装zabbix4.2
7.测试LAMP连通性
命令:
vi /var/www/html/index.php
添加如下内容
echo "Zabbix 4.X

";

    $conn = new mysqli("127.0.0.1","root","a123456");

    if ($conn->connect_error) {
        die("连接数据库失败: ");
    }

    echo "连接数据库成功";
?>

CentOS6.9 LAMP环境下安装zabbix4.2_第7张图片

8.测试LAMP
CentOS6.9 LAMP环境下安装zabbix4.2_第8张图片

关闭mysql数据,再次测试访问
命令:service mysqld stop
CentOS6.9 LAMP环境下安装zabbix4.2
CentOS6.9 LAMP环境下安装zabbix4.2_第9张图片

9.安装依赖包(经测试,此步可以不操作)
命令:
yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc*
CentOS6.9 LAMP环境下安装zabbix4.2

10.安装zabbix4.2
命令:
rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/6/x86_64/zabbix-release-4.2-2.el6.noarch.rpm
yum clean all
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
CentOS6.9 LAMP环境下安装zabbix4.2_第10张图片

导入zabbix需要的数据库件
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
CentOS6.9 LAMP环境下安装zabbix4.2

vi /etc/zabbix/zabbix_server.conf
修改DBPassword=password
CentOS6.9 LAMP环境下安装zabbix4.2

重启httpd并启动zabbix-server和zabbix-agent
service zabbix-server start
service zabbix-agent start
service httpd restart
CentOS6.9 LAMP环境下安装zabbix4.2_第11张图片

11.修改httpd的配置文件
命令:
vi /etc/httpd/conf/httpd.conf
找到 DocumentRoot "/var/www/html"修改为DocumentRoot "/usr/share/zabbix" ///usr/share/zabbix为zabbix程序目录
CentOS6.9 LAMP环境下安装zabbix4.2

12.重新启动httpd服务
命令:
service httpd restart
CentOS6.9 LAMP环境下安装zabbix4.2

13.在浏览器中访问http://192.168.80.63 初始化zabbix4.2
CentOS6.9 LAMP环境下安装zabbix4.2_第12张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第13张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第14张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第15张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第16张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第17张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第18张图片
CentOS6.9 LAMP环境下安装zabbix4.2_第19张图片