系统环境
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
安装工具
# 先安装dnf 和epel源
yum -y install dnf epel-release
dnf update -y
dnf install php
# 安装以来工具和常用工具;chkconfig工具用来设置启动项的;initscripts是用来安装/etc/init.d/functions,zabbix_server启动文件会调用funcitons。
yum -y install wget 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
安装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/mysqld.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<87y64P)
-------------------------------------------------
[root@localhost yum.repos.d]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
New password: 【输入密码】
Re-enter new password:【输入密码】
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
# 这时候输出ctrl+c 结束。 然后重新进入安全设置模式
[root@localhost ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 【输入n ,变改变面膜继续下一步】
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y 【输入y删除匿名用户】
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n 【输入n允许root远程登录】
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y 【输入y删除test数据库】
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y 【输入y 重新加载权限】
Success.
All done!
#修改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
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
并增加以下配置:
[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
open_files_limit = 8192
table_open_cache = 8192
max_connections = 8192
[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;
导入初始架构和数据,系统将提示您输入新创建的密码。
wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.4.tar.gz
tar zxvf zabbix-6.4.4.tar.gz
[root@localhost ~]# cd zabbix-6.4.4
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix < database/mysql/schema.sql
Enter password:
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix < database/mysql/images.sql
Enter password:
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix < database/mysql/data.sql
Enter password:
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix < database/mysql/double.sql
Enter password:
[root@localhost zabbix-6.4.3]# mysql -u root -p zabbix < database/mysql/history_pk_prepare.sql
Enter password:
导入数据库模式后,禁用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! *
* <http://www.zabbix.com> *
***********************************************************
==================================================================
=====================================
#编译安装执行如下命令
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/conf
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
修改nginx默认根目录
修改/etc/nginx/nginx.conf root就是你创建的目录,此教程目录为/data/nginx-root
root /data/nginx-root;
修改完成systemctl restart nginx
注意,有的环境默认80没有开启,需要修改 默认端口80改成别的。
listen 11111;
listen [::]:11111;
web浏览 http://111.11.11.11
其他配置参考
https://blog.51cto.com/506554897/1766141
https://blog.51cto.com/506554897/1766150
监控参考:Monitor 分类