Centos 8,搭建6.4(转载)

环境:centos8
安装版本:zabbix6.4

一、Web环境搭建

1. 切换CentOS 8源为阿里源

备份原有的yum源文件,以便需要时恢复:

sudo mv /etc/yum.repos.d/CentOS-* /tmp/

下载并安装阿里云的CentOS 8源配置文件:

sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

生成缓存

sudo yum makecache

更新一下yum源:

yum -y update

如果出现这样(尝试添加 --skip-broken 来跳过无法安装的软件包 或 --nobest 来不只使用最佳选择的软件包)的报错,只需根据提示在命令结尾加上–allowerasing或–nobest后再次执行即可yum -y update --nobest
后续如果这样报错,都可以按照此方法
完成上述步骤后,就将yum镜像源更换为阿里云的了。

2. 关闭防火墙,SELINUX

systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

关闭之后,查看状态

systemctl status firewalld
systemctl status selinux-autorelabel

3. web环境搭建(安装LAMP)

LAMP和LNMP是常见的web环境,它们具体代表如下:

  • L:linux,操作系统
  • A或N:Apache或Nginx,Web服务器软件
  • M:MariaDB或MySQL,数据库软件
  • P:PHP、Perl、Python,脚本软件

 使用yum源,向系统安装MariaDB、PHP、hpptd,并借助yum解决LAMP各组件间的依赖关系

yum -y install mariadb mariadb-server php php-mysqlnd httpd

将http服务设置为开机自启

[root@hello ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

对于Apache测试,可在浏览器中搜索Apache所在的主机ip地址。如果出现以下图片,代表成功。

5. 配置数据库

[root@hello ~]# systemctl enable mariadb      #开机启动
[root@hello ~]# systemctl start mariadb       #开启数据库

安全初始化数据库

[root@hello ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

## 输入数据库root用户密码(默认为空,直接回车,若当时自己设的有,则输入),我这里设置的是有密码的
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

 ## 我在这里是在修改我原来的密码,看个人是否需要
Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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.

## 是否禁止root用户远程登陆? 否 (按回车跳过)
Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB 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? [Y/n] y
 - 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? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

至此,数据库安装并初始化完成

6. 创建Zabbix数据库及用户

[root@hello ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

## 建zabbix库,并设定utf8字符集
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.001 sec)

## 授权zabbix用户给zabbix库权限并修改密码
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit

退出数据库,再测试一下zabbix用户

[root@hello ~]# mysql -uzabbix -p123456    ##使用zabbix登录数据库
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;       ## 以zabbix身份查看所有数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.002 sec)

MariaDB [(none)]> exit     ## 退出数据库
Bye     

二、Server端安装配置

1. 软件包安装

# 1、安装zabbix仓库
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/8/x86_64/zabbix-release-6.4-1.el8.noarch.rpm
# 2、清除缓存
dnf clean all 

# 3、配置zabbix.repo文件仓库
[root@centos8 yum.repos.d]# cat zabbix.repo 
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=https://repo.zabbix.com/zabbix/6.4/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.4/rhel/8/x86_64/zabbix-release-6.4-1.el8.noarch.rpm # zabbix清华源
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository (non-supported) - $basearch
#baseurl=https://repo.zabbix.com/non-supported/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/x86_64/ # zabbix-non-supported清华源
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

[zabbix-unstable]
name=Zabbix Official Repository (unstable) - $basearch
baseurl=https://repo.zabbix.com/zabbix/5.5/rhel/8/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[root@centos8 yum.repos.d]# 

# 4、配置zabbix-agent2-plugins.repo文件仓库
[root@centos8 yum.repos.d]# cat zabbix-agent2-plugins.repo 
[zabbix-agent2-plugins]
name=Zabbix Official Repository (Agent2 Plugins) - $basearch
#baseurl=https://repo.zabbix.com/zabbix-agent2-plugins/1/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix-agent2-plugins/1/rhel/8/x86_64/ # agent2清华源
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
[root@centos8 yum.repos.d]# 

 # 安装Zabbix server,Web前端,agent
 dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2 //注意这里安装的是agent2

2. 配置数据库

2.1
配置zabbix之前,需先将其与数据库进行连接
初始数据导入数据库

zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

修改配置文件vim /etc/zabbix/zabbix_server.conf ,添加DBPassword=123456

  ##在文件的最后添加
NodeAddress=localhost:10051
AllowUnsupportedDBVersions=1
DBSocket=/var/lib/mysql/mysql.sock

2.3
更改时区

vim /etc/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai (有的话修改,没有添加)

2.4
最后,启动进程,并为它们设置开机自启。

systemctl restart zabbix-server zabbix-agent2 httpd php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd php-fpm

3. Zabbix访问测试

最后访问网址,图片是5.0,实际是6.0
http://192.168.10.125/zabbix/setup.php

输入zabbix数据库密码,我这里是123456

默认的用户是Admin,密码为zabbix,该用户是超级用户,输入登录信息后,点击Sign In按钮,进行登录

可以看到zabbix的界面

1、zabbix在现实图形的时候,中文会乱码,添加中文字体

首先,找一台win系统的电脑,进入C:\Windows\Fonts目录,这里面是window系统存放字体的地方

随便选择一个喜欢的中文字体,拖到本机的桌面。

根据不同的字形,有些字体只有一个文件,有些有多个文件。

无论是一个文件的字体还是多个文件的字体,我们只需要一个即可。

上传完成之后的使用时,.TTF需要把后缀改成小写的.ttf.ttc不需要更改后缀

可以使用任意方式将字体文件上传至zabbix的服务器。

我这里用scp直接上传。注意,如果前面修改了SSH的端口,这里的-P参数,P大写

C:\WINDOWS\system32> scp -P 55555 D:/Desktop/msyhbd.ttc root@10.100.1.159:/usr/share/zabbix/assets/fonts/
 
root@10.100.1.159's password:
msyhbd.ttc                                              100%   16MB  11.0MB/s   00:01
C:\WINDOWS\system32>

/usr/share/zabbix/assets/fonts/目录是zabbix默认存放字体的位置。

[root@localhost ~]# cd /usr/share/zabbix/assets/fonts/
[root@localhost fonts]# ls
graphfont.ttf  msyhbd.ttc

可以看到,graphfont.ttf是默认的字体文件。

可以修改配置来直接引用我们上传的字体文件,不过那样过于繁琐,我这里选择直接覆盖。

[root@localhost fonts]# cp graphfont.ttf graphfont.ttf.bak       //防止意外,备份文件
[root@localhost fonts]# ls
graphfont.ttf  graphfont.ttf.bak  msyhbd.ttc
[root@localhost fonts]# \cp msyhbd.ttc graphfont.ttf             //忽略覆盖警告,直接覆盖
[root@localhost fonts]#

3、修改默认内存设置
zabbix默认的内存是设置的很低的,我们需要手动调整。

否则内存溢出后,页面下方会不断报警zabbix server is not running

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
把原来的 # CacheSize=8M 前面的#注释去掉,将8M修改为2048M,这个2048M根据服务器性能修改。

### Option: CacheSize
#       Size of configuration cache, in bytes.
#       Shared memory size for storing host, item and trigger data.
#
# Mandatory: no
# Range: 128K-64G
# Default:
 CacheSize=2048M
重启zabbix服务。

systemctl restart zabbix_server
systemctl restart httpd
systemctl restart zabbix_agent
 

  • 38
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你好!以下是在CentOS 8上安装Zabbix 6.4的步骤: 1. 更新系统: ``` sudo dnf update ``` 2. 安装必要的软件包: ``` sudo dnf install epel-release sudo dnf install httpd mariadb-server mariadb sudo dnf install php php-mysqlnd php-ldap php-bcmath php-mbstring php-gd php-json php-xml php-xmlrpc php-gd ``` 3. 启动并设置服务: ``` sudo systemctl enable --now httpd sudo systemctl enable --now mariadb ``` 4. 配置MariaDB: ``` sudo mysql_secure_installation ``` 按照提示设置root密码和其他安全选项。 5. 创建Zabbix数据库和用户: ``` sudo mysql -u root -p CREATE DATABASE zabbix character set utf8 collate utf8_bin; GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'YourPassword'; FLUSH PRIVILEGES; quit; ``` 6. 下载并导入Zabbix数据库模式和数据: ``` wget https://repo.zabbix.com/zabbix/6.4/mysql/zabbix-6.4.0.tar.gz tar -zxvf zabbix-6.4.0.tar.gz cd zabbix-6.4.0/database/mysql sudo mysql -u zabbix -p zabbix < schema.sql sudo mysql -u zabbix -p zabbix < images.sql sudo mysql -u zabbix -p zabbix < data.sql ``` 7. 安装Zabbix服务器和前端: ``` sudo dnf install zabbix-server-mysql zabbix-web-mysql ``` 8. 配置Zabbix服务器: ``` sudo nano /etc/zabbix/zabbix_server.conf ``` 找到并修改以下行: ``` DBPassword=YourPassword ``` 9. 启动并设置Zabbix服务器和相关服务: ``` sudo systemctl enable --now zabbix-server sudo systemctl restart httpd ``` 10. 配置Zabbix前端: ``` sudo nano /etc/zabbix/web/zabbix.conf.php ``` 找到并修改以下行: ``` $DB['PASSWORD'] = 'YourPassword'; ``` 11. 设置SELinux规则(如果SELinux启用): ``` sudo setsebool -P httpd_can_connect_zabbix on ``` 12. 访问Zabbix Web界面: 在浏览器中输入服务器的IP地址或域名,并按照界面上的指引完成初始配置。 希望这对你有所帮助!如果你还有其他问题,请随时问我。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值