[root@localhost ~]# tar xzf zabbix_image.tar.gz [root@localhost ~]# cd zabbix/[root@localhost zabbix]# lszabbix-agent.tar zabbix-server.tar zabbix-web.tar
[root@localhost zabbix]# docker load -i zabbix-agent.tar [root@localhost zabbix]# docker load -i zabbix-server.tar [root@localhost zabbix]# docker load -i zabbix-web.tar
[root@localhost ~]# docker images |grep zabbix zabbix/zabbix-web-nginx-mysql latest 116855eaede2 2 weeks ago 164MBzabbix/zabbix-server-mysql latest 8ca9fbc31571 2 weeks ago 67.7MBzabbix/zabbix-agent latest 9084e5d9908f 2 weeks ago 16.4MB
[root@localhost ~]# tar xzf mysql5.7_utf8.tar.gz [root@localhost ~]# docker load -i mysql5.7_utf8.tar
[root@localhost zabbix]# vim docker-compose.yml [root@localhost zabbix]# cat docker-compose.yml version: "3"services: mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: 123 MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: 123 zabbix-server: image: zabbix/zabbix-server-mysql ports: - "10051:10051" environment: DB_SERVER_HOST: mysql MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: 123 depends_on: - mysql zabbix-web: image: zabbix/zabbix-web-nginx-mysql ports: - "80:8080" environment: DB_SERVER_HOST: mysql MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: 123 PHP_TZ: Asia/Shanghai ZBX_SERVER_HOST: zabbix-server depends_on: - zabbix-server - mysql
[root@localhost zabbix]# docker-compose up -dCreating network "zabbix_default" with the default driverCreating zabbix_mysql_1 ... doneCreating zabbix_zabbix-server_1 ... doneCreating zabbix_zabbix-web_1 ... done
[root@localhost zabbix]# docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------zabbix_mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp zabbix_zabbix-server_1 /sbin/tini -- /usr/bin/doc ... Up 0.0.0.0:10051->10051/tcp zabbix_zabbix-web_1 docker-entrypoint.sh Up 0.0.0.0:80->8080/tcp, 8443/tcp[root@localhost zabbix]#
用戶名:Admin
密碼: zabbix
[root@localhost ~]# yum search ansible[root@localhost ~]# yum -y install centos-release-ansible-29[root@localhost ~]# yum -y insatll ansible
[root@localhost ~]# ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:4VR DrKshFAcKdb3Ax/ d46b4wQZsMGhCp6EKXbqGjA root@localhost.localdomainThe key's randomart image is: ---[RSA 2048]---- | ooo . .. || oo. o.o* || o o ..==. . ||ooo o = * ||E.o o . Soo . ||o. . . ... . ||.. . .. ||.. .o.. ||. . o | ----[SHA256]-----
[root@localhost ~]# ssh-copy-id root@192.168.153.184[root@localhost ~]# ssh-copy-id root@192.168.153.185
[root@localhost ~]# vim /etc/ansible/hosts [webservers]192.168.153.184192.168.153.185
[root@localhost ~]# ansible all -m ping192.168.153.185 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}192.168.153.184 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong"}[root@localhost ~]#
[root@localhost agent]# vim agent.yml ---- hosts: webservers tasks: - name: "推送zabbix源" copy: src=zabbix_Aliyun.repo dest=/etc/yum.repos.d/ - name: "安裝zabbix-agent" yum: name=zabbix-agent state=latest - name: "修改agent配置文件" script: agent.sh - name: "啟動(dòng)agent" systemd: name=zabbix-agent state=started enabled=yes - name: "關(guān)閉防火墻" systemd: name=firewalld state=stopped - name: "關(guān)閉selinux" shell: "setenforce 0"[root@localhost agent]#
[root@localhost agent]# ansible-playbook agent.yml PLAY [webservers] ***************************************************************************************************************TASK [Gathering Facts] **********************************************************************************************************ok: [192.168.153.185]ok: [192.168.153.184]TASK [推送zabbix源] ****************************************************************************************************************changed: [192.168.153.185]changed: [192.168.153.184]TASK [安裝zabbix-agent] ***********************************************************************************************************changed: [192.168.153.184]changed: [192.168.153.185]TASK [修改agent配置文件] **************************************************************************************************************changed: [192.168.153.184]changed: [192.168.153.185]TASK [啟動(dòng)agent] ******************************************************************************************************************changed: [192.168.153.185]changed: [192.168.153.184]TASK [關(guān)閉防火墻] ********************************************************************************************************************changed: [192.168.153.184]changed: [192.168.153.185]TASK [關(guān)閉selinux] ****************************************************************************************************************changed: [192.168.153.185]changed: [192.168.153.184]PLAY RECAP **********************************************************************************************************************192.168.153.184 : ok=7 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.153.185 : ok=7 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@localhost agent]# cd ../zabbix/[root@localhost zabbix]# docker-compose exec zabbix-server bashbash-5.0$ zabbix_get -s 192.168.153.184 -k agent.ping1bash-5.0$ zabbix_get -s 192.168.153.185 -k agent.ping1bash-5.0$
返回值為1則配置成功
來(lái)源:https://www.icode9.com/content-4-792801.html聯(lián)系客服