Moment For Technology

Deployment practice of Zabbix5.0+PostgreSQL12+TimescaleDB in CentOS7

Posted on Dec. 3, 2022, 9:53 a.m. by 鄧志豪
Category: The back-end Tag: centos The back-end

Deployment practice of Zabbix5.0+PostgreSQL12+TimescaleDB in CentOS7

(Click to enlarge the picture to view)

Install Zabbix Server

1. Configure the YUM source and prepare the basic environment

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 
Copy the code

Common Software Installation

yum install -y lrzsz bash-completion vim wget net-tools ncdu iftop
Copy the code

Close the SELINUX

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
Copy the code

2. Zabbix source Configure and install zabbix Server

The RPM - sed Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm - 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-agentCopy the code

(Click to enlarge the picture to view)

Install 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
Copy the code

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

Install the PostgreSQL12 database

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
Copy the code

(Click to enlarge the picture to view)

Description The PostgreSQL database is initialized

/usr/pgsql-12/bin/postgresql-12-setup initdb 
systemctl enable --now postgresql-12 
systemctl status postgresql-12.service 
Copy the code

(Click to enlarge the picture to view)

5. Install and configure TimescaleDB

Configure the TimesacleDB source first

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
Copy the code

Install timesacleDB\ using yum

yum install -y timescaledb-postgresql-12
Copy the code

(Click to enlarge the picture to view)

\

(Click to enlarge the picture to view)

\

Note that the timEscaledb-2-loader-PostgresqL-12-2.4.0-0.el7.x86_64 package is installed by default in the yum installation

The timEscaledb-PostgresQL-12 version is 1.7.5

You need to degrade timEscaledB-2-loader-PostgresQL to 1.7.5

You can manually download version 1.7.5 from the official website and install it

(Click to enlarge the picture to view)

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-12Copy the code

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

The script initializes parameters and restarts PostgresQL

timescaledb-tune --pg-config=/usr/pgsql-12/bin/pg_config
systemctl restart postgresql-12
Copy the code

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

6. Zabbix database creation and database script import

Create an initial Zabbix database and import it

Createuser zabbix. Set password sudo -u postgres createuser --pwprompt zabbix creates database zabbix. Sudo -u postgres createdb -o zabbix zabbixCopy the code

(Click to enlarge the picture to view)

Enable timEscaledb plugin \

echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
Copy the code

(Click to enlarge the picture to view)

Import the PostgresQL and TimEscaledb database scripts of Zabbix

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
Copy the code

(Click to enlarge the picture to view)

7. Configure postgresQL database remote connection and authentication

PostgreSQL does not support remote connections. Modify the configuration file by adding or modifying it as follows

12 / vim/var/lib/PGSQL/data/postgresql conf line like listen_addresses = '*' port = 5432 max_connections = 500Copy the code

(Click to enlarge the picture to view)

Configure md5 authentication \

12 / vim/var/lib/PGSQL/data/pg_hba conf host all all 0.0.0.0/0 md5Copy the code

(Click to enlarge the picture to view)

After the modification, restart Postgresql-12 \

systemctl restart postgresql-12
Copy the code

(Click to enlarge the picture to view)

Example Modify the database information in the Zabbix Server configuration file

Vim/etc/zabbix zabbix_server. Conf DBHost = 127.0.0.1 DBPassword = zabbix @ 2021Copy the code

(Click to enlarge the picture to view)

8. Modify PHP parameters and nginx configuration files

Conf using the vi editor: vi /etc/opt/rh/rh-php72/ php-fmm. d/zabbix.conf modify the timezone and ACL listen.acl_users = apache,nginx php_value[date.timezone] = Asia/ShanghaiCopy the code

(Click to enlarge the picture to view)

CD /etc/opt/rh/rh-nginx116/nginx/ vim nginx.conf Change the default port 80 to 81Copy the code

(Click to enlarge the picture to view)

Vim/etc/opt/rh/rh - nginx116 / nginx/conf. D/zabbix. Conf uncomment, using port 80Copy the code

(Click to enlarge the picture to view)

9. Restart all services and configure automatic startup upon startup

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 --reloadCopy the code

(Click to enlarge the picture to view)

Initialize the Zabbix5.0 Web interface

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

Note that Database host should be changed from localhost to 127.0.0.1\

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

(Click to enlarge the picture to view)

Default password: Admin/zabbix\

(Click to enlarge the picture to view)

Install Zabbix5.0 Agent

1. Install zabbix Agent

The RPM - sed Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm - I "s#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#g" /etc/yum.repos.d/zabbix.repo yum install zabbix-agentCopy the code

(Click to enlarge the picture to view)

2. Modify the configuration file

Modify the Server and ServerActive IP addresses in the configuration file

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=Copy the code

(Click to enlarge the picture to view)

3. Start related services of zabbix-Agent and set it to start automatically upon startup

Zabbix-agent needs to play port 10050 on the firewall

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
Copy the code

(Click to enlarge the picture to view)

4. Add hosts to ZabbixServer Web

(Click to enlarge the picture to view)

5. Verify that data collection on the Agent is normal

(Click to enlarge the picture to view)

\

Conclusion: PostgreSQL12+TimescaleDB is used in this deployment. The installation and configuration of the PostgreSQL12+TimescaleDB are relatively large. Compared with the MySQL database deployment, the performance of the PostgreSQL12+TimescaleDB is significantly improved

Search
About
mo4tech.com (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.