01 zabbix yum 安装


1
2
3
4
参考:
https://www.zabbix.com/documentation/3.4/zh/manual/installation/install_from_packages
https://www.zabbix.com/download?zabbix=3.0&os_distribution=centos&os_version=7&db=mysql
https://www.cnblogs.com/luoahong/articles/10557723.html

环境准备

修改时区

1
2
timedatectl set-timezone Asia/Shanghai
timedatectl status

同步时间

1
2
3
4
5
6
yum install ntpdate -y
ntpdate tiger.sina.com.cn
ping tiger.sina.com.cn

crontab -e
0 3 * * * /usr/sbin/ntpdate -s tiger.sina.com.cn

常用工具安装

1
2
3
4
5
cd /etc/yum.repos.d
mkdir bak;mv *.repo bak/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y net-tools vim wget lrzsz tree screen lsof tcpdump

关闭防火墙和selinux

1
2
systemctl disable firewalld
systemctl stop firewalld
  • 关闭selinux
1
2
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
getenforce

搭建运行环境

安装所需软件

1
yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
1
rpm -qa httpd php mariadb            #安装完成后检查应用版本

编辑httpd

1
2
3
4
vi /etc/httpd/conf/httpd.conf

ServerName www.zabbix.com #修改为主机名
DirectoryIndex index.html index.php # 添加首页支持格式

编辑配置php,配置中国时区

1
2
vim /etc/php.ini
date.timezone = PRC # 配置时区

启动httpd,mysqld

1
2
3
4
5
6
7
8
9
#启动并加入开机自启动httpd
systemctl start httpd
systemctl enable httpd
systemctl status httpd

#启动并加入开机自启动mariadb
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

创建一个测试页,测试LAMP是否搭建成功

1
2
3
4
5
6
# 创建一个测试页,并编辑
vim /var/www/html/index.php

<?php
phpinfo()
?>

初始化mysql数据库,并配置root用户密码

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
# 设置数据库root密码
mysqladmin -u root password 123456

# root用户登陆数据库
mysql -u root -p

# 创建zabbix数据库(中文编码格式)
CREATE DATABASE zabbix character set utf8 collate utf8_bin;

# 有空用户名称占用导致本地无法登录远程可登录
select user,host from mysql.user;

# 删除空用户
drop user ''@localhost;

# 授予zabbix用户zabbix数据库的所有权限,密码123456
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123456';
GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY '123456';
GRANT all ON zabbix.* TO 'zabbix'@'linux-node2.example.com' IDENTIFIED BY '123456';

# 刷新权限
flush privileges;
exit

# 测试登录
mysql -uzabbix -p123456

测试mysql与php连接

1
2
3
4
5
6
7
[root@ fonts]# vim /var/www/html/server.php
<?php
$link=mysql_connect('10.0.0.161','zabbix','123456');
if($link) echo "<h1>Success!!</h1>"; #显示Success表示连接数据库成功
else echo "Fail!!";
mysql_close();
?>

安装zabbix

安装依赖包 + 组件

1
2
# 依赖包
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*
1
2
3
4
5
6
7
8
# 组件
# 安装php支持zabbix组件
yum install php-bcmath php-mbstring -y

# 选择了官方源
# 安装zabbix组件
rpm -Uvh https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

导入数据 到数据库zabbix

1
2
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:

配置数据库和用户名密码

1
2
vim  /etc/zabbix/zabbix_server.conf 
DBPassword=password

修改时区

1
2
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai

启动服务

1
2
3
4
5
6
# 启动并加入开机自启动zabbix-server
systemctl restart zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd

# 端口检查 10051
netstat -anpt | grep zabbix

web界面安装zabbix

chrome浏览器 打开

1
http://10.0.0.161/zabbix/

菜单栏中文

将zabbix server 加入到监控