zabbix4.0监控-service部署(一)

安装zabbix环境

三台机器 主机名字:zabbix-server agentd1 agentd2

[root@zabbix-server ~]# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core) 
[root@zabbix-server ~]# uname -a                
Linux zabbix-server 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@zabbix-server ~]# 

相同配置

centos系统配置yum源 

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

自己创建一个Centos-7.repo 把curl 东西放进去
curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo > /etc/yum.repos.d/Centos-7.repo

yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存

配置epel源

[root@zabbix-server yum.repos.d]# yum list | grep epel-release #查看可用epel源
epel-release.noarch                         7-11                       extras   
[root@zabbix-server yum.repos.d]# 

下载epel源(三台)

wget -O /etc/yum.repos.d/epel-7.repo  http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all # 清除系统所有的yum缓存 
yum makecache # 生成yum缓存

1、配置zabbix yum仓库源

清华源地址:mirror.tuna.tsinghua.edu.cn

[root@zabbix-server ~]# wget https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm  #下载4.0版本
--2020-10-22 21:43:55--  https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
正在解析主机 mirror.tuna.tsinghua.edu.cn (mirror.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirror.tuna.tsinghua.edu.cn (mirror.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:13800 (13K) [application/x-redhat-package-manager]
正在保存至: “zabbix-release-4.0-2.el7.noarch.rpm”

100%[====================================================================================================================================>] 13,800      --.-K/s 用时 0s      

2020-10-22 21:44:00 (61.5 MB/s) - 已保存 “zabbix-release-4.0-2.el7.noarch.rpm” [13800/13800])
[root@zabbix-server ~]# rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm  #安装
警告:zabbix-release-4.0-2.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-4.0-2.el7         ################################# [100%]
[root@zabbix-server ~]# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-4.0
/usr/share/doc/zabbix-release-4.0/GPL #GPL协议

 !!!发现/etc/yum.repos.d/zabbix.repo 里面zabbix源下载不是很快 所以更改一下地址 不用zabbix官网的源了 用清华的

打开清华源地址 mirror.tuna.tsinghua.edu.cn 找到目录 复制https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/ 替换zabbix.repo

vim 打开文件 替换两条记录

:%s#repo.zabbix.com#mirror.tuna.tsinghua.edu.cn/zabbix#g
:%s#gpgcheck=1#gpgcheck=0#g   #GPG验证是否开启的选项,1是开启,0是不开启,一般情况可以关掉

2、安装zabbix服务端和zabbix-web前端

yum install zabbix-server-mysql zabbix-web-mysql  -y

 

 3:安装mariadb,创建zabbix库,授权zabbix用户

yum install mariadb-server -y
systemctl start mariadb  #启动
systemctl enable mariadb  #开机自启动

 

 这个命令可以方便设置删除授权表的修改 个人认为还不错

[root@zabbix-server yum.repos.d]# 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] n   #--为root用户设置密码
 ... skipping.

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] y  #--取消root用户远程登录
 ... 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  #--删除test库和对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? [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!

 

 进入Mariadb

[root@zabbix-server yum.repos.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.65-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)]> create database zabbix character set utf8 collate utf8_bin; #设置字符集为UFT8 不然显示中文有问题
Query OK, 1 row affected (0.00 sec)

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

MariaDB [(none)]> 

 

 导入zabbix表结构和初始数据

!!!怎么找到zabbix表结构和初始化数据的sql文件呢???

[root@zabbix-server yum.repos.d]# rpm -ql zabbix-server-mysql |grep sql
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-4.0.25
/usr/share/doc/zabbix-server-mysql-4.0.25/AUTHORS
/usr/share/doc/zabbix-server-mysql-4.0.25/COPYING
/usr/share/doc/zabbix-server-mysql-4.0.25/ChangeLog
/usr/share/doc/zabbix-server-mysql-4.0.25/NEWS
/usr/share/doc/zabbix-server-mysql-4.0.25/README
/usr/share/doc/zabbix-server-mysql-4.0.25/create.sql.gz
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix #导入到mysql里面

 

 检查zabbix库是否导入成功

[root@zabbix-server yum.repos.d]# mysql -uroot  zabbix -e 'show tables'
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
。。。。
。。。。 省略。。。
。。。。 | widget | | widget_field | +----------------------------+ [root@zabbix-server yum.repos.d]#

 

 4:配置启动zabbix-server

#配置
vi /etc/zabbix/zabbix_server.conf 
DBHost=localhost  
DBName=zabbix
DBUser=zabbix
DBPassword=123456

#启动
systemctl start zabbix-server 
systemctl enable zabbix-server

#检查
[root@zabbix-server yum.repos.d]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1722/master         
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      22826/zabbix_server 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      22606/mysqld        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1506/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1722/master         
tcp6       0      0 :::10051                :::*                    LISTEN      22826/zabbix_server 
tcp6       0      0 :::22                   :::*                    LISTEN      1506/sshd           

 

 5:修改Zabbix前端的PHP配置,并启动httpd

vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai  #修改时区 亚洲/上海
systemctl start httpd  #启动
systemctl enable httpd #自启动

 6:前端zabbix-web的安装

浏览器:http://xx.xx.xx.xx/zabbix

提示信息:

后期修改zabbix数据库密码的时候,需要修改的配置文件:
/etc/zabbix/web/zabbix.conf.php
​
http://192.168.123.89/zabbix/zabbix.php
登录的账号密码;
Admin
zabbix

先把自己监控上

[root@zabbix-server yum.repos.d]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.11-1.el7.x86_64.rpm
获取https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.11-1.el7.x86_64.rpm  #安装zabbix-agent
警告:/var/tmp/rpm-tmp.pQDAJI: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-agent-4.0.11-1.el7        ################################# [100%]
[root@zabbix-server yum.repos.d]# systemctl start  zabbix-agent  #启动
[root@zabbix-server yum.repos.d]# systemctl enable  zabbix-agent #开机自启动
ln -s '/usr/lib/systemd/system/zabbix-agent.service' '/etc/systemd/system/multi-user.target.wants/zabbix-agent.service'
[root@zabbix-server yum.repos.d]# 
[root@zabbix-server yum.repos.d]# 
[root@zabbix-server yum.repos.d]# systemctl enable  zabbix-agent
[root@zabbix-server yum.repos.d]# systemctl restart mariadb

 

 

#次文件用于个人笔记记录 不可转载

posted on 2020-10-23 14:54  I我非柠檬为何心酸I  阅读(223)  评论(0编辑  收藏  举报