1. #!/usr/bin/env bash
    2. __mian() {
    3. cat >docker-compose.yaml <<EOF
    4. version: "3.9"
    5. services:
    6. # zabbix 数据库
    7. zabbix-mysql:
    8. container_name: zabbix-mysql
    9. image: mysql:8.0.29
    10. command: --character-set-server=utf8mb4
    11. --collation-server=utf8mb4_unicode_ci
    12. --default-authentication-plugin=mysql_native_password
    13. networks:
    14. zabbix_net:
    15. aliases:
    16. - zabbix-mysql
    17. ports:
    18. - "3306:3306"
    19. environment:
    20. - TZ=Asia/Shanghai
    21. - MYSQL_USER=zabbix
    22. - MYSQL_PASSWORD=bad_password
    23. - MYSQL_ROOT_PASSWORD=bad_password
    24. - MYSQL_DB=zabbix
    25. volumes:
    26. - ./volumes/mysql/conf/:/etc/mysql.copy/
    27. # - ./volumes/mysql/conf/:/etc/mysql/
    28. - ./volumes/mysql/data/:/var/lib/mysql
    29. - ./volumes/mysql/files/:/var/lib/mysql-files
    30. - ./volumes/mysql/back/:/backups
    31. stop_grace_period: 1m
    32. # zabbix 服务端
    33. zabbix-server:
    34. container_name: zabbix-server
    35. image: zabbix/zabbix-server-mysql:ubuntu-6.0.3
    36. networks:
    37. zabbix_net:
    38. aliases:
    39. - zabbix-server
    40. ports:
    41. - "10051:10051"
    42. environment:
    43. - TZ=Asia/Shanghai
    44. - DB_SERVER_HOST=zabbix-mysql
    45. - MYSQL_USER=root
    46. - MYSQL_PASSWORD=bad_password
    47. depends_on:
    48. - zabbix-mysql
    49. volumes:
    50. - ./volumes/zabbix_server:/etc/zabbix.copy
    51. # - ./volumes/zabbix_server/zabbix_server.conf:/etc/zabbix/zabbix_server.conf
    52. # zabbix web
    53. zabbix-web:
    54. container_name: zabbix-web
    55. image: zabbix/zabbix-web-nginx-mysql:ubuntu-6.0.3
    56. networks:
    57. - zabbix_net
    58. ports:
    59. - "8080:8080"
    60. environment:
    61. - TZ=Asia/Shanghai
    62. - ZBX_SERVER_HOST=zabbix-server
    63. - DB_SERVER_HOST=zabbix-mysql
    64. - MYSQL_USER=root
    65. - MYSQL_PASSWORD=bad_password
    66. - PHP_TZ=Asia/Shanghai
    67. networks:
    68. zabbix_net:
    69. external: true
    70. EOF
    71. docker network create -d bridge --subnet=172.22.1.0/24 --gateway=172.22.1.254 zabbix_net
    72. docker-compose -p zabbix -f docker-compose.yaml up -d
    73. sleep 2s
    74. docker exec -it -u root zabbix-mysql bash -c 'cp -rf /etc/mysql/* /etc/mysql.copy/'
    75. docker exec -it -u root zabbix-server bash -c 'cp -rf /etc/zabbix/* /etc/zabbix.copy/'
    76. }
    77. __mian