安装zabbix小记

zabbix server安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#检查并安装gcc
isInstallGcc=`rpm -qa | grep ^gcc`
[ -z "$isInstallGcc" ] && yum install gcc -y

#安装依赖环境
yum install curl curl-devel net-snmp net-snmp-devel perl-DBI ntddate libxml2-devel
#时间同步
#此处有坑,必须同步!否则无法安装
ntpdate time.nist.gov
#添加zabbix用户
useradd zabbix

#安装mariadb数据库并导入数据
yum install mariadb mariadb-server mariadb-devel -y
systemctl start mariadb
systemctl enable mariadb
mysqladmin -uroot password 'mysqlpassword'
mysql -uroot -pmysqlpassword
1
2
3
4
5
6
7
create database zabbix default character set utf8;
grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
grant all privileges on zabbix.* to zabbix@127.0.0.1 identified by 'zabbix';
delete from user where user='';
flush privileges;
exit
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
#解压并安装zabbix
tar xf zabbix-3.2.4.tar.gz && cd zabbix-3.2.4
mysql -uzabbix -pzabbix zabbix < /root/zabbix/database/mysql/schema.sql
mysql -uzabbix -pzabbix zabbix < /root/zabbix/database/mysql/images.sql
mysql -uzabbix -pzabbix zabbix < /root/zabbix/database/mysql/data.sql
#创建zabbix agent日志目录,并授权zabbix用户
mkdir /var/log/zabbix/ && chown zabbix:zabbix /var/log/zabbix

#解压并安装zabbix
tar xf zabbix-3.2.4.tar.gz && cd zabbix-3.2.4
./configure --sysconfdir=/opt/zabbix --enable-server --enable-agent --with-net-snmp --enable-java --with-libxml2 --with-libcurl --with-mysql
make && make install

#参照如下参数修改zabbix server
LogFile=/var/log/zabbix/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
Timeout=4
AlertScriptsPath=/opt/zabbix/scripts
LogSlowQueries=3000
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=5

#拷贝启动文件并
cp /root/zabbix/misc/init.d/fedora/core//zabbix_agentd /etc/init.d/
cp /root/zabbix/misc/init.d/fedora/core/zabbix_server /etc/init.d/
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start

zabbix web安装

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
#添加并更新yum源
#此处有坑,默认php是php5.4版本,有些库不支持,需要php56以上版本,需要更新yum源安装php5.6版本
tar xf rhel7_repo.tar.gz -C /etc/yum.repos.d/
yum clean all && yum repolst

#安装php环境
yum install httpd php56w php56w-devel php56w-pdo php56w-gd php56w-mysql php56w-common php56w-mbstring php56w-odbc php56w-xml php56w-bcmath php56w-pear

#修改php配置
vim /etc/php.ini
#配置如下
max_execution_time=300
memory_limit=128M
post_max_size=16M
upload_max_filesize=2M
max_input_time=300
date.timezone="Asia/Shanghai"
always_populate_raw_post_data=-1

#拷贝zabbi web到httpd目录
cp -a /root/zabbix/frontends/php/* /var/www/html

#启动httpd
systemctl start httpd
systemctl enable httpd

zabbix agent安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
#检查并安装gcc
isInstallGcc=`rpm -qa | grep ^gcc`
[ -z "$isInstallGcc" ] && yum install gcc -y

#添加zabbix用户
useradd zabbix

#创建zabbix agent日志目录,并授权zabbix用户
mkdir /var/log/zabbix/ && chown zabbix:zabbix /var/log/zabbix

#解压并安装zabbix
tar xf zabbix-3.2.4.tar.gz && cd zabbix-3.2.4
./configure --sysconfdir=/opt/zabbix_agent --enable-agent
make install

#拷贝启动文件和zabbix配置文件到相应目录
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp ../zabbix_agentd.conf /opt/zabbix_agent

#启动zabbix客户端
/etc/init.d/zabbix_agentd start

zabbix proxy安装

1
2
3
4
5
6
7
8
9
10
11
#解压并安装zabbix proxy
tar xf zabbix-3.2.4.tar.gz && cd zabbix-3.2.4
yum install gcc curl-devel libxml2-devel net-snmp-devel perl-DBI ntpdate -y
./configure --sysconfdir=/opt/zabbix --enable-proxy --enable-agent --with-net-snmp --with-libxml2 --with-libcurl --with-mysql
make install

#安装mauradb并修改密码
yum install mariadb mariadb-devel mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysqladmin -uroot password 'password'

创建数据库

1
2
3
4
create database zabbix_proxy default character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
exit

导入表结构

1
2
mysql -uzabbix -p zabbix_proxy < database/mysql/schema.sql
mysql -uzabbix -p zabbix_proxy < database/mysql/schema.sql

zabbix proxy配置参考

1
2
3
4
5
6
7
8
9
10
Server=1.1.1.1
Hostname=proxysh
LogFile=/tmp/zabbix_proxy.log
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=zabbix
ConfigFrequency=60
DataSenderFrequency=60
Timeout=4
LogSlowQueries=3000

1
2
#启动zabbixproxy
zabbix_proxy
0%