zabbix安装以及部署

一·下载安装包

[root@server1 ~]# ls     
fping-3.10-1.el7.x86_64.rpm            zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm
iksemel-1.4-2.el7.centos.x86_64.rpm    zabbix-proxy-mysql-3.4.6-1.el7.x86_64.rpm
php-bcmath-5.4.16-42.el7.x86_64.rpm    zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm  zabbix-web-3.4.6-1.el7.noarch.rpm
zabbix-agent-3.4.6-1.el7.x86_64.rpm    zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
zabbix-get-3.4.6-1.el7.x86_64.rpm
[root@server1 ~]# yum install -y *.rpm    
[root@server1 ~]# cd /etc/zabbix/
[root@server1 zabbix]# ls
web                 zabbix_java_gateway.conf         zabbix_server.conf
zabbix_agentd.conf  zabbix_java_gateway_logback.xml
zabbix_agentd.d     zabbix_proxy.conf

zabbix安装以及部署_第1张图片

二·下载mysql

1.修改密码

[root@server1 zabbix]# yum install -y mariadb-server
[root@server1 zabbix]# systemctl start mariadb
[root@server1 zabbix]# 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] 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!

2.授权以及建立库

[root@server1 zabbix-server-mysql-3.4.6]# mysql -p
MariaDB [mysql]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [mysql]> grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';

zabbix安装以及部署_第2张图片

[root@server1 ~]# cd /usr/share/doc/
[root@server1 doc]# cd zabbix-server-mysql-3.4.6/
[root@server1 zabbix-server-mysql-3.4.6]# zcat create.sql.gz | mysql -u zabbix -p zabbix    #导入数据库(输入密码后,需要等待)
[root@server1 zabbix-server-mysql-3.4.6]# cd /etc/zabbix/
[root@server1 zabbix]# ls
[root@server1 zabbix]# vim zabbix_server.conf    #修改配置文件

zabbix安装以及部署_第3张图片

[root@server1 zabbix]# cd /etc/httpd/
[root@server1 httpd]# cd conf.d/
[root@server1 conf.d]# vim zabbix.conf    #修改时区
[root@server1 conf.d]# systemctl start zabbix-server    #开启服务
[root@server1 conf.d]# systemctl enable zabbix-server    #开机自起
[root@server1 conf.d]# systemctl start httpd   #开启服务
[root@server1 conf.d]# systemctl enable httpd

zabbix安装以及部署_第4张图片

[root@server1 conf.d]# cd
[root@server1 ~]# ls
zabbix-agent-3.4.6-1.el7.x86_64.rpm
[root@server1 ~]# yum install zabbix-agent-3.4.6-1.el7.x86_64.rpm  -y
[root@server1 ~]# systemctl start zabbix-agent

三·访问网页:172.25.41.11/zabbix

zabbix安装以及部署_第5张图片
zabbix安装以及部署_第6张图片
zabbix安装以及部署_第7张图片
zabbix安装以及部署_第8张图片
zabbix安装以及部署_第9张图片
zabbix安装以及部署_第10张图片
zabbix安装以及部署_第11张图片

2.切换中文

zabbix安装以及部署_第12张图片

3.修改密码(更改密码后重新登陆)

zabbix安装以及部署_第13张图片
zabbix安装以及部署_第14张图片

四·客户端server2

1.安装zabbix-agent

[root@server2 ~]# ls
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server2 ~]# rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm

2.修改配置文件

[root@server2 ~]# cd /etc/zabbix/
[root@server2 zabbix]# vim zabbix_agentd.conf    #修改以下内容

这里写图片描述
zabbix安装以及部署_第15张图片

[root@server2 zabbix]# /etc/init.d/zabbix-agent start    #开启服务
[root@server2 zabbix]# netstat -antlp  #查看端口

zabbix安装以及部署_第16张图片

五·网页添加主机

1.手动添加

方法一:
zabbix安装以及部署_第17张图片
zabbix安装以及部署_第18张图片
zabbix安装以及部署_第19张图片
zabbix安装以及部署_第20张图片
点击主机查看是否添加成功
zabbix安装以及部署_第21张图片

方法二:先关闭自动发现,再关闭动作
关闭自动发现:
zabbix安装以及部署_第22张图片
关闭动作:
zabbix安装以及部署_第23张图片
zabbix安装以及部署_第24张图片
创建主机
zabbix安装以及部署_第25张图片
建立模板
zabbix安装以及部署_第26张图片
zabbix安装以及部署_第27张图片

2.自动添加

删除添加的server2
zabbix安装以及部署_第28张图片
zabbix安装以及部署_第29张图片
zabbix安装以及部署_第30张图片
zabbix安装以及部署_第31张图片
zabbix安装以及部署_第32张图片

3.用api删除

(1)

[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": "westos"
    },
    "id": 1,
    "auth": null
}' http://172.25.41.11/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# chmod +x ./zabbix-api.sh
[root@server1 ~]# ./zabbix-api.sh
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "a22f5f33dfc64d0cd969243f07d54977"
}

zabbix安装以及部署_第33张图片
zabbix安装以及部署_第34张图片

(2)

[root@server1 ~]# vim zabbix-api.sh 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["host"]
    },
    "auth": "a22f5f33dfc64d0cd969243f07d54977",
    "id": 1
}' http://172.25.41.11/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": "server2",
            "hostid": "10256"
        }
    ]
}

zabbix安装以及部署_第35张图片
zabbix安装以及部署_第36张图片

(3)

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.delete",
    "params": [
        "10256"
    ],
    "auth": "a22f5f33dfc64d0cd969243f07d54977",
    "id": 1
}' http://172.25.41.11/zabbix/api_jsonrpc.php | python -m json.tool

[root@server1 ~]#  ./zabbix-api.sh   #执行结果
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10256"
        ]
    }
}

zabbix安装以及部署_第37张图片
zabbix安装以及部署_第38张图片

网页查看时,添加的信息已删除
zabbix安装以及部署_第39张图片

4.用api添加

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "server2",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "172.25.41.11",
                "dns": "",
                "port": "10256"
            }
        ],
        "groups": [
            {
                "groupid": "0"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "auth": "a22f5f33dfc64d0cd969243f07d54977",
    "id": 1
}' http://172.25.41.11/zabbix/api_jsonrpc.php | python -m json.tool

[root@server2 ~]# ./zabbix-api.sh
{
    "error": {
        "code": -32500, 
        "data": "No permissions to referred object or it does not exist!", 
        "message": "Application error."
    }, 
    "id": 1, 
    "jsonrpc": "2.0"
}

zabbix安装以及部署_第40张图片
zabbix安装以及部署_第41张图片

网页会看到,已添加
zabbix安装以及部署_第42张图片

5.手动添加httpd和mysql模块

[root@server1 ~]# mkdir /var/lib/zabbix
[root@server1 ~]# cd /var/lib/zabbix/
[root@server1 zabbix]# vim .my.cnf
[mysql]
user=root
password=westos
socket=/var/lib/mysql/mysql.scok
[mysqladmin]
user=root
password=westos
socket=/var/lib/mysql/mysql.scok
[root@server1 zabbix]# systemctl restart zabbix-agent

添加httpd和mysql
zabbix安装以及部署_第43张图片
查看
zabbix安装以及部署_第44张图片
zabbix安装以及部署_第45张图片

你可能感兴趣的:(zabbix安装以及部署)