RedHat7.9安装zabbix6.4
RedHat7.9安装zabbix6.4
1. 安装环境说明
本例中安装zabbix
开源软件和zabbix
运行所需的中间件和数据库apache、php
和postgres
,软件版本信息如下:
软件 | 版本 |
---|---|
zabbix | Zabbix6.4.0 |
apache | httpd-2.4.57 |
apr | apr-1.7.4 |
apr-util | 1.6.3 |
php | 8.2.6 |
sqlite-autoconf | 3420000 |
gcc | 11 |
postgres | 14.7 |
zabbix_agent | 6.4.17 |
主机信息如下:
Red Hat Enterprise Linux Server 7.9 (Maipo)
2. 服务器准备
主机名 | 主机地址 | 用途 |
---|---|---|
zib_server | 192.168.101.238 | zabbix的服务器地址 |
pgsql_master | 192.168.101.232 | pgsql的主服务器 |
pgsql_backup | 192.168.101.239 | pgsql的备服务器 |
安装流程:
1. 安装zabbix-server服务端
2. 安装zabbix-agent客户端
3. 连接服务端和客户端
3. zabbix的服务器安装
3.1 apche及依赖软件安装
3.1.1 安装gcc
安装
yum install centos-release-scl -y
yum install devtoolset-11-gcc* -y
安装完centos-release-scl
可能导致yum
无法使用,这个时候需要去/etc/yum.repos.d
目录下,去修改yum
源。详情请见240715-centos7中安装了centos-release-scl后,之前的yum源变为不可用 解决方案.md
文档。
激活对应的devtoolset
,所以你可以一次安装多个版本的devtoolset
,需要的时候用下面这条命令切换到对应的版本
scl enable devtoolset-11 bash
查看gcc
版本
gcc -v
补充:这条激活命令只对本次会话有效,重启会话后还是会变回原来的4.8.5版本,要想随意切换可按如下操作。
首先,安装的devtoolset
是在 /opt/rh
目录下的
cd /opt/rh/devtoolset-11
source ./enable
直接替换旧的gcc
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
gcc --version
g++ --version
3.1.2 安装apache
apache下载:http://httpd.apache.org/download.cgi
apache apr和apache apr-util下载:http://apr.apache.org/download.cgi
创建目录:
mkdir /usr/local/apache
mkdir /usr/local/apache/apr/apr-1.7.4
mkdir /usr/local/apache/apr-util
解压文件:
备注:进入soft目录的原因是因为所有的安装的都放在/soft目录下。
cd /soft
tar -zxvf apr-1.7.4.tar.gz -C /usr/local/apache/apr --strip-components=1
tar -zxvf apr-util-1.6.3.tar.gz -C /usr/local/apache/apr-util
tar -zxvf httpd-2.4.57.tar.gz -C /usr/local/apache
安装依赖软件及安装包
yum install expat-devel pcre-devel openssl-devel -y
3.1.3 安装apr
源码编译安装:
cd /soft
cd /usr/local/apache/apr/apr-1.7.4
./configure --prefix=/usr/local/apache/apr
make -j4 && make install
3.1.4 安装apr-util
源码编译安装:
cd /usr/local/apache/apr-util/apr-util-1.6.3
./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/apr
make -j4 && make install
3.1.5 安装apache
源码编译安装:
cd /usr/local/apache/httpd-2.4.57
./configure --prefix=/usr/local/apache --sysconfdir=/usr/local/apache/conf --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=all --enable-mods-shared=all --enable-mpms-shared=all --with-apr=/usr/local/apache/apr --with-apr-util=/usr/local/apache/apr-util --with-pcre
make -j4 && make install
3.1.6 启动 apache
/usr/local/apache/bin/apachectl start
3.2 安装PHP
3.2.1 下载源码安装包
php下载:http://php.net/downloads.php
3.2.2 创建目录并解压
mkdir /usr/local/php
解压安装文件:
tar -zxvf php-8.2.6.tar.gz -C /usr/local/php
3.2.3 安装依赖软件及安装包
yum install expat-devel pcre-devel openssl-devel libxslt-devel libXpm* libjpeg* libcurl* libpng* bzip2* libxml2-devel sqlite-devel oniguruma-devel postgresql-devel gcc* net-snmp-devel curl curl-devel automake autoconf libtool make libevent-devel libicu-devel libzip libzip-devel python-freetype.noarch freetype-devel.x86_64 freetype-demos.x86_64 freetype.i686 freetype.x86_64 –y --setopt=protected_multilib=false
3.2.4 源码编译安装php
cd /usr/local/php/php-8.2.6
./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --enable-fpm --with-pear --with-curl --with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-freetype --with-zlib-dir --with-iconv --enable-mbstring --enable-bcmath --with-mhash --with-zlib --with-xmlrpc --with-xsl --with-openssl --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-bz2 --with-gettext --with-xpm-dir=/usr/lib64/ --with-pdo-pgsql --with-pgsql --enable-gd --enable-gd-jis-conv --enable-sockets --enable-soap --enable-xml --enable-shmop --enable-sysvsem --with-jpeg
make && make install -j4
3.2.5 修改php
配置环境
cd /usr/local/php/php-8.2.6
cp php.ini-development /usr/local/php/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini
sed -i 's#;date.timezone =#date.timezone=Asia/Shanghai#g' /usr/local/php/etc/php.ini
sed -i 's#;always_populate_raw_post_data = -1#always_populate_raw_post_data = -1#g' /usr/local/php/etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#g' /usr/local/php/etc/php.ini
3.2.6 安装php sockets
拓展包
cd /usr/local/php/php-8.2.6/ext/sockets/
生成源码文件:
yum -y install gcc automake autoconf libtool make
/usr/local/php/bin/phpize
make clean
源码编译安装
./configure --enable-sockets --with-php-config=/usr/local/php/bin/php-config
make && make install -j4
修改配置文件:
sed -i '$a extension=sockets.so' /usr/local/php/etc/php.ini
3.2.7 修改apache配置文件
修改apache的配置文件,添加apache对php的支持
sed -i '$a PHPIniDir /usr/local/php/etc/php.ini' /usr/local/apache/conf/httpd.conf
sed -i 's#DirectoryIndex index.html#DirectoryIndex index.html index.php#g' /usr/local/apache/conf/httpd.conf
sed -i '410a AddType application/x-httpd-php .php' /usr/local/apache/conf/httpd.conf
3.3 安装数据库
3.3.1 在.bash_profile中增加环境变量
export PGPORT=5432
export PGDATA=/home/postgres/data
export PGUSER=postgres
export PGHOST=localhost
export PGDATABASE=postgres
export PGHOME=/home/postgres/FlyingDB
export DATE=`date +"%Y%m%d%H%M"`
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.utf8
export PGBHOME=/postgres/pgbouncer/Files
export LD_LIBRARY_PATH=$PGHOME/lib:$PGBHOME/third-lib/:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PGBHOME/bin:$PATH:$HOME/.local/bin:$HOME/bin
3.3.2创建数据库目录并创建数据库
useradd postgres
mkdir /home/postgres/data
chmod 0700 /home/postgres/data
chown postgres:postgres /home/postgres/data
initdb -D /home/postgres/data -E UTF8 --locale=C -U postgres
3.3.3 在pg_hba.conf
增加如下配置
host all all 0.0.0.0/0 md5
3.3.4 在postgres.conf
里面增加如下配置
listen_addresses = '*'
port = 5432
max_connections = 1000
superuser_reserved_connections = 10
unix_socket_directories = '/home/postgres/'
unix_socket_permissions = 0700
tcp_keepalives_idle = 60
tcp_keepalives_interval = 10
tcp_keepalives_count = 10
shared_buffers = 2000MB
huge_pages = off
work_mem = 4063kB
maintenance_work_mem = 2GB
max_stack_depth = 2MB
dynamic_shared_memory_type = posix
vacuum_cost_delay = 10
vacuum_cost_limit = 1000
bgwriter_delay = 10ms
bgwriter_lru_maxpages = 1000
bgwriter_lru_multiplier = 10.0
effective_io_concurrency = 2
max_parallel_workers_per_gather = 4
max_parallel_maintenance_workers = 4
max_worker_processes = 18
parallel_leader_participation = on
max_parallel_workers = 18
wal_level = replica
fsync = on
synchronous_commit = on
wal_sync_method = fdatasync
full_page_writes = on
wal_compression = on
wal_buffers = 16MB
wal_writer_delay = 10ms
commit_delay = 10
commit_siblings = 28
checkpoint_timeout = 10min
max_wal_size = 8GB
min_wal_size = 2GB
checkpoint_completion_target = 0.9
archive_mode = on
archive_command = 'mkdir -p /home/postgres/data/archivedir && cp %p /home/postgres/data/archivedir/%f'
max_wal_senders = 10
hot_standby = off
wal_receiver_status_interval = 0
random_page_cost = 4
effective_cache_size = 47616MB
default_statistics_target = 100
log_destination = 'csvlog'
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_file_mode = 0600
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 128MB
log_checkpoints = on
log_error_verbosity = verbose
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '
log_lock_waits = on
log_timezone = 'PRC'
track_io_timing = on
track_functions = all
track_activity_query_size = 2048
autovacuum = on
log_autovacuum_min_duration = 0
autovacuum_max_workers = 3
autovacuum_naptime = 300s
datestyle = 'iso, mdy'
timezone = 'Asia/Vientiane'
lc_messages = 'C'
lc_monetary = 'C'
lc_numeric = 'C'
lc_time = 'C'
default_text_search_config = 'pg_catalog.english'
deadlock_timeout = 200ms
3.4 安装zabbix
3.4.1 下载源码安装包
wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.0.tar.gz
3.4.2 创建目录并解压
mkdir /usr/local/zabbix
tar -zxvf zabbix-6.4.0.tar.gz -C /usr/local/zabbix
3.4.3 安装依赖软件及安装包
yum install gcc* net-snmp-devel curl curl-devel postgresql-devel –y
3.4.4 安装zabbix
源码安装编译:
cd /usr/local/zabbix/zabbix-6.4.0
yum install libevent-devel -y
export CFLAGS="-std=gnu99"
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-postgresql
make && make install -j4
3.4.5 导入数据库表
(venv-patroni-3.0.1) [postgres@fd-mq-test-1 postgres]$ psql
psql (14.7)
Type "help" for help.
postgres=# create user zabbix with password '183737';
CREATE ROLE
postgres=# CREATE DATABASE zabbix OWNER zabbix;
CREATE DATABASE
psql -U fbase -w -c "create user zabbix with password 'zabbix';"
psql -U fbase -w -c "CREATE DATABASE zabbix OWNER zabbix;"
cd /usr/local/zabbix/zabbix-6.4.0/database/postgresql/
psql -U zabbix -d zabbix -f schema.sql
psql -U zabbix -d zabbix -f images.sql
psql -U zabbix -d zabbix -f data.sql
3.4.6 配置zabbix
服务
cat >> /etc/services << EOF
# Zabbix
zabbix-agent 10050/tcp #ZabbixAgent
zabbix-agent 10050/udp #ZabbixAgent
zabbix-trapper 10051/tcp #ZabbixTrapper
zabbix-trapper 10051/udp #ZabbixTrapper
EOF
3.4.7 拷贝zabbix web
页面到apache
目录
mkdir /usr/local/apache/htdocs/zabbix
cp -r /usr/local/zabbix/zabbix-6.4.0/ui/* /usr/local/apache/htdocs/zabbix
添加zabbix
用户:
useradd zabbix
3.4.8 修改zabbix-server
配置文件
vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=192.168.101.238
DBName=zabbix
DBSchema=public
DBUser=zabbix
DBPassword=zabbix
DBPort=8432
3.4.9 修改zabbix agentd
配置文件
vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server=192.168.101.238
ServerActive=192.168.101.238
Hostname=redhat238
3.4.10 启动服务
/usr/local/apache/bin/apachectl start
/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
# 查看服务是否启动
ps aux | grep '/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf'
ps aux | grep '/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf'
4.zabbix web
界面配置
4.1 浏览器访问 http://192.168.101.238/zabbix
点击Next step
4.2 zabbix
检查软件运行环境
4.3 填写主机信息
填写zabbix_server
的信息,填写完成之后点击Next step
4.4 安装完成
5. 遇到相关错误解决方法
问题1:编译zabbix
时遇到报错
Error:--with-postgresql configure: error: PostgreSQL library not found
解决方法:
yum install postgresql-devel
问题2:postgres 14.7
密码认证模式为SCRAM-SHA-256,zabbix
与postgresql
会认证失败
解决方法:
1.postgres.conf
增加password_encryption = md5
配置
2.登入psql
对密码重新修改:
ALTER user zabbix PASSWORD 'zabbix';
问题3:数据库信息填完成后无法创建配置文件
如下:
解决方法:
将文件下载,上传到系统/usr/local/apache/htdocs/zabbix/conf
这个目录下
问题4:首次安装zabbix
安装,浏览器打开为文本,或者是数据库选项不能选择数据库。
解决方法:可以尝试对httpd
服务重起,或是对php
重新编译。应注意./configure
后编译报错信息如果php
版本跨度较大,有些参数已不支持。应仔细 ./configure --help
查看帮助。