hopeless-dream

导航

centos 7——LNMP环境编译安装zabbix-5.0.8

服务器环境

服务器IP 安装软件
10.0.0.20

zabbix-server、Nginx-1.22、PHP-7.3.29

10.0.0.21 zabbix-agent
10.0.0.22 zabbix-agent
10.0.0.23 MySQL

 

二进制安装mysql 8.0

获取软件包

# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

安装依赖

# yum install -y libaio

卸载mariadb的库

# yum remove -y mariadb-libs

解压 并创建数据目录

# tar -xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
# mv /usr/local/mysql-8.0.20-linux-glibc2.12-x86_64/ /usr/local/mysql8.0
# mkdir /data/mysql8.0 -p

创建用户

# groupadd mysql
# useradd -g mysql mysql

初始化数据库

# cd /usr/local/mysql8.0/bin
# ./mysqld --user=mysql --basedir=/usr/local/mysql8.0 --datadir=/data/mysql8.0 --initialize
2022-08-23T04:57:59.714960Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2022-08-23T04:57:59.715050Z 0 [System] [MY-013169] [Server] /usr/local/mysql8.0/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 2054
2022-08-23T04:57:59.735287Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-23T04:58:00.281794Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-23T04:58:00.777487Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uQjrcj0gfJ_f

修改配置文件

[mysqld]
user=mysql
basedir=/usr/local/mysql8.0
datadir=/data/mysql8.0
socket=/tmp/mysql.sock

# 连接层 设置
max_connect_errors=20000      # 默认值
max_connections=1500          # 默认值151,单节点不高于3000
wait_timeout=600              # 默认值28800
interactive_timeout=600
max_allowed_packet=64M        # 默认64M。防止地段数据过于庞大,导致更新数据失败

# server层 配置
#ini-file=/usr/local/mysql8.0/init-file.sql
slow_query_log=ON
slow_query_log_file=/data/mysql8.0/slow_log
long_query_time=1                                       # 慢查询时间
log_queries_not_using_indexes=ON                        # 默认关闭,记录未使用到索引的查询语句,忽略long_query_time的设置
log_throttle_queries_not_using_indexes=10               # 默认是0,表示不限制。限制每分钟记录到slow log的语句数量
tmp_table_size=32M                                           # 默认16M,建议不要超过128M
max_heap_table_size=32M                                          # 默认16M,建议不要超过128M
# sql_mode                                              # 建议保持默认。
max_execution_time=10                                   # 设置语句执行的超时时间。默认值0,表示不限制。建议跑批量是设置较大。
lock_wait_timeout=10                                    # 建议设置在60秒以内
#lower_case_table_names=1                                # 忽略表名大小写,初始化时要设置好
thread_cache_size=64                                    # 线程缓存池大小,和线程命中率(Threads_created/connections)的比值有关,根据物理内存设置原则:1G ---》8 2G ----》16
character_set_server=utf8                               # 或者utf8mb4
log_timestamps=SYSTEM                                   # 控制错误日志、慢查询日志等日志中的显示时间
init_connect="set names utf8"                           # 用于登录审计(普通用户)时,可以设置为'insert into auditdb.access(thread_id,login_time,localname,matchname) values (connection_id(),now(),user(),current_user());'



log_bin=/data/mysql8.0/binlog_3306
port=3306
server_id=5                              
#character-set-server=UTF8MB4 默认
#innodb_file_per_table=1   默认开启
symbolic-links=0
transaction-isolation="READ-COMMITTED"


[mysql]
socket=/tmp/mysql.sock
no-auto-rehash
pager="less -i -n -S"
[include]
ini-file=/usr/local/mysql8.0/init-file.sql

设置 sql 安全模式

# cat /usr/local/mysql8.0/init-file.sql
set global sql_safe_updates=1;

拷贝启动文件

# cp -a ../support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld

启动mysql

启动mysql
# /etc/init.d/mysqld start

修改 mysql 的 root 用户密码

# mysql -uroot -puQjrcj0gfJ_f

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> flush privileges;

授权远程连接主机

mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> flush privileges;

建立zabbix库,并授权

mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@'10.%' identified by 'zabbix';

mysql> grant all privileges on zabbix.* to zabbix@'10.%';
mysql> flush privileges;

编译安装zabbix-server

# yum install -y libevent-devel net-snmp-devel gcc gcc-c++
# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.8.tar.gz

添加用户、用户组并授权

# groupadd -r zabbix
# useradd -r -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "test zabbix" zabbix
# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
# chown zabbix:zabbix /usr/lib/zabbix

安装依赖

# yum install -y gcc gcc-c++ mysql-community-devel net-snmp-devel libxml2 libxml2-devel  unixODBC-devel libcurl-devel curl-devel libssh2-devel OpenIPMI-devel openssl-devel openldap-devel libevent-devel pcre-devel fping java-1.8.0-openjdk  java-1.8.0-openjdk-devel 

mysql-community-devel:解决报错 “configure: error: MySQL library not found”

libxml2 libxml2-devel:解决报错 “No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
checking for xmlReadMemory in -lxml2... no”

net-snmp-devel: 解决报错 “configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config”

curl-devel:解决报错 “checking for curl-config... no
configure: error: Curl library not found”

解压软件包

# tar xfz zabbix-5.0.8.tar.gz -C /usr/local/
# cd /usr/local/zabbix-5.0.8/

编译

./configure --prefix=/usr/local/zabbix --enable-server    --enable-agent --with-mysql --enable-ipv6 --with-libcurl  --with-libxml2 --with-openipmi --with-net-snmp --with-ssh2 --with-unixodbc --with-openssl   --enable-java

安装

# make && make install

MySQL中倒入数据库

# cd /usr/local/zabbix-5.0.8/database/mysql
# scp schema.sql data.sql images.sql 10.0.0.23:
# cat schema.sql|mysql -uroot -p123456 -D zabbix
# cat images.sql|mysql -uroot -p123456 -D zabbix
# cat data.sql|mysql -uroot -p123456 -D zabbix

修改 zabbix-server 的配置文件

# cd  /usr/local/zabbix/etc
# >zabbix_server.conf

# vim zabbix_server.conf
LogFile=/usr/local/zabbix/log/zabbix_server.log
LogFileSize=5 
PidFile=/usr/local/zabbix/zabbix_server.pid
DBHost=10.0.0.23
DBName=zabbix
DBUser=zabbix
DBPassword=123456
AllowRoot=1

完整的zabbix_server配置文件

# cat /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/log/zabbix_server.log
LogFileSize=5 
PidFile=/usr/local/zabbix/zabbix_server.pid
DBHost=10.0.0.23
DBName=zabbix
DBUser=zabbix
DBPassword=123456
AllowRoot=1
StartPollers=100
StartIPMIPollers=10
StartPollersUnreachable=10
StartTrappers=10
StartPingers=10
StartDiscoverers=10
SNMPTrapperFile=/var/log/snmptt/snmptt.log
MaxHousekeeperDelete=500
CacheSize=256M
HistoryCacheSize=128M
TrendCacheSize=128M
# HistoryTextCacheSize=128M
ValueCacheSize=2048M
Timeout=30
TrapperTimeout=300
UnreachablePeriod=45
UnavailableDelay=60
UnreachableDelay=15
AlertScriptsPath=/usr/local/zabbix/alertscripts      # 告警脚本目录
ExternalScripts=/usr/local/zabbix/externalscripts    # 扩展脚本存放目录
FpingLocation=/usr/sbin/fping
LogSlowQueries=10000
StartProxyPollers=50
ProxyConfigFrequency=3600

创建脚本目录

# mkdir -p /usr/local/zabbix/alertscripts /usr/local/zabbix/externalscripts

# chown -R zabbix: /usr/local/zabbix/

# mkdir -p /var/log/snmptt/
# touch /var/log/snmptt/snmptt.log

# chown -R zabbix: /var/log/snmptt/

创建日志目录

# mkdir /usr/local/zabbix/log/ -p

配置 zabbix-server 的 unit 文件

# vi  /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
 
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
Type=forking
PIDFile=/usr/local/zabbix/zabbix_server.pid
Restart=on-failure
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
 
[Install]
WantedBy=multi-user.target

编译安装 Nginx

安装依赖

# yum install -y zlib zlib-devel

zlib:解决报错
“/usr/bin/ld: cannot find -lz

  collect2: error: ld returned 1 exit status

下载软件包并解压

# wget http://nginx.org/download/nginx-1.22.0.tar.gz
# tar xfz nginx-1.22.0.tar.gz

编译安装 Nginx

# cd nginx-1.22.0/

# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module  --with-http_ssl_module  --with-pcre
# make && make install

修改 Nginx 配置文件

    server {
        listen       80;
        server_name  localhost;
        location /nginx_status {
            stub_status on;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

配置 Nginx 的 unit 文件

# vi  /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

安装PHP

下载软件包

# cd /opt
# wget https://www.php.net/distributions/php-7.3.29.tar.gz
# tar xfz php-7.3.29.tar.gz

编译安装PHP

# cd php-7.3.29/
# ./configure --prefix=/usr/local/php --enable-fpm --enable-mbstring --with-openssl    --with-mysqli --with-mysql-sock --with-gd   --enable-pdo --with-pdo-mysql --with-gettext  --enable-sockets --enable-bcmath    --enable-xml --with-bz2  --with-freetype-dir=/usr/local --with-libxml-dir=/usr/local    --with-zlib --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local  --with-ldap --with-libdir=lib64

# make && make install

修改php配置文件

# cp /opt/php-7.3.29/php.ini-production  /usr/local/php/lib/php.ini

# vim /usr/local/php/lib/php.ini
date.timezone = Asia/Shanghai   
post_max_size = 20M
upload_max_filesize = 20M
max_execution_time = 300 
max_input_time = 300
memory_limit = 1024M

准备 php-fpm 配置文件

# cd /usr/local/php/etc
 
# cp php-fpm.conf.default   php-fpm.conf
 
# cp php-fpm.d/www.conf.default   php-fpm.d/www.conf

拷贝zabbix前端到nginx默认web目录

# cd /usr/local/zabbix-5.0.8/
# cp -a ui/* /usr/local/nginx/html/

配置 php-fpm 的 unit 文件

vi  /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.targe

[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

安装zabbix agent2

Zabbix 5.0 版本推出了使用 go 语言重写的 Agent2,也是 5.0 版本新特性,Agent2 有如下特性:

  • 完成的插件框架支持,可扩张服务及应用监控
  • 支持灵活的采集周期调度
  • 更高效的数据采集及传输
  • 可完全替换先有的 agent
  • …..

特性较多,建议使用。由于使用 go 语言编写,编译安装与之前版本有所区别。Agent2 默认使用的 10050 端口,与 Zabbix Agent 端口一样,不修改端口情况下,同一台机器不能同时启动 Zabbix Agent 与 Zabbix Agent2。

编译安装

安装 gcc 等基础编译环境,由于使用 go 编写,因此需要配置 go 编译环境,下载并配置 go 语言编译环境

# cd /opt
#
wget https://dl.google.com/go/go1.14.3.linux-amd64.tar.gz # tar zxvf go1.14.3.linux-amd64.tar.gz -C /usr/local/
# echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile # source /etc/profile

查看 go 环境是否安装成功

# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build821720893=/tmp/go-build -gno-record-gcc-switches"

开启 go mod,由于编译过程需要联网下载依赖包,配置 go mod 代理

# go env -w GO111MODULE=on
# go env -w GOPROXY=https://goproxy.cn,direct

下载 zabbix 5.0.8 源码

# cd /opt
# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.8.tar.gz
# tar zxvf zabbix-5.0.8.tar.gz
# cd zabbix-5.0.8

如果只是要编译 agent2,直接加-enable-agent2 参数即可

# ./configure --prefix=/usr/local/zabbix -enable-agent2
# make && make install

安装完成后 agent2 配置文件和二进制启动程序路径

/usr/local/zabbix/etc/zabbix_agent2.conf

/usr/local/zabbix/sbin/zabbix_agent2

修改配置文件

# grep -Ev "^$|#" /usr/local/zabbix/etc/zabbix_agent2.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=10.0.0.20
ServerActive=10.0.0.21
Hostname=10.0.0.20
ControlSocket=/tmp/agent.sock
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1

参数含义如下:

  • Server:被动模式,允许 zabbix_server 服务器连接客户端,此处允许本机和 10.0.0.20 访问10050端口,多个IP地址之间用逗号分隔。
  • ServerActive:主动模式,向目标 zabbix_server 服务器传送数据。这种模式的性能较好,建议使用,但需要确保 zabbix_agentd.conf 的参数 Hostname 值与 Zabbix-Web 页面中的主机名一致;否则,在 zabbix-server.log 中将会看到如下日志:
2022/08/26 17:25:49.277934 [101] no active checks on server [10.0.0.20:10051]: host [10.0.0.20] not found

创建日志文件

# groupadd zabbix
# useradd -g zabbix zabbix

# mkdir -p /var/log/zabbix/
# touch /var/log/zabbix/zabbix_agentd.log
# chown zabbix: /var/log/zabbix

配置 agent2 的unit 文件

# vi /lib/systemd/system/zabbix-agent2.service
[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target
 
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agent2.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent2
Type=simple
Restart=on-failure
PIDFile=/tmp/zabbix_agent2.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
 
[Install]
WantedBy=multi-user.target

启动并设置开机启动

# systemctl enable --now zabbix-agent2

 注意:Agent2 没有组件依赖,可直接拷贝编译好的二进制文件和配置文件在其他主机上运行即可。

原文链接:https://blog.csdn.net/qq_55723966/article/details/122085551

访问并完成安装zabbix

访问地址:http://$zabbix-serverIP/zabbix.php

 用户名Admin,密码zabbix

posted on 2022-08-26 17:44  hopeless-dream  阅读(286)  评论(0编辑  收藏  举报