环境
- CentOS 6.x
- Nginx
- MySQL
- PHP
部署主机
安装 Zabbix-Agent
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
or
rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum clean all
yum install -y zabbix-agent
被动模式
vi /etc/zabbix/zabbix_agentd.conf
Server=1.2.3.4
ListenPort=10050
ListenIP=0.0.0.0
被动模式记得放行 10050 端口
/sbin/iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
/sbin/iptables -I INPUT -p udp --dport 10050 -j ACCEPT
主动模式
Agent 主动模式不监听 10050 端口 nano /etc/zabbix/zabbix_agentd.conf
grep '^StartAgents=\|^ServerActive=\|^Hostname=' /etc/zabbix/zabbix_agentd.conf
StartAgents=0
ServerActive=zabbix-server.domain:10051
Hostname=zabbix-agent.domain
systemctl restart zabbix-agent
systemctl enable zabbix-agent
systemctl status zabbix-agent
部署服务器
安装 Server 与 Web 前端
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
或 vi /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/6/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
yum install -y zabbix-server-mysql zabbix-web-mysql
导入数据库模板
mysql -uroot -p
<Enter 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
修改 Zabbix 配置
vi /etc/zabbix/zabbix_server.conf
ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password>
DBSocket=/var/lib/mysql/mysql.sock
启动 Zabbix Server service zabbix-server start
Starting Zabbix server: [ OK ]
chkconfig zabbix-server on
修改前端目录权限
修改前端目录与 maintenance.inc.php 所在目录的权限
chown -R www-data:www-data /etc/zabbix
chown -R www-data:www-data /usr/share/zabbix
Nginx 配置
修改 php_fastcgi.conf 配置,增加前端相关目录的权限:
/etc/zabbix/web/
/usr/share/zabbix/
vi /etc/nginx/others/php_fastcgi.conf
将
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/";
修改为
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/:/usr/share/zabbix/:/etc/zabbix/web/";
nginx -s reload
PHP 配置
安装 Zabbix 依赖的扩展并设置相关参数
service php-fpm stop
yum install -y php-bcmath php-xmlwriter php-xmlreader
vi /etc/php.ini
memory_limit = 128M
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
service php-fpm start
chown -R www-data /dev/shm
chown -R www-data /var/lib/php/session
Web 前端默认登陆用户名:Admin,密码:zabbix 。
邮件报警设置
Zabbix Server 自带邮件报警功能需要 curl 7.20 及更新的版本支持,同时编译时需要 -with-libcurl 参数。CentOS 6 自带的 curl 为 7.19 版本,另外 Zabbix Server 也是安装的二进制文件。避免升级 curl 与重新编译安装 Zabbix Server,还是使用 Python 脚本来实现推送邮件报警功能。
创建脚本
vi /usr/lib/zabbix/alertscripts/mail.py
#!/usr/bin/python
# coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_user = 'xxxxxxxx@gmail.com'
mail_pass = 'xxxxxxxx'
def send_mail(to_list,subject,content):
me = "Zabbix Alert"+"<"+mail_user+">"
msg = MIMEText(content,_charset="utf-8")
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP_SSL("smtp.gmail.com", 465)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
chmod +x /usr/lib/zabbix/alertscripts/mail.py
测试一下
/usr/lib/zabbix/alertscripts/mail.py user@gmail.com "Alert Mail Title" "Alert Mail Content"
添加报警媒介
Zabbix > 管理 > 报警媒介类型 > 创建媒体类型
名称:邮件报警
类型:脚本
脚本名称:mail.py
添加脚本参数:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
点击“更新保存”即可。
Debian 部署 5.0 TLS
- Install Zabbix repository
wget https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/zabbix-release_5.0-2+debian11_all.deb
dpkg -i zabbix-release_5.0-2+debian11_all.deb
- Install Zabbix server, frontend
apt update
apt install zabbix-server-mysql zabbix-frontend-php
- Create initial database
mysql -uroot -p
<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by '1Qaz2Wsx!zabbix';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password.
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
or
zcat /usr/share/zabbix-server-mysql/schema.sql.gz | mysql -uzabbix -p zabbix
Disable log_bin_trust_function_creators option after importing database schema.
mysql -uroot -p
<password>
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
- Configure the database for Zabbix server
# nano /etc/zabbix/zabbix_server.conf
DBPassword=1Qaz2Wsx!zabbix
DBHost=localhost
DBPort=3306
# DBSocket=/var/run/mysqld/mysqld.sock
systemctl start zabbix-server
systemctl enable zabbix-server
- frontend
cp -R /usr/share/zabbix /var/www/benhon.net/
chown -R www-data:www-data /var/www/benhon.net
nano /etc/php/7.4/fpm/php.ini
memory_limit = 128M
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
systemctl restart php7.4-fpm
nano /etc/nginx/others/php_fastcgi.conf
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/";
>
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$base/:/usr/lib/php/:/tmp/:/usr/share/zabbix/:/etc/zabbix/web/";
nano /etc/nginx/conf.d/benhon.net.conf
location /zabbix {
auth_basic "Authorized";
auth_basic_user_file /etc/nginx/htpasswd.conf;
}
nano /etc/nginx/htpasswd.conf
benhon:$apr1$t4iap2fb$N0rnU6C98bgsaCDwWjxca0
nginx -t && nginx -s reload
locale -a
nano /etc/locale.gen
zh_CN.UTF-8 UTF-8
locale-gen
systemctl restart zabbix-server
reboot
Default username and password: Admin:zabbix
版权声明:本文为原创文章,版权归 BenhoN 所有。
本文链接:https://blog.benhon.net/archives/install_and_config_zabbix_on_centos_6.html
所有原创文章采用知识共享 署名-非商业性使用 4.0 国际 许可协议进行许可,你可以自由地转载和修改,但请务必注明文章来源并且不可用于商业目的。