CentOS7安装zabbix分布式监控软件

以下为在同一台机器(localhost)上安装zabbix-server、zabbix-agent,均使用部署包安装。

一、配置LAMP环境

# yum install httpd httpd-devel mariadb mariadb-server mariadb-devel php php-devel php-mysql -y

# systemctl restart httpd

# systemctl restart mariadb

# systemctl enable httpd

# systemctl enable mariadb

二、升级php

升级软件仓库:

# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

删除php:

# yum remove php-common -y

安装php5.6:

# yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring

重新启动httpd:

# systemctl restart httpd

三、初始化数据库服务程序

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current password for the root user.  If you’ve just installed MariaDB, and you haven’t set the root password yet, the password will be blank, so you should just press enter here.

Enter current password for root (enter for none): 当前数据库密码为空,直接敲击回车。

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.

Set root password? [Y/n] y

New password: 输入要为root用户设置的数据库密码。

Re-enter new password: 重复再输入一次密码。

Password updated successfully!

Reloading privilege tables..

… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them.  This is intended only for testing, and to make the installation go a bit smoother.  You should remove them before moving into a production environment.

Remove anonymous users? [Y/n] y(删除匿名帐号)

… Success!

Normally, root should only be allowed to connect from ‘localhost’.  This ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y(禁止root用户从远程登陆)

… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can access.  This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? [Y/n] y(删除test数据库并取消对其的访问权限)

– Dropping test database…

… Success!

– Removing privileges on test database…

… Success!

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? [Y/n] y(刷新授权表,让初始化后的设定立即生效)

… Success!

Cleaning up…

All done!  If you’ve completed all of the above steps, your MariaDB installation should now be secure.

Thanks for using MariaDB!

四、从部署包安装zabbix

大多数主流的操作系统分发版本都提供了Zabbix部署包,你可以使用这些部署包安装Zabbix。以下为CentOS7为例:(操作系统分发版本的源码库中可能会缺少Zabbix的最新版本)

安装源码库配置部署包

安装源码库配置部署包,这个部署包包含了yum配置文件。(文件名以最新文件名为准,下同)

# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

安装Zabbix-server

安装Zabbix部署包。以下是使用Mysql数据库安装Zabbix server、WEB前端的示例。(Zabbix官方源码库也提供fping,iksemel,libssh2部署包这些包位于non-supported目录)

# yum install zabbix-server-mysql zabbix-web-mysql

安装Zabbix Agent

# yum install zabbix-agent

安装初始化数据库

在MySQL上安装Zabbix-server使用的数据库:

shell> mysql -uroot -p<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> quit;

然后导入初始架构(Schema)和数据:

# cd /usr/share/doc/zabbix-server-mysql-3.4.14
# zcat create.sql.gz | mysql -uroot Zabbix -p<password>

配置Zabbix Server

在zabbix_server.conf中编辑数据库配置

# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=<password>

启动zabbix-server、zabbix-agent进程

# systemctl start zabbix-server
# systemctl enable zabbix-server
# systemctl start zabbix-agent
# systemctl enable zabbix-agent

编辑Zabbix前端的PHP配置

Zabbix前端的Apache配置文件位于 /etc/httpd/conf.d/zabbix.conf,通常这些设置已经完成。

# vi /etc/httpd/conf.d/zabbix.conf
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai

在配置文件更改后,需要重启Apache Web服务器。

# systemctl restart httpd

通过web界面完成相关设置

Zabbix前端可以在浏览器中通过 http://zabbix-frontend-hostname/zabbix 进行访问,填入相关信息即可。默认的用户名/密码为Admin/zabbix,登录后可看到一默认存在主机zabbix server,查看状态:

zabbix监控图像

五、zabbix-server is not running 解决方案

官方解决方案:(测试无效,有待考证)

SELinux configuration

Having SELinux status enabled in enforcing mode, you need to execute the following commands to enable communication between Zabbix frontend and server:

RHEL 7 and later:

# setsebool -P httpd_can_connect_zabbix on
If the database is accessible over network (including 'localhost' in case of PostgreSQL), you need to allow Zabbix frontend to connect to the database too:
# setsebool -P httpd_can_network_connect_db on

RHEL prior to 7:

# setsebool -P httpd_can_network_connect on
# setsebool -P zabbix_can_network on

As frontend and SELinux configuration is done, you need to restart Apache web server:

# service httpd restart

替代方案:关闭防火墙和selinux

# systemctl stop firewalld
# systemctl disable firewalld
# systemctl status firewalld
# vi /etc/selinux/config
SELINUX=disabled
# reboot

发表评论

电子邮件地址不会被公开。