系统环境
centos-stream9
16G内存
8核cpu
硬盘500G,大于20台机器,存储3个月以上建议存储2T以上。
防火墙开放端口号
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
安装工具
yum -y install dnf wget epel-release net-snmp net-snmp-devel libxml2 libxml2-devel libssh2 libssh2-devel libevent libevent-devel php-xml php-bcmath php-common php-mbstring php-gd php-odbc php-pear php-mysqlnd curl curl-devel perl-DBI pcre* chkconfig initscripts
dnf update -y
dnf install php
安装mysql、nginx
#安装mysql
rpm -ivh https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
yum install mysql-community-server mysql-community-devel -y
#启动mysql
systemctl start mysqld
more /var/log/mysql.log | grep pass
有生成一个临时密码
-------------------------------------------------
[root@localhost ~]# more /var/log/mysqld.log | grep pass
2023-06-08T03:25:43.513068Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2023-06-08T13:47:44.582717Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: GhuL
#修改mysql主目录
[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# cp -R /var/lib/mysql /data/
[root@localhost ~]# chown -R mysql:mysql /data/mysql/
修改配置文件/etc/my.cnf
并增加以下配置:
[client]
default-character-set=utf8
socket=/data/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/data/mysql/mysql.sock
修改完重启mysql:systemctl restart mysqld
#安装nginx
[root@localhost ~]# yum -y install nginx
# 选配,修改nginx的端口号
[root@localhost ~]# systemctl start nginx
安装中文字体
[root@localhost ~]# dnf install -y langpacks-zh_CN
新建zabbix账号
#建立zabbix账户
groupadd zabbix
useradd -g zabbix zabbix
创建zabbix初始化数据库
# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。
tar zxvf zabbix-6.4.3.tar.gz
[root@localhost ~]# cd zabbix-6.4.3
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix
导入数据库模式后,禁用log _ bin _ trust _ function _ creators选项。
# mysql -uroot -p
password
mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> set global log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
编译安装zabbix
[root@localhost zabbix-6.4.3]# ./configure -sysconfdir=/usr/local/zabbix --bindir=/usr/local/zabbix/bin --sbindir=/usr/local/zabbix/sbin --sysconfdir=/usr/local/zabbix/etc --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
##安装完提示::==============================
Configuration:
Detected OS: linux-gnu
Install path: /usr/local
Compilation arch: linux
Compiler: cc
Compiler flags: -g -O2
Library-specific flags:
database: -I/usr/include/mysql -m64
libXML2: -I/usr/include/libxml2
Net-SNMP: -I. -I/usr/include
Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
SSL certificates: /usr/local/share/zabbix/ssl/certs
SSL keys: /usr/local/share/zabbix/ssl/keys
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -L/usr/lib64 -L/usr/lib64/mysql -rdynamic
Libraries: -lmysqlclient -lssl -lcrypto -lresolv -lm -lxml2 -lnetsnmp -lz -lpthread -levent -levent_pthreads -lcurl -lpthread -lm -lpcre
Configuration file: /usr/local/zabbix/etc/zabbix_server.conf
External scripts: /usr/local/share/zabbix/externalscripts
Alert scripts: /usr/local/share/zabbix/alertscripts
Modules: /usr/local/lib/modules
Enable proxy: no
Enable agent: yes
Agent details:
TLS: no
Modbus: no
Linker flags: -rdynamic
Libraries: -lz -lpthread -lcurl -lpthread -lm -lpcre
Configuration file: /usr/local/zabbix/etc/zabbix_agentd.conf
Modules: /usr/local/lib/modules
Enable agent 2: no
Enable web service: no
Enable Java gateway: no
LDAP support: no
IPv6 support: yes
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* *
***********************************************************
==================================================================
=====================================
#编译安装执行如下命令
make
make install
创建zabbix日志目录
mkdir /var/log/zabbix
chown zabbix.zabbix /var/log/zabbix
添加启动脚本
[root@localhost zabbix-6.4.3]# ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/
[root@localhost zabbix-6.4.3]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@localhost zabbix-6.4.3]# chmod 744 /etc/init.d/zabbix_*
# 更改zabbix.pid 文件到/var/log/zabbix/文件夹下
[root@localhost zabbix-6.4.3]# sed -i "s#PIDFILE=/tmp#PIDFILE=/var/log/zabbix#g" /etc/init.d/zabbix_server
[root@localhost zabbix-6.4.3]# sed -i "s#PIDFILE=/tmp#PIDFILE=/var/log/zabbix#g" /etc/init.d/zabbix_agentd
zabbix前端文件移动到nginx主目录
将zabbix的web文件拷贝到httpd的目录/data
cp -r ui /data/nginx-root
chown -R nginx.nginx /data/nginx-root/
cd /data/nginx-root/
cp zabbix.conf.php.example zabbix.conf.php
修改/data/nginx-root/conf/zabbix.conf.php配置文件:连接数据库的参数:端口号不用改,数据库名字、数据库用户名、数据库密码
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '数据库密码';
配置php.ini文件,适应安装所需的参数
vi /etc/php.ini
date.timezone= Asia/Chongqing
max_execution_time= 300
max_input_time= 300
memory_limit = 128M
post_max_size= 32M
mysqli.default_socket = /data/mysql/mysql.sock
配置zabbix配置文件
zabbix_server.conf 配置文件优化
zabbix_agentd.conf配置文件优化
添加开机启动和启动服务
chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig --level 35 zabbix_server on
chkconfig --level 35 zabbix_agentd on
systemctl enable zabbix_server
systemctl enable zabbix_agentd
systemctl enable mysqld
systemctl enable nginx
systemctl start zabbix_server
systemctl start zabbix_agentd
web浏览 http://111.11.11.11
其他配置参考
https://blog.51cto.com/506554897/1766141
https://blog.51cto.com/506554897/1766150
监控参考:Monitor 分类
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com