Skip to content

Commit

Permalink
Added CRDBNODE# so that it is possible to ssh to the CRDB Cluster num…
Browse files Browse the repository at this point in the history
…ber for the node (see the README.md for more info).
  • Loading branch information
nollenr committed Sep 12, 2022
1 parent 0d052a6 commit 4dfc9c2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,26 @@ Nodes 4, 5, and 6 have the IP Addresses for nodes 1-6.
</br>
Nodes 7, 8, and 9 have the IP Addresses for nodes 1-9.

This node number corresponds to the LINUX node number you would find in the EC2 console. This is not the node number of the Cockroach Cluster Node (see below).

## SSH To a CRDB Node Number
A `cockroach node status` lists all of the nodes participating in the cluster and produces output that looks like the following:

| id | address | sql_address | build | started_at | updated_at | locality | is_available | is_live|
|-----|---------------------|---------------------|---------|----------------------------|----------------------------|----------------------------------|--------------|----------|
| 1 | 192.168.2.132:26257 | 192.168.2.132:26257 | v22.1.6 | 2022-09-09 16:46:43.361479 | 2022-09-12 16:39:26.894466 | region=us-west-2,zone=us-west-2c | true | true|
| 2 | 192.168.2.4:26257 | 192.168.2.4:26257 | v22.1.6 | 2022-09-09 16:46:45.226062 | 2022-09-12 16:39:24.260465 | region=us-west-2,zone=us-west-2a | true | true|
| 3 | 192.168.2.68:26257 | 192.168.2.68:26257 | v22.1.6 | 2022-09-09 16:46:45.360192 | 2022-09-12 16:39:24.372785 | region=us-west-2,zone=us-west-2b | true | true|

You can ssh to any of the nodes by using `CRDBNODE` and the node number. For example, to ssh to node id '3', you can do the following:

```
ssh $CRDBNODE3
```

Note that the LINUX node number and the CRDB node number are different. The LINUX node number is the node in the order it was created. The CRDB Node number is the number assigned by CRDB when the node joins the cluster.


# Additional Bash Functions
## STARTCRDB
If you shutdown the nodes running the CockroachDB cluster, you can easily restart the database by issuing the ```STARTCRDB``` command on all nodes in the cluster.
Expand Down
91 changes: 91 additions & 0 deletions crdb_cloudformation_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Parameters:
Default: "22.1.6"
Description: Cockroach Version to install
AllowedValues:
- "22.2.0-alpha.2"
- "22.1.6"
- "22.1.5"
- "22.1.4"
Expand Down Expand Up @@ -797,6 +798,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -936,6 +947,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1092,6 +1113,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1235,6 +1266,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1381,6 +1422,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1527,6 +1578,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1676,6 +1737,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1827,6 +1898,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down Expand Up @@ -1979,6 +2060,16 @@ Resources:
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
Expand Down

0 comments on commit 4dfc9c2

Please sign in to comment.