[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
[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!
[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';
[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 #修改配置文件
[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
[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
[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
[root@server2 ~]# cd /etc/zabbix/
[root@server2 zabbix]# vim zabbix_agentd.conf #修改以下内容
[root@server2 zabbix]# /etc/init.d/zabbix-agent start #开启服务
[root@server2 zabbix]# netstat -antlp #查看端口
方法二:先关闭自动发现,再关闭动作
关闭自动发现:
关闭动作:
创建主机
建立模板
(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"
}
(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"
}
]
}
(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"
]
}
}
[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"
}
[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