# zabbix

1、部署zabbix-server

```docker
docker run --name zabbix-mysql-server --hostname zabbix-mysql-server \
-e MYSQL_ROOT_PASSWORD="123456" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_DATABASE="zabbix" \
-p 3306:3306 \
-d mysql:5.7 --character-set-server=utf8 --collation-server=utf8_bin
```

```docker
docker run --name zabbix-server-mysql --hostname zabbix-server-mysql \
--link zabbix-mysql-server:mysql \
-e DB_SERVER_HOST="mysql" \
-e MYSQL_USER="zabbix" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_PASSWORD="123456" \
-v /etc/localtime:/etc/localtime:ro \
-v /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
-v /data/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
-p 10051:10051 \
-d zabbix/zabbix-server-mysql
```

```docker
docker run --name zabbix-web-nginx-mysql --hostname zabbix-web-nginx-mysql \
--link zabbix-mysql-server:mysql \
--link zabbix-server-mysql:zabbix-server \
-e DB_SERVER_HOST="mysql" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="123456" \
-e MYSQL_DATABASE="zabbix" \
-e ZBX_SERVER_HOST="zabbix-server" \
-e PHP_TZ="Asia/Shanghai" \
-p 8000:80 \
-p 8443:443 \
-d zabbix/zabbix-web-nginx-mysql
```

浏览器访问 [http://127.0.0.1:8000](http://127.0.0.1:8000)  默认登录 username: Admin password: zabbix

2、部署zabbix-agent

```docker
docker run --name zabbix-agent \
--link zabbix-server-mysql:zabbix-server \
-d zabbix/zabbix-agent:latest
```

说明下，mysql没做数据卷的映射，nginx也没做数据卷的映射，在实际生产环境下，最好做数据映射。防止数据丢失。&#x20;

docker-zabbbix-agent的安装以及链接zabbix-server 最后需要在web端将，zabbix-agent添加到zabbix-server的host列表里面。

```bash
#!/bin/bash
rpm -Uvh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.3-1.el7.x86_64.rpm
yum install -y zabbix-agent
sed -i "s/Server=127.0.0.1/Server=ZABBIX服务器IP/g" /etc/zabbix/zabbix_agentd.conf
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
netstat -anpt | grep zabbix
yum -y install lsof && lsof -i:10050 && curl ifconfig.me && hostname
```

