目录
- Centos 7 版本(不支持yum安装zabbix服务端,只能编译安装服务端)
- zabbix 6.0 版本(需要注意zabbix版本所支持的php版本,6.0版本不支持centos 7的php5.4版本),官网可查看支持的版本:Zabbix documentation
- Nginx 1.22.1 版本
- php 7.2.34 版本
- mariadb 10.5.19 版本
#关闭防火墙[root@zabbix ~]# systemctl stop firewalld[root@zabbix ~]# systemctl disable firewalld#改为宽容模式[root@zabbix ~]# sed -ri '/^SELINUX/s#enforcing#permissive#' /etc/selinux/config
主机名 | IP地址 |
zabbix | 192.168.10.150 |
zabbix-2 | 192.168.10.151 |
6
1、安装Nginx
#Nginx的yum源[root@zabbix ~]# vim /etc/yum.repos.d/nginx.repo[nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true#安装Nginx[root@zabbix ~]# yum install nginx -y
2、安装PHP
#把阿里云的base源覆盖到本地的base源[root@zabbix ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo#安装第三方epel-release源[root@zabbix ~]# yum install epel-release.noarch -y#把阿里云的epel源覆盖到本地的base源[root@zabbix ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo#第三方webtatic源[root@zabbix ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm#安装PHP[root@zabbix ~]# yum install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y
3、配置Nginx
[root@zabbix ~]# vim /etc/nginx/conf.d/conn.confserver { listen 80; server_name www.haha.com; root /app/www/haha; location / { index index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastegi_params; }}
4、配置PHP
#把www.conf配置文件里的user和group的Apache值改为Nginx[root@zabbix ~]# sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
5、创建测试目录测试文件
[root@zabbix ~]# mkdir -p /app/www/haha[root@zabbix ~]# vim /app/www/haha/info.php
6、启动Nginx和PHP
[root@zabbix ~]# systemctl enable nginx php-fpm --now
7、测试
#修改hosts文件,在C:\Windows\System32\drivers\etc\hosts
1、安装mariadb
#配置mariadb的yum源[root@zabbix ~]# vim /etc/yum.repos.d/mariadb.repo[mariadb]name=Mariadbbaseurl=http://mirrors.aliyun.com/mariadb/yum/10.5/centos7-amd64/gpgkey=http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDBgpgcheck=1enabled=1#安装mariadb[root@zabbix ~]# yum install mariadb-server -y#启动并开机自启[root@zabbix ~]# systemctl enable mariadb --now
2、初始化
#数据库的初始化[root@zabbix ~]# mysql_secure_installation Enter current password for root (enter for none): 直接回车,新用户没密码Switch to unix_socket authentication [Y/n] 输入nChange the root password? [Y/n] 输入Y,改root密码Remove anonymous users? [Y/n] 输入YDisallow root login remotely? [Y/n] 输入YRemove test database and access to it? [Y/n] 输入YReload privilege tables now? [Y/n] 输入Y
3、创建库及用户
[root@zabbix ~]# mysql -uroot -p#创建数据库zabbix,字符集为utf8MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;#创建用户zabbix,密码zabbix,并授权,只能在本地登录MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
4、向数据库中导入数据
#下载源码包
#下载包[root@zabbix ~]# wget -c https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.14.tar.gz[root@zabbix ~]# tar -xzvf zabbix-6.0.14.tar.gz [root@zabbix ~]# cd zabbix-6.0.14/database/mysql/#导入数据,注意顺序#-p是密码[root@zabbix mysql]# mysql -uroot -predhat zabbix
1、安装
- 安装依赖
[root@zabbix ~]# yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel gcc gcc-c++
- 编译安装
[root@zabbix ~]# cd zabbix-6.0.14[root@zabbix zabbix-6.0.14]# ./configure --sysconfdir=/etc/zabbix --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre [root@zabbix zabbix-6.0.14]# make install
--sysconfdir=/etc/zabbix #指定配置文件路径
--enable-server #安装服务端
--with-mysql #开启数据库mysql的支持
#安装依赖与功能
--with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre
2、修改配置文件
[root@zabbix zabbix-6.0.14]# vim /etc/zabbix/zabbix_server.conf把DBHost=localhost和DBPassword=和ListenPort=10051前面的注释删掉,并且设置为DBPassword=zabbix。注意:DBName为你的数据库名,DBUser为你的用户名,DBPassword为你的密码
- 启动zabbix-server
#由于编译安装zabbix服务端,需要添加虚拟用户[root@zabbix zabbix-6.0.14]# useradd -s /usr/sbin/nologin -M zabbix#启动zabbix[root@zabbix zabbix-6.0.14]# zabbix_server #检查zabbix进程[root@zabbix zabbix-6.0.14]# ps -ef | grep zabbix#检查zabbix端口[root@zabbix zabbix-6.0.14]# ss -lntup | grep 10051
- 书写systemctl配置文件
[root@zabbix zabbix-6.0.14]# vim /usr/lib/systemd/system/zabbix-server.service[Unit]Description=Zabbix Server with Mysql DBAfter=syslog.target network.target mysqld.service[Service]Type=simpleExecStart=/usr/local/sbin/zabbix_server -fUser=zabbix[Install]WantedBy=multi-user.target[root@zabbix zabbix-6.0.14]# systemctl reload#需要先把手动的关闭,在systemctl[root@zabbix zabbix-6.0.14]# pkill zabbix[root@zabbix zabbix-6.0.14]# systemctl enable zabbix-server --now #检查zabbix-server是否启动[root@zabbix zabbix-6.0.14]# systemctl status zabbix-server
3、配置前端代码进行web访问
[root@zabbix ~]# cp -r zabbix-6.0.14/ui/* /app/www/haha/[root@zabbix ~]# chown -R nginx.nginx /app/www/haha/
#修改比要求大的就行[root@zabbix ~]# vim /etc/php.ini post_max_size = 16Mmax_input_time = 300max_execution_time = 300[root@zabbix ~]# systemctl restart php-fpm
#自我监控
#从清华镜像下载zabbix源[root@zabbix ~]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-1.el7.noarch.rpm #更换为清华的镜像[root@zabbix ~]# sed -i 's#https://repo.zabbix.com/zabbix#https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix#g' /etc/yum.repos.d/zabbix.repo [root@zabbix ~]# yum install zabbix-agent2 -y#修改配置文件,自我监控就不用,server为zabbix的服务端地址[root@zabbix ~]# vim /etc/zabbix/zabbix_agent2.conf Server=127.0.0.1[root@zabbix ~]# systemctl enable zabbix-agent2 --now
#再次查看web页面
安装完成!
#上传一个中文的ttf字体替换zabbix的即可,windows的字体路径C:\Windows\Fonts
[root@zabbix ~]# cd /app/www/haha/assets/fonts/[root@zabbix fonts]# cp DejaVuSans.ttf{,.bak}#用xftp上传字体,名字也要跟这个一样,我用的是微软雅黑[root@zabbix fonts]# mv msyh.ttc DejaVuSans.ttfmv: overwrite ‘DejaVuSans.ttf’? y#重新刷新一下页面即可,不用重启
#但还是有些字体还会有点乱码
1、安装zabbix客户端
#安装依赖[root@zabbix-2 ~]# yum install pcre2 pcre2-devel -y#只需要安装个客户端即可[root@zabbix-2 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent2-6.0.7-1.el7.x86_64.rpm#配置zabbix服务端地址[root@zabbix-2 ~]# sed -i '/^Server/s#127.0.0.1#192.168.10.150#g' /etc/zabbix/zabbix_agent2.conf #启动并开机[root@zabbix-2 ~]# systemctl enable zabbix-agent2 --now
2、web页面添加主机
[root@zabbix ~]# systemctl restart zabbix-server
#如果再创建一个客户端,直接克隆,如下
来源地址:https://blog.csdn.net/weixin_59128094/article/details/129815872