Centos 7 Zabbix 6.0 TimescaleDB 安装配置

Zabbix 6.0 TimescaleDB 安装配置
系统:Centos7
PHP: PHP 7.4.30
apache :httpd-2.4.6
PostgreSQL : 13
TimescaleDB: version 2.7.0
zabbix: zabbix-6.0.0beta3

1,TimescaleDB
TimescaleDB基于PostgreSQL数据库打造的一款时序数据库,插件化的形式部署,随着PostgreSQL的版本升级而升级,具备以下特点:
基于时序优化;
自动分片(按时间、空间自动分片(chunk));
全SQL接口;
支持垂直于横向扩展;
支持时间维度、空间维度自动分区。
空间维度指属性字段(例如传感器ID,用户ID等);
支持多个SERVER,多个CHUNK的并行查询。
分区在TimescaleDB中被称为chunk;
自动调整CHUNK的大小;
内部写优化(批量提交、内存索引、事务支持、数据倒灌);
复杂查询优化(根据查询条件自动选择chunk,最近值获取优化(最小化的扫描,类似递归收敛),limit子句pushdown到不同的;
server,chunks,并行的聚合操作);
利用已有的PostgreSQL特性(支持GIS,JOIN等),方便的管理(流复制、PITR);
支持自动的按时间保留策略(自动删除过旧数据);

Zabbix 从5.0版本开始全面支持TimescaleDB,并针对其特性做了优化。可自动压缩历史数据存储,节省50-70%的存储空间,同时具备自动分区功能。
通过Zabbix Housekeeper清理历史数据时直接清理对应的分区,大大提高了历史数据的清理效率。建议新建系统采用TimescaleDB方案。

2,初始化
yum update -y
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
systemctl disable --now firewalld
dnf install chrony wget -y
systemctl enable --now chronyd
setenforce 0

2,zabbix 6.0 yum源
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm

3,Zabbix DB 配置
本次使用PostgreSQL 13+TimescaleDB。
Zabbix 6.0目前支持PostgreSQL 13不支持最新的14版本,

安装PostgreSQL
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -qy module disable postgresql
yum install -y postgresql13-server

安装TimescaleDB
添加TimescaleDB源
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

安装TimescaleDB包
yum install timescaledb-2-postgresql-13 -y
配置
初始化PostgreSQL
/usr/pgsql-13/bin/postgresql-13-setup initdb
[root@aliyuan-ops-01 devops]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database … OK

启动PostgreSQL server
systemctl enable --now postgresql-13

添加TimescaleDB并配置参数
timescaledb-tune --pg-config=/usr/pgsql-13/bin/pg_config
会出现交互画面,一路y 即可,此步骤会根据当前机器配置,调整PostgreSQL配置参数,并加载Timescaledb插件库.
[root@aliyuan-ops-01 devops]# timescaledb-tune --pg-config=/usr/pgsql-13/bin/pg_config
Using postgresql.conf at this path:
/var/lib/pgsql/13/data/postgresql.conf

Is this correct? [(y)es/(n)o]: y
Writing backup to:
/tmp/timescaledb_tune.backup202206161750

shared_preload_libraries needs to be updated
Current:
#shared_preload_libraries = ‘’
Recommended:
shared_preload_libraries = ‘timescaledb’
Is this okay? [(y)es/(n)o]: y
success: shared_preload_libraries will be updated

Tune memory/parallelism/WAL and other settings? [(y)es/(n)o]: y
Recommendations based on 3.56 GB of available memory and 2 CPUs for PostgreSQL 13

Memory settings recommendations
Current:
shared_buffers = 128MB
#effective_cache_size = 4GB
#maintenance_work_mem = 64MB
#work_mem = 4MB
Recommended:
shared_buffers = 933394kB
effective_cache_size = 2734MB
maintenance_work_mem = 466697kB
work_mem = 9333kB
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: memory settings will be updated

Parallelism settings recommendations
Current:
missing: timescaledb.max_background_workers
#max_worker_processes = 8
#max_parallel_workers_per_gather = 2
#max_parallel_workers = 8
Recommended:
timescaledb.max_background_workers = 8
max_worker_processes = 13
max_parallel_workers_per_gather = 1
max_parallel_workers = 2
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: parallelism settings will be updated

WAL settings recommendations
Current:
#wal_buffers = -1
min_wal_size = 80MB
Recommended:
wal_buffers = 16MB
min_wal_size = 512MB
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: WAL settings will be updated

Miscellaneous settings recommendations
Current:
#default_statistics_target = 100
#random_page_cost = 4.0
#checkpoint_completion_target = 0.5
max_connections = 100
#max_locks_per_transaction = 64
#autovacuum_max_workers = 3
#autovacuum_naptime = 1min
#effective_io_concurrency = 1
Recommended:
default_statistics_target = 500
random_page_cost = 1.1
checkpoint_completion_target = 0.9
max_connections = 50
max_locks_per_transaction = 64
autovacuum_max_workers = 10
autovacuum_naptime = 10
effective_io_concurrency = 256
Is this okay? [(y)es/(s)kip/(q)uit]: y
success: miscellaneous settings will be updated
Saving changes to: /var/lib/pgsql/13/data/postgresql.conf
[root@aliyuan-ops-01 devops]#

重启PostgreSQL生效.

systemctl restart postgresql-13

建立Zabbix用户及数据库
sudo -u postgres createuser --pwprompt zabbix
此处是需要输入数据库zabbix用户的密码,输入二次后确认。此处配置密码为: zabbixpwd0616
后续zabbix server连接数据库使用这个密码,用户为zabbix
创建zabbix数据库

sudo -u postgres createdb -O zabbix zabbix

为Zabbix数据库启用TimescleDB插件

echo “CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;” | sudo -u postgres psql zabbix
systemctl restart postgresql-13
成功后会出现如下画面,表示配置完成。

[root@aliyuan-ops-01 zabbix-6.0.0beta3]# echo “CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;” | sudo -u postgres psql zabbix
could not change directory to “/root/devops/zabbix-6.0.0beta3”: Permission denied
WARNING:
WELCOME TO


|_ () | | | _ \ ___ \
| | _ _ __ ___ ___ ___ ___ __ | | | | | | |/ /
| | | | _ _ \ / _ \/ __|/ __/ _ | |/ _ \ | | | ___ \
| | | | | | | | | _/_ \ (
| (
| | | __/ |/ /| |
/ /
|| ||| || ||_||/__,|_|_|/ _/
Running version 2.7.0
For more information on TimescaleDB, please visit the following links:

  1. Getting started: https://docs.timescale.com/timescaledb/latest/getting-started
  2. API reference documentation: https://docs.timescale.com/api/latest
  3. How TimescaleDB is designed: https://docs.timescale.com/timescaledb/latest/overview/core-concepts

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescale.com/timescaledb/latest/how-to-guides/configuration/telemetry.

CREATE EXTENSION

下载
https://cdn.zabbix.com/zabbix/sources/development/6.0/zabbix-6.0.0beta3.tar.gz

tar zxvf zabbix-6.0.0beta3.tar.gz
cd zabbix-6.0.0beta3/database/postgresql/
useradd zabbix
依次按照顺序导入三个Zabbix sql文件

cat schema.sql |sudo -u zabbix psql zabbix
cat images.sql |sudo -u zabbix psql zabbix
cat data.sql |sudo -u zabbix psql zabbix

导入TimescleDB表配置sql
cat timescaledb.sql |sudo -u zabbix psql zabbix

导入成功后会后如下提示
[root@aliyuan-ops-01 postgresql]# cat timescaledb.sql |sudo -u zabbix psql zabbix
could not change directory to “/root/devops/zabbix-6.0.0beta3/database/postgresql”: Permission denied
NOTICE: PostgreSQL version 13.7 is valid
NOTICE: TimescaleDB extension is detected
NOTICE: TimescaleDB version 2.7.0 is valid
NOTICE: TimescaleDB is configured successfully
DO

修改配置允许远程连接
sed -i “s/#listen_addresses = ‘localhost’/listen_addresses = ‘*’/g” /var/lib/pgsql/13/data/postgresql.conf
sed -i ‘s/#port = 5432/port = 5432/g’ /var/lib/pgsql/13/data/postgresql.conf
sed -i ‘s/max_connections = 100/max_connections = 500/g’ /var/lib/pgsql/13/data/postgresql.conf
连接数修改成500,生产可根据实际情况修改。

配置使用md5方式认证
vi /var/lib/pgsql/13/data/pg_hba.conf
添加如下信息到# IPv4 local connections之后
host all all 0.0.0.0/0 md5

重启pgsql
systemctl restart postgresql-13

Zabbix Server
Zabbix Server使用源码编译方式安装,其他版本可参考此安装方式。

初始化
yum update -y
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
systemctl disable --now firewalld
yum --enablerepo=powertools install OpenIPMI-devel -y
yum install make wget chrony gcc curl-devel net-snmp-devel
libxml2-devel libevent-devel pcre-devel -y
setenforce 0 systemctl enable --now chronyd

由于后端采用PostgreSQL数据库,因此需要安装PostgreSQL的开发包。

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -qy module disable postgresql
yum install -y postgresql13-devel -y
编译
下载Zabbix Server源码

useradd zabbix
wget https://cdn.zabbix.com/zabbix/sources/development/6.0/zabbix-6.0.0beta3.tar.gz
tar zxvf zabbix-6.0.0beta3.tar.gz
cd zabbix-6.0.0beta3/
编译

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent
–with-postgresql=/usr/pgsql-13/bin/pg_config --with-net-snmp
–with-libcurl --with-libxml2 --with-openipmi

执行make

make
make install

配置
安装后,需要修改配置文件里的数据库连接信息
sed -i ‘s/# DBHost=localhost/DBHost=172.26.17.186/g’ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘s/# DBPassword=/DBPassword=zabbixpwd0616/g’ /usr/local/zabbix/etc/zabbix_server.conf

Zabbix 6.0增加了二个关于HA的配置参数,建议配置
sed -i ‘s/# HANodeName=/HANodeName=aliyuan-ops-01/g’ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘s/# NodeAddress=localhost:10051/NodeAddress=172.16.66.61:10051/g’ /usr/local/zabbix/etc/zabbix_server.conf
HANodeName修改为主机名,这里最好配置唯一;
NodeAddress为节点地址,这里配置为实际ip+默认的10050端口;
创建Zabbix Server启动脚本

tee /lib/systemd/system/zabbix-server.service <<EOL
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service

[Service]
Environment=“CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf”
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EOL

创建Zabbix Agent启动脚本
tee /lib/systemd/system/zabbix-agent.service <<EOL
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment=“CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf”
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target
EOL

启动
使用以下命令启动Zabbix Server及Zabbix Agent

systemctl enable --now zabbix-server
systemctl enable --now zabbix-agent
如启动异常,查看日志确认异常,日志位置/tmp/zabbix_server.log

Zabbix Web
Zabbix 6.0需要php最低版本为7.2,由于使用PostgreSQL,因此需要按照php的PostgreSQL扩展组件。

初始化
yum update -y
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
systemctl disable --now firewalld

配置PHP7 yum 源
安装EPEL和Remi存储库
如果要安装PHP7,首先需要在Centos7系统上安装并启用EPEL和Remi存储库

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装yum-utils
yum-utils 可以扩展yum的默认功能,用于管理yum存储库以及程序包,而无需进行任何手动配置,yum-utils提供的程序之一是yum-config-manager,
可以使用它来启用Remi存储库作为默认存储库,以安装不同的PHP版本。
yum install yum-utils

选择要安装的PHP7版本
yum-config-manager --enable remi-php74

这里我们选择安装PHP74的版本
yum-config-manager --enable remi-php74
yum install wget chrony httpd php php-pgsql php-xml php-ldap php-json php-gd php-mbstring php-bcmath langpacks-zh_CN.noarch -y
systemctl enable --now chronyd
setenforce 0

安装Web
下载Zabbix源码,并拷贝到对应目录

wget https://cdn.zabbix.com/zabbix/sources/development/6.0/zabbix-6.0.0beta3.tar.gz
tar zxvf zabbix-6.0.0beta3.tar.gz
cd zabbix-6.0.0beta3/ui
cp -raf * /var/www/html/

修改php参数,并启动Apache和php
sed -i ‘s/post_max_size = 8M/post_max_size = 16M/’ /etc/php.ini
sed -i ‘s/max_execution_time = 30/max_execution_time = 300/’ /etc/php.ini
sed -i ‘s/max_input_time = 60/max_input_time = 300/’ /etc/php.ini
chown -R apache:apache /var/www/html/
systemctl enable --now httpd
systemctl enable --now php-fpm
Web初始化
浏览器输入Web IP地址:http://xx.xx.xx.xx/
设置,语言,数据库,时区

使用默认的帐号密码登陆,帐号:Admin 密码:zabbix

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值