您的位置:首页 > 其它

zabbix安装部署

2018-08-16 10:06 330 查看

###实验环境
iptables和selinux关闭
redhat7.3:zabbix-server
server1:172.25.35.61
redhat6.5:zabbix-agent
server6:172.25.35.56
###zabbix-server

[root@server1 ~]# yum install fping-3.10-1.el7.x86_64.rpm  php-bcmath-5.4.16-42.el7.x86_64.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm iksemel-1.4-2.el7.centos.x86_64.rpm zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm
zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
-y
// 下载安装时,redhat7.0版本需要安装 php-bcmath-5.4.16-21.el7.x86_64.rpm php-mbstring-5.4.16-21.el7.x86_64.rpm
redhat7.2版本需要安装 php-bcmath-5.4.16-36.el7.x86_64.rpm php-mbstring-5.4.16-36.el7.x86_64.rpm

[root@server1 ~]# yum install mariadb-server -y  //安装数据库
[root@server1 ~]# systemctl start mariadb
[root@server1 ~]# 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] y
... 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]
- 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]
... 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@server1 ~]# mysql -p
Enter password:
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;  //创建数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'ZhanG@2424';  //创建用户并授权
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@server1 ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.6/
[root@server1 zabbix-server-mysql-3.4.6]# ls
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@server1 zabbix-server-mysql-3.4.6]# zcat create.sql.gz | mysql -u zabbix -p zabbix   //导入数据库,第一个zabbix为zabbix用户,第二个zabbix是创建的数据库名
Enter password:  //输入授权用户zabbix的密码
[root@server1 zabbix-server-mysql-3.4.6]# cd /etc/zabbix
[root@server1 zabbix]# vim zabbix_server.conf
125         DBPassword=ZhanG@2424
132         DBSocket=/var/lib/mysql/mysql.sock
[root@server1 zabbix]# yum install httpd
[root@server1 zabbix]# vim /etc/httpd/conf.d/zabbix.conf //修改时区
19         php_value date.timezone Asia/Shanghai
[root@server1 zabbix]# systemctl start zabbix-server
[root@server1 zabbix]# systemctl start httpd
[root@server1 zabbix]# cd
[root@server1 ~]# yum install zabbix-agent-3.4.6-1.el7.x86_64.rpm -y
[root@server1 ~]# systemctl start zabbix-agent

浏览器:


登录输入的是数据库授权zabbix的登录密码:




输入zabbix原始用户名Admin,密码zabbix:

登录进去之后:

点击人头修改语言和密码,重新登陆,用户依旧是Admin:


在主机可以看到zabbix-server

###zabbix-agent

[root@server6 ~]# rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm
warning: zabbix-agent-3.4.6-1.el6.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
1:zabbix-agent           ########################################### [100%]
[root@server6 ~]# cd /etc/zabbix/
[root@server6 zabbix]# vim zabbix_agentd.conf
97 Server=172.25.35.61
138 ServerActive=172.25.35.61  //zabbix-server的ip
149 Hostname=server6  //本机名称,一定要在本机解析
[root@server6 zabbix]# vim /etc/hosts  //写入本地解析
172.25.35.56 server6
[root@server6 zabbix]# /etc/init.d/zabbix-agent start  //开启服务
[root@server6 zabbix]# netstat -antlp
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      2110/zabbix_agentd

###服务器(zabbix web)添加监控
####添加方式一:自动添加
点击动作->右上角选择事件源:自动发现

点击自动发现,点击Local network添加网段

点击停用的,将自动发现启用

等待一会即可在主机查看到zabbix-agent

####添加方式二:手动添加
先关闭自动发现,再关闭动作
点击创建主机:

主机名称为客户端主机名称,群组:linux servers

点击模版,添加模块:

添加完毕:

刷新一下:变成可用

####方式三:自动注册
删除刚才添加的zabbix-agent:server6
选择自动注册,点击创建动作

添加名称:

点击新的:

添加主机、添加到主机群组选择linux servers、连接到模版选择Template OS linux

点击未启用,之后变成启用

等一会即可看见自动添加进去

###用api删除zabbix-agent

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "ZhanG@2424"  //这里的密码是在server web修改过的密码
},
"id": 1,
"auth": null
}' http://172.25.35.61/zabbix/api_jsonrpc.php | python -m json.tool
//这里的ip是zabbix-server的
[root@server1 ~]# chmod +x ./zabbix-api.sh
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": "3b31002c01ecc1bf9164c67eb17f5e14"
}

[root@server1 ~]# vim zabbix-api.sh  //获取zabbix-agent的主机信息
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host"]
},
"auth": "3b31002c01ecc1bf9164c67eb17f5e14",
//这里的内容是上一步执行出来显示的结果
"id": 1
}' http://172.25.35.61/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server",
"hostid": "10084"
},
{
"host": "server6",
"hostid": "10261"
}
]
}

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10261"   //这里是上一步执行出来显示的hostid
],
"auth": "3b31002c01ecc1bf9164c67eb17f5e14",
"id": 1
}' http://172.25.35.61/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10261"
]
}
}

刷新浏览器,刚才添加的已经删除:

####用api添加zabbix-agent

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server6",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.35.61",   //zabbix-server的ip
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
//可以在zabbix web中点击主集群组中的linux server,上面的地址栏会显示groupid
}
],
"templates": [
{
"templateid": "10001"
//点击模版OS linux,上面的地址栏会显示templateid
}
]
},
"auth": "3b31002c01ecc1bf9164c67eb17f5e14",
"id": 1
}' http://172.25.35.61/zabbix/api_jsonrpc.php | python -m json.tool

[root@server1 ~]# ./zabbix-api.sh
{
"error": {
"code": -32602,
"data": "Host with the same name \"server6\" already exists.",
"message": "Invalid params."
},
"id": 1,
"jsonrpc": "2.0"
}

浏览器查看已经添加:

####添加模版
1、添加http、mysql模块

[root@server1 ~]# yum install httpd -y
[root@server1 ~]# systemctl start httpd
[root@server1 ~]# mkdir /var/lib/zabbix
[root@server1 ~]# cd /var/lib/zabbix/
[root@server1 zabbix]# vim .my.cnf
[mysql]
user=root
password=ZhanG@2424
socket=/var/lib/mysql/mysql.scok
[mysqladmin]
user=root
password=ZhanG@2424
socket=/var/lib/mysql/mysql.scok
[root@server1 zabbix]# systemctl restart zabbix-agent


查看已经添加:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: