我正在尝试使用terraform创建一个cassandra集群,使用google\u compute\u instance\u group\u manager。我可以使用这个组管理器同时创建多个示例。但问题来自于启动脚本。当我试图将一个cassandra数据节点添加到cassandra主集群中时。此添加操作不能同时发生。但是当我使用组管理器创建多个示例时。启动脚本将始终并行运行。这将导致只有一个节点可以加入cassandra集群。
我尝试在启动脚本中添加一些随机睡眠以避免冲突,但这将导致基础结构不可预测。我还尝试在开始时创建一个示例,然后更新或将更多示例添加到集群中。但是gcp将为集群中的所有restart/replace示例分配一个新的ip。这会让Cassandra的主节点很困惑。
因此,我不确定是否有人知道如何让googlecomputegroup manager以某种顺序创建节点,或者是否有更好的方法让gpc在创建示例后在不同的时间戳运行脚本以避免冲突。地形文件
resource "google_compute_health_check" "autohealing" {
name = "autohealing-health-check"
check_interval_sec = 5
timeout_sec = 5
healthy_threshold = 2
unhealthy_threshold = 10 # 50 seconds
http_health_check {
request_path = "/healthz"
port = "8080"
}
}
resource "google_compute_instance_template" "instance_template" {
name_prefix = "cassandra-template-"
machine_type = var.machine_type
region = var.region
disk {
// Instance Templates reference disks by name, not self link
source_image = "centos-7"
auto_delete = false
boot = false
}
lifecycle {
create_before_destroy = true
}
network_interface {
network = "cassandra-network"
}
metadata = {
cassandra_seed = "${var.CASSANDRA_SEED}"
}
metadata_startup_script = file("startup.sh")
}
resource "google_compute_instance_group_manager" "instance_group_manager" {
name = "cassandra-slave-manager"
base_instance_name = "cassandra-slave-manager"
zone = var.zone
version {
name = "instance_group_manager"
instance_template = google_compute_instance_template.instance_template.self_link
}
target_size = "3" // When this size > 1 only one instance can join to cassandra cluster
update_policy {
type = "PROACTIVE"
minimal_action = "RESTART"
max_surge_fixed = "1"
max_unavailable_fixed = "1"
}
}
启动脚本
# !/bin/bash
sudo yum install docker -y
sudo systemctl start docker
export SEED=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/cassandra_seed" -H "Metadata-Flavor: Google")
export LISTEN_ADDRESS=$(hostname -i)
sleep $[ ( $RANDOM % 10 ) + 1 ]s
sudo docker run --name cas1 --network host \
-e CASSANDRA_SEEDS=$SEED \
-e CASSANDRA_LISTEN_ADDRESS=$LISTEN_ADDRESS \
-e CASSANDRA_CLUSTER_NAME=MyCluster \
-e CASSANDRA_START_RPC=true \
-e CASSANDRA_RPC_ADDRESS=$LISTEN_ADDRESS \
-e CASSANDRA_DC=datacenter1 \
-e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch \
-d cassandra
本地运行脚本
echo "Start CASSANDRA Cluster"
echo "Start Master Node"
cd terraform_cassandra
terraform init
terraform apply -auto-approve
echo "Start Slave Nodes"
export CASSANDRA_SEED=$(gcloud --format="value(networkInterfaces[0].networkIP)" compute instances list --filter=cassandra-vm-master)
cd ../terraform_cassandra_slave_gm/
terraform init
terraform apply -auto-approve -var "CASSANDRA_SEED="$CASSANDRA_SEED
错误
-- StackTrace --
java.lang.AssertionError
at org.apache.cassandra.locator.TokenMetadata.getTokens(TokenMetadata.java:474)
at org.apache.cassandra.service.StorageService.getTokens(StorageService.java:2263)
at org.apache.cassandra.service.StorageService.getTokens(StorageService.java:2252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:112)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:46)
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237)
at com.sun.jmx.mbeanserver.PerInterface.getAttribute(PerInterface.java:83)
at com.sun.jmx.mbeanserver.MBeanSupport.getAttribute(MBeanSupport.java:206)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:647)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1445)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:639)
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
暂无答案!
目前还没有任何答案,快来回答吧!