Skip to content

Instantly share code, notes, and snippets.

@metal3d
Last active December 13, 2021 12:51
Show Gist options
  • Select an option

  • Save metal3d/be1dc1849011379391c62669d61e35ee to your computer and use it in GitHub Desktop.

Select an option

Save metal3d/be1dc1849011379391c62669d61e35ee to your computer and use it in GitHub Desktop.

Revisions

  1. metal3d revised this gist Dec 13, 2021. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions create-couchbas-pods.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Configuration
    count=2
    count=4
    clustername=mycluster
    admin=admin
    password=password
    @@ -30,7 +30,9 @@ until [ $RESPOND == 1 ]; do
    done

    # now, init the cluster
    podman exec -it couch1 couchbase-cli cluster-init --cluster-name=${clustername} --cluster-username=${admin} --cluster-password=${password}
    podman exec -it couch1 couchbase-cli cluster-init \
    --cluster-name=${clustername} --cluster-username=${admin} --cluster-password=${password} \
    --services fts,data,index,query

    # add others server to the cluster
    for i in $(seq 2 $count); do
  2. metal3d revised this gist Dec 13, 2021. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions create-couchbas-pods.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    # configuration
    # Configuration
    count=2
    clustername=mycluster
    admin=admin
    password=password

    networkname=couchbase
    volumename=couchbase

    # inside the pods, do not change it
    volumepath=/opt/couchbase/var

    # create a network
    podman network create ${networkname}
    @@ -13,11 +18,12 @@ for i in $(seq $count); do
    port1=$((8091 + (i-1)*4 ))
    port2=$((8094 + (i-1)*4 ))
    podman pod create --name server$i --network ${networkname} -p $port1-$port2:8091-8094
    podman run -d --rm --name couch$i --pod server$i docker.io/couchbase:community
    podman volume create ${volumename}${i}
    podman run -d --rm --name couch$i --pod server$i -v ${volumename}${i}:${volumepath} docker.io/couchbase:community
    done

    # wait for the server 1 to respond
    echo "Waiting for the first server to respond..."
    echo "Waiting for the first server to be up and running..."
    RESPOND=0
    until [ $RESPOND == 1 ]; do
    podman exec -t couch1 bash -c 'curl -sf server1:8091 -o /dev/null' && RESPOND=1
    @@ -28,6 +34,11 @@ podman exec -it couch1 couchbase-cli cluster-init --cluster-name=${clustername}

    # add others server to the cluster
    for i in $(seq 2 $count); do
    RESPOND=0
    echo "Waiting server $i to be up and running..."
    until [ $RESPOND == 1 ]; do
    podman exec -t couch1 bash -c 'curl -sf server'${i}':8091 -o /dev/null' && RESPOND=1
    done
    podman exec -it couch$i bash -c 'couchbase-cli server-add -c server1 -u '${admin}' -p '${password}' \
    --server-add $(hostname -I) --server-add-username '${admin}' --server-add-password '${password}
    done
    @@ -43,6 +54,7 @@ echo To remove all:
    cat <<EOF
    for i in {1..$count}; do
    podman pod rm -f server\${i}
    podman volume rm ${volumename}\${i}
    done
    podman network rm ${networkname}
    EOF
    EOF
  3. metal3d revised this gist Dec 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-couchbas-pods.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # configuration
    count=4
    count=2
    clustername=mycluster
    admin=admin
    password=password
  4. metal3d created this gist Dec 13, 2021.
    48 changes: 48 additions & 0 deletions create-couchbas-pods.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # configuration
    count=4
    clustername=mycluster
    admin=admin
    password=password
    networkname=couchbase

    # create a network
    podman network create ${networkname}

    # and now create $count servers, decay ports
    for i in $(seq $count); do
    port1=$((8091 + (i-1)*4 ))
    port2=$((8094 + (i-1)*4 ))
    podman pod create --name server$i --network ${networkname} -p $port1-$port2:8091-8094
    podman run -d --rm --name couch$i --pod server$i docker.io/couchbase:community
    done

    # wait for the server 1 to respond
    echo "Waiting for the first server to respond..."
    RESPOND=0
    until [ $RESPOND == 1 ]; do
    podman exec -t couch1 bash -c 'curl -sf server1:8091 -o /dev/null' && RESPOND=1
    done

    # now, init the cluster
    podman exec -it couch1 couchbase-cli cluster-init --cluster-name=${clustername} --cluster-username=${admin} --cluster-password=${password}

    # add others server to the cluster
    for i in $(seq 2 $count); do
    podman exec -it couch$i bash -c 'couchbase-cli server-add -c server1 -u '${admin}' -p '${password}' \
    --server-add $(hostname -I) --server-add-username '${admin}' --server-add-password '${password}
    done

    # and rebalance
    podman exec -it couch1 couchbase-cli rebalance -u ${admin} -p ${password} -c server1


    echo
    echo "CouchBase cluster accessible at http://localhost:8091"
    echo
    echo To remove all:
    cat <<EOF
    for i in {1..$count}; do
    podman pod rm -f server\${i}
    done
    podman network rm ${networkname}
    EOF