xadocker@xadocker-virtual-machine:~$ cd workdir/datadir/terraform/ xadocker@xadocker-virtual-machine:~/workdir/datadir/terraform$ mkdir -p tf-nacos-cluster/ansible-deploy xadocker@xadocker-virtual-machine:~/workdir/datadir/terraform$ cd tf-nacos-cluster/
resource "alicloud_alidns_record" "record" { domain_name = "xadocker.cn" rr = "nacos-dev" type = "A" value = alicloud_instance.instance_nginx_node.0.public_ip remark = "create by tf for nacos nginx lb" status = "ENABLE" }
ansible主机清单模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
xadocker@xadocker-virtual-machine:~/Desktop/workdir/datadir/terraform/tf-nacos-cluster$ cat ansible_inventory.tpl [nacos] %{ for addr in nacos_ip_addrs ~} ${addr} ansible_ssh_port=${port} ansible_ssh_user=${user} %{ endfor ~}
[mysql] %{ for addr in mysql_ip_addrs ~} ${addr} ansible_ssh_port=${port} ansible_ssh_user=${user} %{ endfor ~}
[nginx] %{ for addr in nginx_ip_addrs ~} ${addr} ansible_ssh_port=${port} ansible_ssh_user=${user} %{ endfor ~}
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create
Terraform will perform the following actions:
# alicloud_alidns_record.record will be created + resource "alicloud_alidns_record" "record" { + domain_name = "xadocker.cn" + id = (known after apply) + line = "default" + remark = "create by tf for nacos nginx lb" + rr = "nacos-dev" + status = "ENABLE" + ttl = 600 + type = "A" + value = (known after apply) }
# alicloud_ecs_key_pair.publickey will be created + resource "alicloud_ecs_key_pair" "publickey" { + finger_print = (known after apply) + id = (known after apply) + key_name = (known after apply) + key_pair_name = "my_public_key" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvGLeFdDq4bxVbNmnSKWY+3gUMzs9rSmnHdHUxWZLUo4n980pFzQQ+UPytePnE+DSVES8Pl5KmdFuWsbbNEz7R6bO4lkKkOE2+HC/DwyhmpIM78PDSfFdf+WVIg7VLttIrhJJ6rcv/zdME3si/egXs0I9TfOJ/oO6nzkDjBBEwsvjES6lLs9MQdXa5wi/KAcL/p8OUIWEF8KhNUTQLLp0JxlcJhgx3U+ucn8yd9R2RqOBjdGJXk3rhgSqprAg73t0kt8BREOGoIqZq+e+RNz3/vaTV1yhra45Ni+vJDtTzYnZSQc0xSZU80ZYTSv80Y6AX+rH/4hp+yi4/ps4MOF8B root@xadocker-virtual-machine" }
# alicloud_ecs_key_pair_attachment.my_public_key will be created + resource "alicloud_ecs_key_pair_attachment" "my_public_key" { + id = (known after apply) + instance_ids = (known after apply) + key_name = (known after apply) + key_pair_name = "my_public_key" }
# alicloud_instance.instance_mysql_node[0] will be created + resource "alicloud_instance" "instance_mysql_node" { + availability_zone = "cn-guangzhou-a" + credit_specification = (known after apply) + deletion_protection = false + deployment_set_group_no = (known after apply) + dry_run = false + host_name = (known after apply) + id = (known after apply) + image_id = "centos_7_6_x64_20G_alibase_20211130.vhd" + instance_charge_type = "PostPaid" + instance_name = "tf-nacos-cluster-mysql-0" + instance_type = "ecs.s6-c1m1.small" + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_in = (known after apply) + internet_max_bandwidth_out = 10 + key_name = (known after apply) + password = (sensitive value) + private_ip = (known after apply) + public_ip = (known after apply) + role_name = (known after apply) + secondary_private_ip_address_count = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + spot_strategy = "NoSpot" + status = (known after apply) + subnet_id = (known after apply) + system_disk_category = "cloud_essd" + system_disk_performance_level = (known after apply) + system_disk_size = 40 + volume_tags = (known after apply) + vswitch_id = (known after apply) }
# alicloud_instance.instance_nacos_node[0] will be created + resource "alicloud_instance" "instance_nacos_node" { + availability_zone = "cn-guangzhou-a" + credit_specification = (known after apply) + deletion_protection = false + deployment_set_group_no = (known after apply) + dry_run = false + host_name = (known after apply) + id = (known after apply) + image_id = "centos_7_6_x64_20G_alibase_20211130.vhd" + instance_charge_type = "PostPaid" + instance_name = "tf-nacos-cluster-nacos-0" + instance_type = "ecs.s6-c1m1.small" + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_in = (known after apply) + internet_max_bandwidth_out = 10 + key_name = (known after apply) + password = (sensitive value) + private_ip = (known after apply) + public_ip = (known after apply) + role_name = (known after apply) + secondary_private_ip_address_count = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + spot_strategy = "NoSpot" + status = (known after apply) + subnet_id = (known after apply) + system_disk_category = "cloud_essd" + system_disk_performance_level = (known after apply) + system_disk_size = 40 + volume_tags = (known after apply) + vswitch_id = (known after apply) }
# alicloud_instance.instance_nacos_node[1] will be created + resource "alicloud_instance" "instance_nacos_node" { + availability_zone = "cn-guangzhou-a" + credit_specification = (known after apply) + deletion_protection = false + deployment_set_group_no = (known after apply) + dry_run = false + host_name = (known after apply) + id = (known after apply) + image_id = "centos_7_6_x64_20G_alibase_20211130.vhd" + instance_charge_type = "PostPaid" + instance_name = "tf-nacos-cluster-nacos-1" + instance_type = "ecs.s6-c1m1.small" + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_in = (known after apply) + internet_max_bandwidth_out = 10 + key_name = (known after apply) + password = (sensitive value) + private_ip = (known after apply) + public_ip = (known after apply) + role_name = (known after apply) + secondary_private_ip_address_count = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + spot_strategy = "NoSpot" + status = (known after apply) + subnet_id = (known after apply) + system_disk_category = "cloud_essd" + system_disk_performance_level = (known after apply) + system_disk_size = 40 + volume_tags = (known after apply) + vswitch_id = (known after apply) }
# alicloud_instance.instance_nacos_node[2] will be created + resource "alicloud_instance" "instance_nacos_node" { + availability_zone = "cn-guangzhou-a" + credit_specification = (known after apply) + deletion_protection = false + deployment_set_group_no = (known after apply) + dry_run = false + host_name = (known after apply) + id = (known after apply) + image_id = "centos_7_6_x64_20G_alibase_20211130.vhd" + instance_charge_type = "PostPaid" + instance_name = "tf-nacos-cluster-nacos-2" + instance_type = "ecs.s6-c1m1.small" + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_in = (known after apply) + internet_max_bandwidth_out = 10 + key_name = (known after apply) + password = (sensitive value) + private_ip = (known after apply) + public_ip = (known after apply) + role_name = (known after apply) + secondary_private_ip_address_count = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + spot_strategy = "NoSpot" + status = (known after apply) + subnet_id = (known after apply) + system_disk_category = "cloud_essd" + system_disk_performance_level = (known after apply) + system_disk_size = 40 + volume_tags = (known after apply) + vswitch_id = (known after apply) }
# alicloud_instance.instance_nginx_node[0] will be created + resource "alicloud_instance" "instance_nginx_node" { + availability_zone = "cn-guangzhou-a" + credit_specification = (known after apply) + deletion_protection = false + deployment_set_group_no = (known after apply) + dry_run = false + host_name = (known after apply) + id = (known after apply) + image_id = "centos_7_6_x64_20G_alibase_20211130.vhd" + instance_charge_type = "PostPaid" + instance_name = "tf-nacos-cluster-nginx-0" + instance_type = "ecs.s6-c1m1.small" + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_in = (known after apply) + internet_max_bandwidth_out = 10 + key_name = (known after apply) + password = (sensitive value) + private_ip = (known after apply) + public_ip = (known after apply) + role_name = (known after apply) + secondary_private_ip_address_count = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + spot_strategy = "NoSpot" + status = (known after apply) + subnet_id = (known after apply) + system_disk_category = "cloud_essd" + system_disk_performance_level = (known after apply) + system_disk_size = 40 + volume_tags = (known after apply) + vswitch_id = (known after apply) }
# alicloud_security_group.group will be created + resource "alicloud_security_group" "group" { + description = "nacos-cluster" + id = (known after apply) + inner_access = (known after apply) + inner_access_policy = (known after apply) + name = "tf-nacos-cluster" + security_group_type = "normal" + vpc_id = (known after apply) }
# alicloud_security_group_rule.allow_nacos_tcp will be created + resource "alicloud_security_group_rule" "allow_nacos_tcp" { + cidr_ip = "0.0.0.0/0" + id = (known after apply) + ip_protocol = "tcp" + nic_type = "intranet" + policy = "accept" + port_range = "8848/8848" + prefix_list_id = (known after apply) + priority = 1 + security_group_id = (known after apply) + type = "ingress" }
# alicloud_security_group_rule.allow_nginx_tcp will be created + resource "alicloud_security_group_rule" "allow_nginx_tcp" { + cidr_ip = "0.0.0.0/0" + id = (known after apply) + ip_protocol = "tcp" + nic_type = "intranet" + policy = "accept" + port_range = "80/80" + prefix_list_id = (known after apply) + priority = 1 + security_group_id = (known after apply) + type = "ingress" }
# alicloud_security_group_rule.allow_ssh_tcp will be created + resource "alicloud_security_group_rule" "allow_ssh_tcp" { + cidr_ip = "0.0.0.0/0" + id = (known after apply) + ip_protocol = "tcp" + nic_type = "intranet" + policy = "accept" + port_range = "22/22" + prefix_list_id = (known after apply) + priority = 1 + security_group_id = (known after apply) + type = "ingress" }
# alicloud_vpc.vpc will be created + resource "alicloud_vpc" "vpc" { + cidr_block = "172.16.0.0/16" + id = (known after apply) + ipv6_cidr_block = (known after apply) + name = (known after apply) + resource_group_id = (known after apply) + route_table_id = (known after apply) + router_id = (known after apply) + router_table_id = (known after apply) + status = (known after apply) + vpc_name = "tf-cluster-paas" }
# alicloud_vswitch.vswitch will be created + resource "alicloud_vswitch" "vswitch" { + availability_zone = (known after apply) + cidr_block = "172.16.0.0/24" + id = (known after apply) + name = (known after apply) + status = (known after apply) + vpc_id = (known after apply) + vswitch_name = "tf-cluster-paas" + zone_id = "cn-guangzhou-a" }
# local_file.ip_local_file will be created + resource "local_file" "ip_local_file" { + content = (known after apply) + directory_permission = "0777" + file_permission = "0777" + filename = "./ansible-deploy/ansible_inventory.ini" + id = (known after apply) }
Plan: 15 to add, 0 to change, 0 to destroy.
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Enter a value: yes
alicloud_ecs_key_pair.publickey: Creating... alicloud_vpc.vpc: Creating... alicloud_ecs_key_pair.publickey: Creation complete after 4s [id=my_public_key] alicloud_vpc.vpc: Creation complete after 9s [id=vpc-7xv4dqz2ofevofcr0u9t9] alicloud_security_group.group: Creating... alicloud_vswitch.vswitch: Creating... alicloud_security_group.group: Creation complete after 3s [id=sg-7xvb1hvto3njfp382kie] alicloud_security_group_rule.allow_nacos_tcp: Creating... alicloud_security_group_rule.allow_ssh_tcp: Creating... alicloud_security_group_rule.allow_nginx_tcp: Creating... alicloud_security_group_rule.allow_nginx_tcp: Creation complete after 1s [id=sg-7xvb1hvto3njfp382kie:ingress:tcp:80/80:intranet:0.0.0.0/0:accept:1] alicloud_security_group_rule.allow_ssh_tcp: Creation complete after 1s [id=sg-7xvb1hvto3njfp382kie:ingress:tcp:22/22:intranet:0.0.0.0/0:accept:1] alicloud_security_group_rule.allow_nacos_tcp: Creation complete after 1s [id=sg-7xvb1hvto3njfp382kie:ingress:tcp:8848/8848:intranet:0.0.0.0/0:accept:1] alicloud_vswitch.vswitch: Creation complete after 7s [id=vsw-7xvj9glllhbli978o9uax] alicloud_instance.instance_nginx_node[0]: Creating... alicloud_instance.instance_nacos_node[2]: Creating... alicloud_instance.instance_nacos_node[1]: Creating... alicloud_instance.instance_nacos_node[0]: Creating... alicloud_instance.instance_mysql_node[0]: Creating... alicloud_instance.instance_nginx_node[0]: Still creating... [10s elapsed] alicloud_instance.instance_nacos_node[2]: Still creating... [10s elapsed] alicloud_instance.instance_nacos_node[1]: Still creating... [10s elapsed] alicloud_instance.instance_nacos_node[0]: Still creating... [10s elapsed] alicloud_instance.instance_mysql_node[0]: Still creating... [10s elapsed] alicloud_instance.instance_nginx_node[0]: Creation complete after 12s [id=i-7xva1zlkypri0k4mnhk4] alicloud_alidns_record.record: Creating... alicloud_instance.instance_nacos_node[2]: Creation complete after 12s [id=i-7xv9q6jzyllqy6i7siy3] alicloud_instance.instance_nacos_node[0]: Creation complete after 13s [id=i-7xv6zscdflf8id3uo7uj] alicloud_instance.instance_mysql_node[0]: Creation complete after 13s [id=i-7xvbf7kvtsy3s0fv9lb6] alicloud_instance.instance_nacos_node[1]: Creation complete after 13s [id=i-7xvbf7kvtsy3s0fv9lb5] alicloud_ecs_key_pair_attachment.my_public_key: Creating... local_file.ip_local_file: Creating... local_file.ip_local_file: Creation complete after 0s [id=85bc2c6270a86991b774446140bf145ba89f11fc] alicloud_ecs_key_pair_attachment.my_public_key: Creation complete after 1s [id=my_public_key:["i-7xva1zlkypri0k4mnhk4","i-7xv6zscdflf8id3uo7uj","i-7xvbf7kvtsy3s0fv9lb6","i-7xv9q6jzyllqy6i7siy3","i-7xvbf7kvtsy3s0fv9lb5"]] alicloud_alidns_record.record: Creation complete after 2s [id=811113556473707520]
xadocker@xadocker-virtual-machine:~/Desktop/workdir/datadir/terraform/tf-nacos-cluster$ cat ansible-deploy/nginx-nacos.conf.j2 upstream nacos { {% for i in groups['nacos'] %} server {{ hostvars[i]['ansible_default_ipv4']['address'] }}:8848; {% endfor %}
# Copyright 1999-2018 Alibaba Group Holding Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
if [ -x '/usr/libexec/java_home' ] ; then export JAVA_HOME=`/usr/libexec/java_home`
elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" fi else JAVA_PATH=`dirname $(readlink -f $(which javac))` if [ "x$JAVA_PATH" != "x" ]; then export JAVA_HOME=`dirname $JAVA_PATH 2>/dev/null` fi fi if [ -z "$JAVA_HOME" ]; then error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better!" fi fi
export SERVER="nacos-server" export MODE="cluster" export FUNCTION_MODE="all" export MEMBER_LIST="" export EMBEDDED_STORAGE="" while getopts ":m:f:s:c:p:" opt do case $opt in m) MODE=$OPTARG;; f) FUNCTION_MODE=$OPTARG;; s) SERVER=$OPTARG;; c) MEMBER_LIST=$OPTARG;; p) EMBEDDED_STORAGE=$OPTARG;; ?) echo "Unknown parameter" exit 1;; esac done
#=========================================================================================== # JVM Configuration #=========================================================================================== if [[ "${MODE}" == "standalone" ]]; then JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m" JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true" else if [[ "${EMBEDDED_STORAGE}" == "embedded" ]]; then JAVA_OPT="${JAVA_OPT} -DembeddedStorage=true" fi JAVA_OPT="${JAVA_OPT} -server -Xms{{ nacos_xms_size }} -Xmx{{ nacos_xmx_size }} -Xmn{{ nacos_xmn_size }} -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof" JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
fi
if [[ "${FUNCTION_MODE}" == "config" ]]; then JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config" elif [[ "${FUNCTION_MODE}" == "naming" ]]; then JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming" fi
xadocker@xadocker-virtual-machine:~/Desktop/workdir/datadir/terraform/tf-nacos-cluster$ cat ansible-deploy/cluster.conf.j2 # # Copyright 1999-2018 Alibaba Group Holding Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #
#it is ip #example {% for i in groups['nacos'] %} {{ hostvars[i]['ansible_default_ipv4']['address'] }}:8848 {% endfor %}
xadocker@xadocker-virtual-machine:~/workdir/datadir/terraform/tf-nacos-cluster$ cd ansible-deploy/ xadocker@xadocker-virtual-machine:~/workdir/datadir/terraform/tf-nacos-cluster/ansible-deploy$ sudo ansible-playbook nacos-playbook.yaml
PLAY [install nacos] *************************************************************************************************************************************************************************