Santiago_hao

 

记离线部署docker,以及docker下部署zabbix

一、离线安装docker

下载地址:https://download.docker.com/linux/static/stable/x86_64/

上传软件并解压

[root@localhost opt]# tar xvf docker-20.10.3.tgz

[root@localhost opt]# cp docker/* /usr/bin/

配置system启动脚本

[root@localhost ~]# vim /etc/systemd/system/docker.service

=========================================================================

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service

Wants=network-online.target

 

[Service]

Type=notify

# the default is not to use systemd for cgroups because the delegate issues still

# exists and systemd currently does not support the cgroup feature set required

# for containers run by docker

ExecStart=/usr/bin/dockerd

ExecReload=/bin/kill -s HUP $MAINPID

# Having non-zero Limit*s causes performance problems due to accounting overhead

# in the kernel. We recommend using cgroups to do container-local accounting.

LimitNOFILE=infinity

LimitNPROC=infinity

LimitCORE=infinity

# Uncomment TasksMax if your systemd version supports it.

# Only systemd 226 and above support this version.

#TasksMax=infinity

TimeoutStartSec=0

# set delegate yes so that systemd does not reset the cgroups of docker containers

Delegate=yes

# kill only the docker process, not all processes in the cgroup

KillMode=process

# restart the docker process if it exits prematurely

Restart=on-failure

StartLimitBurst=3

StartLimitInterval=60s

 

[Install]

WantedBy=multi-user.target

============================================================================

[root@localhost ~]# chmod +x /etc/systemd/system/docker.service   #添加执行权限

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl start docker    

二、找一台测试机,可以连接外网的,下载docker 镜像

1.启动一个空的Mysql服务器实例

[root@localhost ~]# docker run --name mysql-server -t \

>       -e MYSQL_DATABASE="zabbix" \

>       -e MYSQL_USER="zabbix" \

>       -e MYSQL_PASSWORD="zabbix" \

>       -e MYSQL_ROOT_PASSWORD="zabbix" \

>       -d mysql:5.7  \

> --character-set-server=utf8 --collation-server=utf8_bin

55567956f8c4b459bb92c70d7e59fcfb696378a183f6976c36c52019afbf9b18

 

2. 启动Zabbix Java gateway实例

[root@localhost ~]# docker run --name zabbix-java-gateway -t \

       -d zabbix/zabbix-java-gateway:latest

 

3.启动Zabbix server实例,并关联这个实例到已创建的MySQL服务器实例

[root@localhost ~]# docker run --name zabbix-server-mysql -t \

>       -e DB_SERVER_HOST="mysql-server" \

>       -e MYSQL_DATABASE="zabbix" \

>       -e MYSQL_USER="zabbix" \

>       -e MYSQL_PASSWORD="zabbix" \

>       -e MYSQL_ROOT_PASSWORD="zabbix" \

>       --link mysql-server:mysql \

>       -p 10051:10051 \

>       -d zabbix/zabbix-server-mysql:latest

4c4f36eec30f51cb693f7ac4115403878563ba13b5760ff0dad2b11a4417c326

 

4.启动Zabbix web 接口,并将它与MySQL服务器实例和Zabbix server实例关联

[root@localhost ~]# docker run --name zabbix-web-nginx-mysql -t \

     -e DB_SERVER_HOST="mysql-server" \

     -e MYSQL_DATABASE="zabbix" \

     -e MYSQL_USER="zabbix" \

     -e MYSQL_PASSWORD="zabbix" \

     -e MYSQL_ROOT_PASSWORD="zabbix" \

     --link mysql-server:mysql \

     --link zabbix-server-mysql:zabbix-server \

     -p 8080:8080 \                         (此处我用8080:80和80:80web无法登录)

     -d zabbix/zabbix-web-nginx-mysql:latest

1c8e8f900f55e55d90626fbce092e8b2c682c2dedcaaa4724981d07a2c9934e5

打包镜像:

[root@localhost ~]# docker save -o docker-zabbix.gz mysql:5.7 zabbix/zabbix-web-nginx-mysql:latest zabbix/zabbix-server-mysql:latest   #打包三个镜像

三、离线服务器上部署zabbix

上传打包好的镜像到离线服务器,导入镜像

[root@localhost opt]# docker load -i docker-zabbix.gz

 

 

 

启动镜像,方法同有网络情况一样。

=============================================================================

[root@localhost ~]# docker run --name mysql-server -t \

       -e MYSQL_DATABASE="zabbix" \

        -e MYSQL_USER="zabbix" \

       -e MYSQL_PASSWORD="zabbix" \

        -e MYSQL_ROOT_PASSWORD="zabbix" \

        -d mysql:5.7  \

  --character-set-server=utf8 --collation-server=utf8_bin

ae216318a740c8a36e160d3dd7c9b528b7f9c018dfe98b61bb65587b23214848

[root@localhost ~]# docker run --name zabbix-server-mysql -t \

      -e DB_SERVER_HOST="mysql-server" \

      -e MYSQL_DATABASE="zabbix" \

      -e MYSQL_USER="zabbix" \

      -e MYSQL_PASSWORD="zabbix" \

      -e MYSQL_ROOT_PASSWORD="zabbix" \

      --link mysql-server:mysql \

      -p 10051:10051 \

>      -d zabbix/zabbix-server-mysql:latest

c0c65c3ab0adbc1eb97b3123062d9baad60efc0c98d35f376d81cb08821a6334

[root@localhost ~]# docker run --name zabbix-web-nginx-mysql -t \

     -e DB_SERVER_HOST="mysql-server" \

      -e MYSQL_DATABASE="zabbix" \

      -e MYSQL_USER="zabbix" \

      -e MYSQL_PASSWORD="zabbix" \

      -e MYSQL_ROOT_PASSWORD="zabbix" \

      --link mysql-server:mysql \

      --link zabbix-server-mysql:zabbix-server \

      -p 8080:8080 \

      -d zabbix/zabbix-web-nginx-mysql:latest

aaac9539cc1e4dd47223ad805f4ccf2423a000b13f68e1a5db08e630916e8028

[root@localhost ~]# docker ps

=============================================================================

通过http://service_ip:8080/登录

用户名:Admin

密码:zabbix

 

 

修改时区和语言

 

四、Zabbix客户端部署

下载地址:

https://www.zabbix.com/download_agents?version=5.2&release=5.2.3&os=Linux&os_version=3.0&hardware=amd64&encryption=No+encryption&packaging=Archive

上传tar包

[root@localhost zabbix_agent]# tar xvf zabbix_agent-5.2.3-linux-3.0-amd64-static.tar.gz

[root@localhost local]# mkdir zabbix-agent

[root@localhost local]# mv /opt/zabbix_agent/* /usr/local/zabbix-agent/

 

 

创建软连接

[root@localhost zabbix-agent]# rm -f /usr/bin/zabbix_sender

[root@localhost zabbix-agent]# ln -s /usr/local/zabbix-agent/bin/zabbix_sender /usr/bin/

[root@localhost zabbix-agent]# ln -s /usr/local/zabbix-agent/bin/zabbix_get /usr/bin/

[root@localhost zabbix-agent]# ll /usr/bin//zabbix_*

lrwxrwxrwx 1 root root 38 2月  26 14:46 /usr/bin//zabbix_get -> /usr/local/zabbix-agent/bin/zabbix_get

lrwxrwxrwx 1 root root 41 2月  26 14:46 /usr/bin//zabbix_sender -> /usr/local/zabbix-agent/bin/zabbix_sender

 

 

sbin目录下。ls可以看到这里面有个zabbix_agentd的可执行文件,这个可执行文件是zabbix 的客户端的可执行文件,agent可以用来获取和监控数据环境。同样建立软连接到usr 下面的sbin目录下。

[root@localhost zabbix-agent]# ln -s /usr/local/zabbix-agent/sbin/zabbix_agentd /usr/sbin/

[root@localhost zabbix-agent]# ll /usr/sbin/zabbix_agentd

lrwxrwxrwx 1 root root 42 2月  26 14:48 /usr/sbin/zabbix_agentd -> /usr/local/zabbix-agent/sbin/zabbix_agentd

conf目录下有一个zabbix_agentd.conf,就是zabbix-agent的配置文件。我们将它copy到/usr/local/etc目录下面。

[root@localhost ~]# cp /usr/local/zabbix-agent/conf/zabbix_agentd.conf /usr/local/etc/

进入到zabbix_agentd.conf进行修改

[root@localhost ~]# vi /usr/local/etc/zabbix_agentd.conf

zabbix_agentd.conf修改如下:

 LogFile=/var/log/zabbix/zabbix_agentd.log

 Server=10.0.0.152#地址主动模式,填写Server的IP

 ServerActive=10.0.0.152 #修改为Server的IP地址

 Hostname=Zabbix server     #重要:客户端的hostname,不配置则使用主机名

保存退出。

创建/var/log/zabbix/并给予权限。

mkdir /var/log/zabbix/

chown zabbix:zabbix /var/log/zabbix/

chmod 644 /var/log/zabbix/

touch  /var/log/zabbix/zabbix_agentd.log

chmod 644 /var/log/zabbix/zabbix_agentd.log

拷贝启动脚本

[root@localhost ~]# cp /usr/local/zabbix-agent/sbin/zabbix_agentd /etc/init.d/

[root@localhost ~]# chmod +x /etc/init.d/zabbix_agentd

启动zabbix客户端

[root@localhost ~]# /etc/init.d/zabbix_agentd

zabbix_agentd [30375]: user zabbix does not exist

zabbix_agentd [30375]: cannot run as root!

这里提示错误,解决方法:

[root@localhost ~]# useradd zabbix -s /sbin/nologin

[root@localhost ~]# id zabbix

uid=1000(zabbix) gid=1000(zabbix) 组=1000(zabbix)

[root@localhost ~]# chown zabbix.zabbix /usr/local/zabbix-agent/*

再次启动:

[root@localhost ~]# /etc/init.d/zabbix_agentd

查看进程,确定是否启动成功

[root@localhost ~]# ps -ef|grep zabbix

 

posted on 2021-02-26 15:53  Santiago_hao  阅读(491)  评论(0编辑  收藏  举报

导航