1. 安装Zabbix服务
1.1 下载
去Zabbix官网选择需要下载的系统和版本,然得到一个对应rpm包地址。
这里以 CentOS 7 安装5.0LTS版,MySQL数据库 + Nginx网页服务器为例
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all
1.2 安装Zabbix 服务器和客户端
# yum install zabbix-server-mysql zabbix-agent
1.3 安装前端
- 启用系统软件集
# yum install centos-release-scl
- 编辑配置文件
/etc/yum.repos.d/zabbix.repo
启用 zabbix-frontend
[zabbix-frontend]
...
enabled=1
...
- 安装zabbix前端库
# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
- 若本地有Nginx服务可以不安装
zabbix-nginx-conf-scl
1.4 创建初始数据库
在主机上安装并运行MySQL数据库,然后创建zabbix相关数据库
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
1.5 为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
,修改数据库密码
DBPassword=password
1.6 为Zabbix前端配置PHP
编辑nginx配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
,修改监听端口和服务器名。
# listen 80;
# server_name zabbx.zngw.icu;
- 如果本地有Nginx服务,在Nginx配置的conf.d目录下创建zabbix.conf文件
server {
listen 80;
server_name zabbx.zngw.icu;
root /usr/share/zabbix;
index index.php;
location = /favicon.ico {
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /\.ht {
deny all;
}
location ~ /(api\/|conf[^\.]|include|locale) {
deny all;
return 404;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock;
# fastcgi_pass unix:/var/opt/rh/rh-php73/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /usr/share/zabbix;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
- 编辑PHP配置文件
/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
添加Nginx
listen.acl_users = apache,nginx
修改时间区为上海
php_value[date.timezone] = Asia/Shanghai
1.7 启动Zabbix server和agent进程
# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
如果启动有问题,后面会将到防火墙及Selinux的设置
1.8 配置Zabbix前端
连接到新安装的Zabbix前端: http://server_ip_or_name
页面上就简单了,除了要填写一下数据库的账号和密码外,基本就是一路next到完成。
默认登录账号为:Admin,密码为:zabbix
1.9 单独安装Zabbix客户端
1.9.1 设置rpm
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all
1.9.2 安装Zabbix 客户端
# yum install zabbix-agent
1.9.3 配置客户端
编辑配置文件/etc/zabbix/zabbix_agentd.conf
Server=zabbix服务端ip地址,多个可以用','号分割,如果不限定服务器ip用0.0.0.0/0
ServerActive=zabbix主动推送服务端ip地址,同Server一样配置
Hostname=zabbix在web界面配置的Host名称
1.9.4 启动Zabbix agent进程
# systemctl restart zabbix-agent
# systemctl enable zabbix-agent
2. 防火墙设置
- Nginx 默认端口 80/443
- zabbix-agent 默认端口 10050
- zabbix-server 默认端口10051
# firewall-cmd --permanent --zone=public --add-port=80/tcp
# firewall-cmd --permanent --zone=public --add-port=443/tcp
# firewall-cmd --permanent --zone=public --add-port=10051/tcp
# firewall-cmd --permanent --zone=public --add-port=10050/tcp
# firewall-cmd --reload
3. Selinux设置
3.1 安装Selinux相关工具包
# yum install policycoreutils checkpolicy setroubleshoot-server -y
3.2 创建zabbix-selinux目录
# mkdir -p ~ /zabbix-selinux
# cd ~ /zabbix-selinux /
3.3 创建zabbix_server_add.te文件
module zabbix_server_add 1.1;
require {
type zabbix_var_run_t;
type tmp_t;
type zabbix_t;
class sock_file { create unlink write };
class unix_stream_socket connectto;
class process setrlimit;
class capability dac_override;
}
#============= zabbix_t ==============
#!!!! This avc is allowed in the current policy
allow zabbix_t self:process setrlimit;
#!!!! This avc is allowed in the current policy
allow zabbix_t self:unix_stream_socket connectto;
#!!!! This avc is allowed in the current policy
allow zabbix_t tmp_t:sock_file { create unlink write };
#!!!! This avc is allowed in the current policy
allow zabbix_t zabbix_var_run_t:sock_file { create unlink write };
#!!!! This avc is allowed in the current policy
allow zabbix_t self:capability dac_override;
3.4 用checkmodule 转换为Selinux模块
# checkmodule -M -m -o zabbix_server_add.mod zabbix_server_add.te
3.5 用semodule_package 编译zabbix_server_add.mod
# semodule_package -m zabbix_server_add.mod -o zabbix_server_add.pp
3.6 应用zabbix_server_add模块
# semodule -i zabbix_server_add.pp
3.7 设置一些变量
# setsebool -P httpd_can_network_connect 1
# setsebool -P httpd_can_connect_zabbix 1
# setsebool zabbix_can_network on
4. 页面出现中文乱码
语言设置为中文时,页面乱码如图,有小方块。这是应为zabbix使用的字体没有中文导致的,替换调就可以了。
4.1 获取中文字体
去下载或系统中找一个带中文的ttf字体。这里用 阿里巴巴普惠体 Alibaba-PuHuiTi-Medium.ttf
4.2 复制到zabbix字体目录
将字体文件 Alibaba-PuHuiTi-Medium.ttf
复制到目录/usr/share/zabbix/assets/fonts
4.3 修改配置脚本
编辑修改PHP配置文件/usr/share/zabbix/include/defines.inc.php
,找到字体修改
...
define('ZBX_GRAPH_FONT_NAME', 'Alibaba-PuHuiTi-Medium'); // font file name
...
define('ZBX_FONT_NAME', 'Alibaba-PuHuiTi-Medium');
...