导航

CentOS7:安装Zabbix

Posted on 2016-11-17 08:51  eastson  阅读(1471)  评论(0编辑  收藏  举报

参考:CentOS 7 yum安装Zabbix

1. 安装Zabbix Server

EPEL源里面有Zabbix的安装包,所以需要先安装EPEL。

Zabbix源也可以从这里获得:http://repo.zabbix.com/

$ yum install epel-release

安装Zabbix Server:

$ yum install zabbix22-server-mysql zabbix22-web-mysql 

安装Zabbix Agent(可选): 

$ yum install zabbix22-agent

 2. 安装MySql Server

先安装MySQL源。从下面网址可以找到对应的MySQL源:

http://dev.mysql.com/downloads/repo/yum/

安装MySQL源:

yum install http://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm

安装MySQL Server:

$ yum install mysql-community-server

启动MySQL Server:

$ systemctl enable mysqld.service
$ systemctl start mysqld.service

3. 创建Zabbix数据库和用户

使用root用户登录mysql:

$ mysql -u root -p mysql

创建zabbix数据库:

mysql> create database zabbix character set utf8;

创建Zabbix用户并授权:

mysql> create user 'zabbix'@'localhost' identified by 'zabbix';

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';

mysql> flush privileges;

 4. 导入zabbix template

使用zabbix用户登录zabbix数据库:

$ mysql -u zabbix -p zabbix

导入zabbix template:

mysql> source /usr/share/zabbix-mysql/schema.sql
mysql> source /usr/share/zabbix-mysql/images.sql
mysql> source /usr/share/zabbix-mysql/data.sql

5.修改Zabbix Server配置

编辑/etc/zabbix/zabbix_server.conf,修改数据库相关选项:

$ vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306

6.修改Zabbix Agent配置

编辑/etc/zabbix/zabbix_agent.conf,修改Server选项:

$ vi /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=127.0.0.1

7.修改PHP配置

编辑/etc/php.ini:

$ vi /etc/php.ini
max_execution_time = 600
max_input_time = 600
memory_limit = 256
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Shanghai

8. 启动服务

修改Firewall,开放zabbix端口10050 and 10051:

$ firewall-cmd --permanent --add-port=10050/tcp
$ firewall-cmd --permanent --add-port=10051/tcp
$ systemctl restart firewalld.service

如果使用 SELinux, 运行以下命令使 Apache 可以和 Zabbix通信:

$ setsebool -P httpd_can_connect_zabbix=1

启动相关服务:

$ systemctl enable zabbix-servermysql.service
$ systemctl enable zabbix-agent.service
$ systemctl enable mysqld.service
$ systemctl enable httpd.service

$ systemctl start zabbix-server-mysql.service
$ systemctl start zabbix-agent.service
$ systemctl restart httpd.service
$ systemctl restart mysqld.service

9.通过控制台访问Zabbix Server

浏览器访问http://ip-address/zabbix:

按照提示进行安装。安装完成后,重定向到zabbix控制台登录页面. 输入用户名和密码,默认的用户名和密码为admin/zabbix.

A1. MySQL一些问题

MySQL初始root密码不对,不能登录。用下面方式重置密码:

$ systemctl stop mysqld.service

$ mysqld-debug --user=mysql --skip-grant-tables --skip-networking &

$ mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
如果没有Password列,就用authentication_string列
mysql> update user set authentication_string=password('root') where user='root' ;
mysql> flush privileges;
mysql> exit;

执行MySQL语句时,提示必须先执行ALTER USER重置密码:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

按下面方式处理:

mysql> SET PASSWORD = PASSWORD('your new password');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;

MySQL5.6.6增加了密码强度验证插件validate_password。使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。可以禁用该插件:

# /etc/my.cnf,需要重启服务
validate_password=off