安装部署zabbix监控架构
部署环境:vmware 虚拟机 系统:centos7 zabbix 5.0 web应用:Nginx php 72 mariadbb
安装部署服务端
# 配置阿里源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 配置zabbix 5.0源
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm`
[root@localhost ~]# yum makecache
# 安装zabbix服务端和客户端
[root@localhost ~]# yum install zabbix-server-mysql zabbix-agent
# 安装依赖,用于调取zabbix源
[root@localhost ~]# yum install centos-release-scl -y
# 修改zabbix源,启用zabbix前端源
[root@localhost ~]# sed -i '0,/enabled=0/s/enabled=0/enabled=1/g' /etc/yum.repos.d/zabbix.repo
[root@localhost ~]# yum makecache
# 安装mariadb-server
[root@localhost ~]# yum install mariadb-server
[root@localhost ~]# systemctl enable mariadb
# 配置mariadb,并导入zabbix数据库
[root@localhost ~]# 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.
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.
Set 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.
Disallow root login remotely? [Y/n] n
... skipping.
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!
[root@localhost ~]# mysql -uroot -p
# 创建zabbix数据库,并导入数据表
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-5.0.17/create.sql.gz > zabbix.sql
[root@localhost ~]# mysql -uroot -p zabbix < ./zabbix.sql
# 添加zabbix用户权限
[root@localhost ~]# mysql -uroot -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.68-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)]> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
# 修改zabbix-server配置文件,默认数据库和用户都为zabbix,只需要加入以上添加的密码即可,如果是自命名数据库可使用同样方法修改DBName和DBUser
[root@localhost ~]# sed -i 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
#配置zabbix-web部分
# 给zabbix默认的web服务器是apache,这里使用的是nginx,所以在listen.acl_users配置项添加nginx
[root@localhost rh-php72]# sed -i 's/listen.acl_users = apache/listen.acl_users = apache,nginx/g' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
# 修改[date.timezone]时区,配置为Asia/Shanghai
[root@localhost rh-php72]# sed -i 's/\; php_value\[date.timezone\] \= Europe\/Riga/php_value\[date.timezone\] \= Asia\/Shanghai/g' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#修改zabbix自带的nginx,将zabbix web页面端口设置为8080
[root@localhost rh-nginx116]# sed -ie '4a\\tlisten 8080;' /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
# 启动zabbix
[root@localhost rh-nginx116]# systemctl start zabbix-server rh-php72-php-fpm rh-nginx116-nginx
[root@localhost rh-nginx116]# systemctl enable zabbix-server rh-php72-php-fpm rh-nginx116-nginx
# 解决中文图表显示乱码
[root@master ~]# yum -y install wqy-microhei-fonts
[root@master ~]# cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
cp: overwrite ‘/usr/share/fonts/dejavu/DejaVuSans.ttf’? y
通过web页面配置zabbix
- 在浏览器输入http://localhost:8080登录zabbix
配置客户端
Zabbix-agent2 是一款新的agent,未来有可能替代原有的agent。 特性:
安装
# 配置源
# 配置阿里云源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 配置zabbix 5.0源
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 配置时间同步
# 安装agen2
[root@agent ~]# yum install -y zabbix-agent2
# 修改配置文件,让zabbix-server发现agent
[root@agent ~]# sed -i 's/^Server=127.0.0.1/Server=192.168.100.10/g' /etc/zabbix/zabbix_agent2.conf
# 启动zabbix-agent2,启动之后即可通过web页面添加被监控的主机了
[root@agent ~]# systemctl start zabbix-agent2
在网页添加被监控主机
- 点击配置->主机->创建主机
- 输入被监控主机的ip等信息,根据自己配置来填
- 在点击模板项,给监控主机添加zabbix自带的监控项
- 添加主机成功
|