Skip to content

Commit

Permalink
update daily
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqinfeng committed Nov 18, 2023
1 parent 35f749c commit 3773c86
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 77 deletions.
41 changes: 41 additions & 0 deletions deploy/docker/ansible_playbook/install_nacos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: Get docker Image Registry Hostname
hosts: registry
tasks:
- name: get registry hostname
command: cat /etc/hostname
register: registry_hostname

- name: Install Nacos
hosts: nacos
vars_files:
- vars.yml
vars:
- registry_addr: "{{registry_hostname.stdout}}:{{registry_srv_port}}"
become: true
tasks:
- name: Copy Docker Compose files
template:
src: ../{{ item }}
dest: /tmp/{{ item }}
force: true
loop:
- "{{nacos1_compose_file}}"
- "{{nacos2_compose_file}}"
- "{{nacos3_compose_file}}"
- "{{nacos_mysql_compose_file}}"

- name: Start Nacos1
shell:
cmd: "docker-compose -f /tmp/{{nacos1_compose_file}} up -d"
when: nacos1_host == ansible_hostname

# - name: Delete docker-compose.yml
# file:
# dest: /tmp/{{ item }}
# state: absent
# loop:
# - "{{nacos1_compose_file}}"
# - "{{nacos2_compose_file}}"
# - "{{nacos3_compose_file}}"
# - "{{nacos_mysql_compose_file}}"
35 changes: 32 additions & 3 deletions deploy/docker/ansible_playbook/prepare_infra_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,49 @@
vars:
- registry_addr: "{{registry_hostname.stdout}}:{{registry_srv_port}}"
tasks:
- name: Pull Images
- name: Pull Images From Web
command: "docker pull {{item}}"
loop:
"{{infra_images_list}}"
- name: Tag Images
command: "docker tag {{item}} {{registry_addr}}/{{item}}"
loop:
"{{infra_images_list}}"

- name: Copy Dockerfiles
copy:
src: "../{{ item }}"
dest: "/tmp/{{ item }}"
mode: 777
loop:
"{{local_infra_images_dockerfile_list}}"

- name: Make Lcal Images
# command: "docker build -f /tmp/{{item.0}} -t {{registry_addr}}/{{item.1}} ."
with_together:
- "{{local_infra_images_dockerfile_list}}"
- "{{local_infra_images_list}}"
docker_image:
name: "{{registry_addr}}/{{item.1}}"
build:
path: /tmp
dockerfile: "{{item.0}}"
source: build
state: present

- name: Push Images
command: "docker push {{registry_addr}}/{{item}}"
loop:
"{{infra_images_list}}"
"{{infra_images_list + local_infra_images_list}}"

- name: Remove Downloaded Images
command: "docker rmi {{registry_addr}}/{{item}} {{item}}"
loop:
"{{infra_images_list}}"
when: delete_download_images == True
when: delete_download_images == True
- name: Remove Local Images
command: "docker rmi {{registry_addr}}/{{item}}"
loop:
"{{local_infra_images_list}}"
when: delete_download_images == True

27 changes: 26 additions & 1 deletion deploy/docker/ansible_playbook/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,51 @@
docker_registry_compose_file: docker_compose_docker_registry.yml # docker私有仓库的compose文件
registry_srv_port: 8080 # docker私有仓库的服务端口

#########################################################################
# 基础设施镜像相关配置
#########################################################################
prometheus_image: prom/prometheus:latest
grafana_image: grafana/grafana:latest
nacos_mysql_image: nacos/mysql:8.0.31
nacos_image: nacos/nacos-server:latest
nacos_mysql_image: nacos/mysql:8.0.31

infra_images_list: # 在线下载的基础设施的镜像列表
- "{{prometheus_image}}"
- "{{grafana_image}}"
- "{{nacos_image}}"
local_infra_images_list: # 本地打包的基础设施的镜像列表
- "{{nacos_mysql_image}}"
local_infra_images_dockerfile_list: # 注意顺序保存和local_infra_images_list一致
- "dockerfile.nacos_mysql"

delete_download_images: true # 是否删除本地已上传到私有仓库的基础设施镜像

#########################################################################
# nacos相关配置
#########################################################################
nacos1_compose_file: docker_compose_nacos1.yml # nacos1的compose文件
nacos2_compose_file: docker_compose_nacos2.yml # nacos2的compose文件
nacos3_compose_file: docker_compose_nacos3.yml # nacos3的compose文件
nacos_mysql_compose_file: docker_compose_nacos_mysql.yml #nacos的mysql的compose文件
config_nacos_mysql: config_nacos_mysql.env # nacos使用的数据库的配置
config_nacos: config_nacos.env # nacos的配置
nacos_mysql_port: 13306 # nacos使用的mysql的服务端口
nacos_mysql_host: master # nacos使用的mysql的服务地址,该主机的dns需要配置在部署nacos的机子上, 并在ansible主机清单维护
nacos1_host: master # nacos1的服务地址,该主机的dns需要配置在部署nacos/promethus的机子上, 并在ansible主机清单维护
nacos1_conn_port1: 7848
nacos1_conn_port2: 9848
nacos1_conn_port3: 9849
nacos1_srv_port: 8848
nacos2_host: master # nacos2的服务地址,该主机的dns需要配置在部署nacos/promethus的机子上, 并在ansible主机清单维护
nacos2_conn_port1: 7849
nacos2_conn_port2: 9849
nacos2_conn_port3: 9850
nacos2_srv_port: 8849
nacos3_host: master # nacos3的服务地址,该主机的dns需要配置在部署nacos/promethus的机子上, 并在ansible主机清单维护
nacos3_conn_port1: 7850
nacos3_conn_port2: 9850
nacos3_conn_port3: 9851
nacos3_srv_port: 8850

#########################################################################
# prometheus相关配置
Expand Down
4 changes: 2 additions & 2 deletions deploy/docker/config_nacos.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PREFER_HOST_MODE=hostname
NACOS_SERVERS=nacos1:8848 nacos2:8849 nacos3:8850
NACOS_SERVERS={{nacos1_host}}:{{nacos1_srv_port}} {{nacos2_host}}:{{nacos2_srv_port}} {{nacos3_host}}:{{nacos3_srv_port}}
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=mysql
MYSQL_SERVICE_HOST={{nacos_mysql_host}}
MYSQL_SERVICE_DB_NAME=nacos_kvdata
MYSQL_SERVICE_PORT={{nacos_mysql_port}}
MYSQL_SERVICE_USER=nacos
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker/config_promethus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ scrape_configs:
- job_name: 'nacos'
metrics_path: '/nacos/actuator/prometheus'
static_configs:
- targets: ["nacos1:8848","nacos2:8849","nacos3:8850"]
- targets: ["{{nacos1_host}}:{{nacos1_srv_port}}","{{nacos2_host}}:{{nacos2_srv_port}}","{{nacos3_host}}:{{nacos3_srv_port}}"]

68 changes: 0 additions & 68 deletions deploy/docker/docker_compose_nacos.yml

This file was deleted.

19 changes: 19 additions & 0 deletions deploy/docker/docker_compose_nacos1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.8"
services:
nacos1:
hostname: nacos1
container_name: nacos1
image: "{{registry_addr}}/{{nacos_image}}"
volumes:
- ./cluster-logs/nacos1:/home/nacos/logs
ports:
- "{{nacos1_conn_port1}}:7848"
- "{{nacos1_srv_port}}:8848"
- "{{nacos1_conn_port2}}:9848"
- "{{nacos1_conn_port3}}:9849"
env_file:
- ./{{config_nacos}}
restart: always
depends_on:
mysql:
condition: service_healthy
20 changes: 20 additions & 0 deletions deploy/docker/docker_compose_nacos2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"
services:
nacos2:
hostname: nacos2
image: "{{registry_addr}}/{{nacos_image}}"
container_name: nacos2
volumes:
- ./cluster-logs/nacos2:/home/nacos/logs
ports:
- "{{nacos2_conn_port1}}:7848"
- "{{nacos2_srv_port}}:8848"
- "{{nacos2_conn_port2}}:9848"
- "{{nacos2_conn_port3}}:9849"
env_file:
- ./{{config_nacos}}
restart: always
depends_on:
mysql:
condition: service_healthy

20 changes: 20 additions & 0 deletions deploy/docker/docker_compose_nacos3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"
services:
nacos2:
hostname: nacos2
image: "{{registry_addr}}/{{nacos_image}}"
container_name: nacos2
volumes:
- ./cluster-logs/nacos2:/home/nacos/logs
ports:
- "{{nacos3_conn_port1}}:7848"
- "{{nacos3_srv_port}}:8848"
- "{{nacos3_conn_port2}}:9848"
- "{{nacos3_conn_port3}}:9849"
env_file:
- ./{{config_nacos}}
restart: always
depends_on:
mysql:
condition: service_healthy

16 changes: 16 additions & 0 deletions deploy/docker/docker_compose_nacos_mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"
services:
mysql:
container_name: mysql
image: "{{registry_addr}}/{{nacos_mysql_image}}"
env_file:
- ./{{config_nacos_mysql}}
volumes:
- ./mysql:/var/lib/mysql
ports:
- "{{nacos_mysql_port}}:3306"
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
interval: 5s
timeout: 10s
retries: 10
4 changes: 2 additions & 2 deletions deploy/docker/dockerfile.nacos_mysql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM mysql:8.0.31
ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql
FROM dockerproxy.com/library/mysql:8.0.31
ADD https://raw.staticdn.net/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql
EXPOSE 3306
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]

0 comments on commit 3773c86

Please sign in to comment.