Centos8 安装 zabbix5.02(php74 + nginx1.18 + TimescaleDB12)
zabbix和数据库分别安装在两台服务器
zabbix+php+nginx+postgresql客户端 | 192.168.1.180 |
postgresql(TimescaleDB) | 192.168.1.181 |
一、首先安装TimescaleDB时序数据库(192.168.1.180,192.168.1.181)
1、安装TimescaleDB
TimescaleDB是基于PostgreSQL数据库打造的一款时序数据库,插件化的形式,随着PostgreSQL的版本升级而升级,不会因为另立分支带来麻烦,CentOS 8/RHEL 8上正式维护的模块化存储库的PostgreSQL版本为10和9.6,我们将添加PostgreSQL Yum Repository,它包含所有最新版本。
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
禁用centos8默认的postgresql模块:
dnf module disable postgresql
创建TimescaleDB的安装源
tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/7/\$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缓存并在Centos8上安装PostgreSQL 11:
192.168.1.181安装服务端
dnf clean all
dnf -y install postgresql12-server postgresql12-contrib
192.168.1.180安装客户端
dnf clean all
dnf -y install postgresql12-devel
在192.168.1.181上安装TimescaleDB
dnf -y install timescaledb-postgresql-12
192.168.1.181:初始化数据库并开启服务(192.168.1.181):
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable --now postgresql-12
确认服务已启动且没有任何错误:
systemctl status postgresql-12
开启防火墙端口5432端口(192.168.1.181):
firewall-cmd --add-port=5432/tcp --permanent
systemctl restart firewalld
2、配置TimescaleDB,初始化zabbix数据库
修改配置文件/var/lib/pgsql/12/data/postgresql.conf
侦听地址、端口、最大连接数
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 500 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - TCP Keepalives -
# see "man 7 tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
# 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
# - Authentication -
#authentication_timeout = 1min # 1s-600s
password_encryption = md5 # md5 or scram-sha-256
#db_user_namespace = off
添加时序数据库支持
修改配置文件
# - Shared Library Preloading -
shared_preload_libraries = 'timescaledb' # (change requires restart)
#local_preload_libraries = ''
#session_preload_libraries = ''
#jit_provider = 'llvmjit' # JIT library to use
*通过timescaledb-tune开启支持(可选)
[root@timescaledb ~]# timescaledb-tune -pg-config /usr/pgsql-12/bin/pg_config
Using postgresql.conf at this path:
/var/lib/pgsql/12/data/postgresql.conf
Is this correct? [(y)es/(n)o]: y
Writing backup to:
/tmp/timescaledb_tune.backup202008050957
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]: n
Saving changes to: /var/lib/pgsql/12/data/postgresql.conf
修改配置文件/var/lib/pgsql/12/data/pg_hba.conf,允许所有远程连接
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
host all all 0.0.0.0/0 md5
重启服务确认没有任何错误:
systemctl restart postgresql-12
systemctl status postgresql-12
设置PostgreSQL管理员用户密码
[root@timescaledb ~]# su postgres
bash-4.4$ psql
could not change directory to "/root": Permission denied
psql (12.3)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
ALTER ROLE
postgres=# quit
bash-4.4$ exit
exit
*给postgres用户授权使用sudo权限
sudo visudo
postgres ALL=(ALL) ALL #增加postgres的root权限并配置
您需要使数据库用户具有创建数据库对象的权限。以下shell命令将创建user zabbix。在出现提示时指定密码并重复输入密码(注意,可能会首先要求您输入sudo密码):
[root@timescaledb home]# sudo -u postgres createuser --pwprompt zabbix
现在,我们将zabbix使用先前创建的用户作为所有者(-O zabbix)来设置数据库(最后一个参数),并导入初始模式和数据(假设您位于Zabbix源的根目录中):
[root@timescaledb home]# sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix
初始化zabbix数据库
[root@timescaledb home]# echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -upostgres psql zabbix
WARNING:
WELCOME TO
_____ _ _ ____________
|_ _(_) | | | _ \ ___ \
| | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ /
| | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
| | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /
|_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
Running version 1.7.2
For more information on TimescaleDB, please visit the following links:
1. Getting started: https://docs.timescale.com/getting-started
2. API reference documentation: https://docs.timescale.com/api
3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture
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.timescaledb.com/using-timescaledb/telemetry.
CREATE EXTENSION
[root@timescaledb zabbix-5.0.2]# cat database/postgresql/schema.sql | sudo -u zabbix psql zabbix
[root@timescaledb zabbix-5.0.2]# cat database/postgresql/images.sql | sudo -u zabbix psql zabbix
[root@timescaledb zabbix-5.0.2]# cat database/postgresql/data.sql | sudo -u zabbix psql zabbix
[root@timescaledb zabbix-5.0.2]# cat database/postgresql/timescaledb.sql | sudo -u zabbix psql zabbix
修改数据库zabbix用户密码
[root@timescaledb zabbix-5.0.2]# su postgres
bash-4.4$ psql
could not change directory to "/root/zabbix-5.0.2": Permission denied
psql (12.3)
Type "help" for help.
postgres=# ALTER USER zabbix WITH PASSWORD 'zabbix';
ALTER ROLE
postgres=# quit
bash-4.4$ exit
exit
二、安装php74(192.168.1.180)
EPEL和REMI存储库是此安装的主要要求,通过运行以下命令将它们添加到系统:
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
启用PHP 7.4 Remi模块并在CentOS 8/RHEL 8系统中安装PHP 7.4:
dnf -y install dnf-utils
查看启动的模块
dnf module list php

在CentOS 8/RHEL 8中启用PHP 7.4的模块流:
dnf module install php:remi-7.4

使用下一个命令安装其他软件包:
dnf update
dnf install -y php-devel php-fpm php-mbstring php-mysqli php-mysqlnd php-pdo php-bcmath php-dom php-gd php-gmp php-pdo_mysql php-posix php-simplexml php-opcache php-xsl php-xmlwriter php-xmlreader php-xml php-zip php-fileinfo php-pgsql
查看php版本,启动服务
[root@Zabbix_Server ~]# php -v
PHP 7.4.8 (cli) (built: Jul 9 2020 08:57:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies
[root@Zabbix_Server ~]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@Zabbix_Server ~]# systemctl start php-fpm
三、安装nginx1.18(192.168.1.180)
1、安装社区版软件源:
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
gpgcheck=1
enabled=1
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
gpgcheck=1
enabled=0
module_hotfixes=true
2、选择安装稳定版还是主线版
安装稳定版输入:
yum-config-manager --enable nginx-stable
安装主线版(测试版)输入:
yum-config-manager --enable nginx-mainline
3、安装 Nginx
dnf --disablerepo=AppStream install -y nginx
四、安装zabbix(192.168.1.180)
配置编译环境
dnf install make curl curl-devel net-snmp net-snmp-devel perl-DBI libxml2-devel libevent-devel yum-utils pcre* openssl openssl-devel zlib zlib-devel gcc gcc-c++
安装go编译环境
1.下载go(最新版列表 https://studygolang.com/dl)
2.解压go到 /opt/
tar -C /opt/ -zxvf go1.15.1.linux-amd64.tar.gz
3.增加环境变量,编辑 /etc/profile 增加如下三行
export PATH=$PATH:/opt/go/bin
export GOROOT=/opt/go
export GOPATH=/root/project #项目代码所在目录,建议编译之前手动建立一个 /root/project
4.刷新环境变量
source /etc/profile
5.开启 go mod,由于编译过程需要联网下载依赖包,配置 go mod 代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
创建zabbix agent日志目录,并授权zabbix用户
useradd zabbix && mkdir /var/log/zabbix/ && chown zabbix:zabbix /var/log/zabbix
编译安装
cd ~
cd zabbix-5.0.2
./configure --prefix=/usr/local/zabbix --sysconfdir=/opt/zabbix --enable-server --enable-agent --enable-agent2 --with-net-snmp --enable-java --with-libxml2 --with-libcurl --with-postgresql=/usr/pgsql-12/bin/pg_config --disable-dependency-tracking
make && make install
参照如下参数修改zabbix server的配置文件
vim /opt/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=192.168.1.181
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=5432
Timeout=30
AlertScriptsPath=/opt/zabbix/scripts
LogSlowQueries=3000
JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=5
拷贝启动文件并配置可执行
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server
根据安装目录修改zabbix_server和zabbix_agentd启动目录
vim /etc/init.d/zabbix_agentd
vim /etc/init.d/zabbix_server
BASEDIR=/usr/local 修改成下面的安装目录
BASEDIR=/usr/local/zabbix
systemctl enable zabbix_agentd
systemctl enable zabbix_server
systemctl start zabbix_agentd
systemctl start zabbix_server
五、安装web界面
修改php配置
vim /etc/php.ini
配置如下
max_execution_time=300
memory_limit=128M
post_max_size=16M
upload_max_filesize=8M
max_input_time=300
session.auto_start = 0
mbstring.func_overload = 0
date.timezone="Asia/Shanghai"
always_populate_raw_post_data=-1 #添加
拷贝zabbi web到httpd目录
mkdir /var/www/html -p
cp -a frontends/php/* /var/www/html
在/etc/nginx/nginx.conf的server{}字段
vim /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/zabbix;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
启动nginx和php72-php-fpm
systemctl start php-fpm
systemctl enable php-fpm
nginx -c /opt/nginx/conf/nginx.conf
目录 返回
首页