CentOS7下Zabbix5.0+PostgreSQL12+TimescaleDB部署实践
一、Zabbix Server 安装
1、YUM源配置及基础环境准备
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
常用软件安装
yum install -y lrzsz bash-completion vim wget net-tools ncdu iftop
关闭SELINUX
setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
2、zabbix源配置并安装Zabbix Server
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm sed -i "s#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#g" /etc/yum.repos.d/zabbix.repo yum clean all yum install zabbix-server-pgsql zabbix-agent
3、安装zabbix web
yum install centos-release-scl sed -i "s/enabled=0/enabled=1/g" /etc/yum.repos.d/zabbix.repo yum install zabbix-web-pgsql-scl zabbix-nginx-conf-scl
4、安装数据库PostgreSQL12
wget https://mirrors.aliyun.com/postgresql/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm rpm -ivh pgdg-redhat-repo-latest.noarch.rpm sed -i "s#https://download.postgresql.org/pub/#https://mirrors.aliyun.com/postgresql/#g" /etc/yum.repos.d/pgdg-redhat-all.repo yum install -y postgresql12-server
PostgreSQL数据库初始化
/usr/pgsql-12/bin/postgresql-12-setup initdb systemctl enable --now postgresql-12 systemctl status postgresql-12.service
5、TimescaleDB安装与配置
先配置timesacledb源
tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL [timescale_timescaledb] name=timescale_timescaledb baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$basearch repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 EOL
yum方式安装timesacleDB
yum install -y timescaledb-postgresql-12
注意这里yum方式安装里会默认安装timescaledb-2-loader-postgresql-12-2.4.0-0.el7.x86_64这个包
而timescaledb-postgresql-12为1.7.5版本
需要降级timescaledb-2-loader-postgresql 为1.7.5版本
可以手动官网下载1.7.5版本并进行安装
yum remove timescaledb-2-loader-postgresql-12-2.4.0-0.el7.x86_64 rpm -ivh timescaledb-loader-postgresql-12-1.7.5-0.el7.x86_64.rpm yum install -y timescaledb-postgresql-12
脚本进行参数初始化并重启postgresql
timescaledb-tune --pg-config=/usr/pgsql-12/bin/pg_config systemctl restart postgresql-12
6、zabbix数据库创建与数据库脚本导入
创建初始zabbix数据库并导入
创建zabbix用户设置密码 sudo -u postgres createuser --pwprompt zabbix 创建zabbix数据库 sudo -u postgres createdb -O zabbix zabbix
开启timescaledb 插件
echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
导入zabbix的postgresql和timescaledb数据库脚本
zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | sudo -u zabbix psql zabbix zcat /usr/share/doc/zabbix-server-pgsql*/timescaledb.sql.gz | sudo -u zabbix psql zabbix
7、postgresql数据库远程连接与认证配置
PostgreSQL不支持远程连接,修改配置文件,添加或修改如下
vim /var/lib/pgsql/12/data/postgresql.conf listen_addresses = '*’ port = 5432 max_connections = 500
配置使用md5方式认证
vim /var/lib/pgsql/12/data/pg_hba.conf host all all 0.0.0.0/0 md5
修改完成后重启postgresql-12
systemctl restart postgresql-12
修改zabbix server配置文件中的数据库信息
vim /etc/zabbix/zabbix_server.conf DBHost=127.0.0.1 DBPassword=zabbix@2021
8、修改php参数和nginx配置文件
vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 主要修改时区和ACL listen.acl_users = apache,nginx php_value[date.timezone] = Asia/Shanghai
cd /etc/opt/rh/rh-nginx116/nginx/ vim nginx.conf 默认的80端口修改为81
vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf 取消注释,使用80端口
9、重启所有服务并配置开机自启动
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 firewall-cmd --permanent --zone=public --add-port=10051/tcp firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --permanent --zone=public --add-port=5432/tcp firewall-cmd --reload
二、Zabbix5.0 Web界面初始化
注意Database host 要由localhost改为127.0.0.1
默认密码Admin/zabbix
三、Zabbix5.0 Agent安装
1、zabbix agent安装
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm sed -i "s#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#g" /etc/yum.repos.d/zabbix.repo yum install zabbix-agent
2、修改配置文件
修改配置文件中Server和ServerActive地址
sed -i "s/Hostname=Zabbix server/Hostname=centos.walkingcloud.cn/g" /etc/zabbix/zabbix_agentd.conf sed -i "s/ServerActive=127.0.0.1/ServerActive=192.168.31.232/g" /etc/zabbix/zabbix_agentd.conf sed -i "s/Server=127.0.0.1/Server=192.168.31.232/g" /etc/zabbix/zabbix_agentd.conf cat /etc/zabbix/zabbix_agentd.conf | grep Server= cat /etc/zabbix/zabbix_agentd.conf | grep ServerActive= cat /etc/zabbix/zabbix_agentd.conf | grep Hostname=
3、启动zabbix-agent相关服务并设置为开机自启动
zabbix-agent需要在防火墙中放通10050端口
firewall-cmd --permanent --zone=public --add-port=10050/tcp firewall-cmd --reload systemctl enable zabbix-agent systemctl start zabbix-agent systemctl status zabbix-agent tail -f /var/log/zabbix/zabbix_agentd.log
4、ZabbixServer Web上添加主机
5、验证Agent数据是否正常采集
总结:本次部署主要使用 PostgreSQL12+TimescaleDB,安装配置比较多,对比MySQL数据库部署的方式,性能是否有大的提升,还需要后续进行测试和验证