1、下载安装包并解压
2、预环境搭建
3、创建zabbix用户,编译安装zabbix
4、配置mysql
5、配置zabbix-server
6、配置apache和php
7、添加开机自启动
1 yum install wget -y
2 wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
3 tar -zxf zabbix-4.0.3.tar.gz
4 cd zabbix-4.0.3
5
6 yum -y install httpd mysql-server
7 rpm -i https://mirror.webtatic.com/yum/el6/latest.rpm
8 yum -y install php55w php55w-mysql php55w-cli php55w-xml php55w-gd php55w-common php55w-bcmath php55w-pdo php55w-mbstring
9 yum -y install gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel libcurl-devel pcre-devel
10
11 useradd zabbix -s /sbin/nologin -M -u 200
12 ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
13 make install
14
15 /etc/init.d/mysqld start
16 mysql
17 create database zabbix4 character set utf8;
18 grant all on zabbix4.* to 'zbxuser'@'10.0.0.%' identified by 'zbxpass';
19 grant all on zabbix4.* to 'zbxuser'@'localhost' identified by 'zbxpass';
20 flush privileges;
21 quit
22 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/schema.sql
23 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/images.sql
24 mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/data.sql
25
26 sed "s/.*DBHost=.*/DBHost=localhost/g" /usr/local/etc/zabbix_server.conf -i
27 sed "s/^DBName=.*/DBName=zabbix4/g" /usr/local/etc/zabbix_server.conf -i
28 sed "s/^DBUser=.*/DBUser=zbxuser/g" /usr/local/etc/zabbix_server.conf -i
29 sed "s/.*DBPassword=.*/DBPassword=zbxpass/g" /usr/local/etc/zabbix_server.conf -i
30 zabbix_server
31
32 cp -r ~/zabbix-4.0.3/frontends/php /var/www/html/zabbix
33 cp /etc/php.ini{,.bak}
34 sed -i '/post_max_size =/ s/=.*M$/= 16M/g' /etc/php.ini
35 sed -i '/max_execution_time =/ s/=.*/= 300/g' /etc/php.ini
36 sed -i '/max_input_time =/ s/=.*/= 300/g' /etc/php.ini
37 sed -i '/date.timezone =/ adate.timezone = Asia/Shanghai' /etc/php.ini
38 chown -R apache. /var/www/html/zabbix/conf/
39 /etc/init.d/httpd restart
40 zabbix_agentd
41
42 chkconfig httpd on
43 chkconfig mysqld on
44 echo "/usr/local/sbin/zabbix_server" >>/etc/rc.local
45 echo "/usr/local/sbin/zabbix_agentd" >>/etc/rc.local
46 netstat -lntp
zabbix4.0.3源码安装脚本
1、下载安装包并解压
zabbix4.0.3源码包地址:https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
# 安装wget
yum install wget -y
# 下载zabbix源码包
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
# 解压缩并切换到zabbix-4.0.3目录下
tar -zxf zabbix-4.0.3.tar.gz
cd zabbix-4.0.3
2、预环境搭建
# 安装lamp环境(3.x以上版本的zabbix需要5.4以上版本的php支持,CentOS6默认yum源php最高版本为php5.3)
# 安装apache和mysql-server
yum -y install httpd mysql-server
# 安装高版本php的yum源
rpm -i https://mirror.webtatic.com/yum/el6/latest.rpm
# 安装php5.5
yum -y install php55w php55w-mysql php55w-cli php55w-xml php55w-gd php55w-common php55w-bcmath php55w-pdo php55w-mbstring
# 安装所需的编译工具或相关类库
yum -y install gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel libcurl-devel pcre-devel
3、创建zabbix用户,编译安装zabbix
# 创建zabbix用户用以启动相关进程
useradd zabbix -s /sbin/nologin -M -u 200
# 配置zabbix需要安装的功能
./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
# 安装
make install
4、配置mysql
# 启动mysqld服务
/etc/init.d/mysqld start
# 进入数据库
mysql
# 创建zabbix4数据库
create database zabbix4 character set utf8;
# 授权
grant all on zabbix4.* to 'zbxuser'@'10.0.0.%' identified by 'zbxpass';
grant all on zabbix4.* to 'zbxuser'@'localhost' identified by 'zbxpass';
# 更新配置使其实时生效
flush privileges;
# 查看数据库是否创建成功
show databases;
# 退出
quit
# 将zabbix的相关表导入到zabbix4数据库中
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/schema.sql
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/images.sql
mysql zabbix4 < ~/zabbix-4.0.3/database/mysql/data.sql
# 验证
mysql zabbix4
show tables;
quit
5、配置zabbix-server
# 配置DBHost
sed "s/.*DBHost=.*/DBHost=localhost/g" /usr/local/etc/zabbix_server.conf -i
# 配置DBName
sed "s/^DBName=.*/DBName=zabbix4/g" /usr/local/etc/zabbix_server.conf -i
# 配置DBUser
sed "s/^DBUser=.*/DBUser=zbxuser/g" /usr/local/etc/zabbix_server.conf -i
# 配置DBPassword
sed "s/.*DBPassword=.*/DBPassword=zbxpass/g" /usr/local/etc/zabbix_server.conf -i
# 查看配置更改情况
cat /usr/local/etc/zabbix_server.conf |grep -E "DBHost=|DBName=|DBUser=|DBPassword="
# 启动zabbix_server服务
zabbix_server
# 查看zabbix_server是否启动成功
netstat -lntp
6、配置apache和php
# 将前端文件拷贝到Apache响应目录下
cp -r ~/zabbix-4.0.3/frontends/php /var/www/html/zabbix
# 配置php.ini
cp /etc/php.ini{,.bak}
sed -i '/post_max_size =/ s/=.*M$/= 16M/g' /etc/php.ini
sed -i '/max_execution_time =/ s/=.*/= 300/g' /etc/php.ini
sed -i '/max_input_time =/ s/=.*/= 300/g' /etc/php.ini
sed -i '/date.timezone =/ adate.timezone = Asia/Shanghai' /etc/php.ini
cat /etc/php.ini |grep -E "post_max_size =|max_execution_time =|max_input_time =|date.timezone ="
# 授权
chown -R apache. /var/www/html/zabbix/conf/
ls -ld /var/www/html/zabbix/conf/
# 启动httpd
/etc/init.d/httpd restart
# 启动zabbix_agentd
zabbix_agentd
# 查看服务启动端口监听情况
netstat -lntp
7、添加开机自启动
chkconfig httpd on
chkconfig mysqld on
echo "/usr/local/sbin/zabbix_server" >>/etc/rc.local
echo "/usr/local/sbin/zabbix_agentd" >>/etc/rc.local