Skip to content

Commit b5bf49f

Browse files
author
sshcherbakov
committed
Initial commit
1 parent 2505d88 commit b5bf49f

10 files changed

+409
-0
lines changed

Diff for: README.md

+163
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,165 @@
11
# geode-control
22
A set of bash scripts to simplify control of a Apache Geode cluster
3+
4+
## The Purpose
5+
6+
This set of scripts provides a consistent approach for starting Apache Geode cluster nodes.
7+
8+
With this set of scripts you can:
9+
10+
* Quickly start the cluster of Apache Geode nodes on a freshly provisioned machines
11+
* Remotely control Geode cluster from a single node
12+
- start / stop cluster
13+
- centrally apply configuration changes to the cluster nodes using trivial template mechanism
14+
- gather logs and statistics files
15+
- clean up working directories
16+
* Have coherent folder and configuration files layout
17+
* Have startup script and configuration files templates
18+
19+
20+
## Prerequisites
21+
22+
The bash scripts are primarily designed and tested on RHEL/CentOS 6.5.
23+
24+
The desired Java runtime must be pre-installed and available at the Bash prompt.
25+
26+
A copy of Apache Geode / Gemfire installation at arbitrary file system location with Geode / Gemfire `bin`
27+
folder added to the `PATH` environment variable.
28+
29+
Password-less SSH authentication between the "master" and other cluster machines.
30+
31+
## Usage
32+
33+
Create a folder at the arbitrary file system location better ouside of any Geode/Gemfire installation.
34+
It is convenient to have a stable symlink to the effective Geode/Gemfire installation folder, e.g.
35+
````
36+
ls -l /opt
37+
lrwxrwxrwx. 1 root root 91 Oct 28 17:23 gemfire -> Pivotal_GemFire_8201_b17966_Linux/
38+
drwxr-xr-x. 11 root root 4096 Oct 23 17:26 Pivotal_GemFire_8201_b17966_Linux
39+
````
40+
41+
Copy or checkout the current repository to an arbitrary folder in your file system where the cluster instances
42+
will be based e.g.
43+
````
44+
cd ~
45+
git clone https://github.com/sshcherbakov/geode-control.git
46+
cd ~/geode-control
47+
````
48+
49+
Create empty folder at the same location (`~/geode-control`) on all machines that will host the cluster.
50+
The current user must have same read/write permissions to that folder on each of the machines.
51+
52+
Set the password-less authentication between the current machine (the master one) and other machines where you
53+
plan to run Geode / Gemfire nodes. [Here](http://hortonworks.com/kb/generating-ssh-keys-for-passwordless-login/) is an example how to do that.
54+
55+
Modify the `config/hostlist` describing the hosts where the cluster members are going to run. Each line of the file represents one Geode/Gemfire process instance and is specified in the following format:
56+
````
57+
<target_hostname> <locator|server> <instance_name>
58+
````
59+
60+
The `target_hostname` here is the name that will be used by the script to login via SSH remotely.
61+
The `locator` or `server` parameter specifies which kind of Geode/Gemfire node to start respectively.
62+
The `instance_name` is the name of the Geode/Gemfire process instance that will also be used as a folder name for the
63+
instance related files.
64+
65+
66+
Place custom Jar files that need to be available at the Geode/Gemfire classpath at runtime to the optional `lib/` subfolder.
67+
68+
We are basically set now. The following commands will bring the Geode cluster up and running.
69+
70+
### Configuration deployment
71+
72+
````
73+
bin/cluster deploy
74+
````
75+
copies the contents of `bin/`, `config/` and `lib/` subfolders to the cluster member machines as specified in the `config/hostlist` file.
76+
The placeholders in the property files get substituted with the local environment variables on each host accordingly.
77+
78+
### Cluster start
79+
80+
````
81+
bin/cluster start
82+
````
83+
84+
Starts all cluster nodes
85+
86+
87+
### Cluster stop
88+
89+
````
90+
bin/cluster stop
91+
````
92+
93+
Starts all running cluster nodes
94+
95+
### Clean up log and work folder
96+
97+
````
98+
bin/cluster clean
99+
````
100+
101+
Removes all log and Geode/Gemfire work files located in the `var/` subfolder on each machine.
102+
103+
104+
### Gather logs and stats files
105+
106+
````
107+
bin/cluster logs
108+
````
109+
110+
Gathers all Geode/Gemfire logs and statistics files from all cluster machines into a singe compressed time stamped tar ball file
111+
placed in the current directory. The file contents is flattened with the log and stats file names indicating the originating Geode/Gemifre instance.
112+
113+
114+
115+
## Folder structure
116+
````
117+
root@vf0 geode-control]# tree
118+
.
119+
├── bin <-- geode-control scripts
120+
│   ├── cluster <-- main script for the cluster control
121+
│   ├── start-locator <-- includes process environment variables
122+
│   ├── start-server <-- includes process environment variables
123+
│   ├── stop-locator
124+
│   └── stop-server
125+
├── config <-- configuration file templates for all cluster participants
126+
│   ├── cache.xml
127+
│   ├── gemfire-locator.properties
128+
│   ├── gemfire-server.properties
129+
│   └── hostlist
130+
├── etc <-- runtime configuration
131+
│   ├── locator1 <-- runtime Gode/Gemfire instance configuration with subsituted placeholders
132+
│   │   └── gemfire.properties
133+
│   └── server1 <-- runtime Gode/Gemfire instance configuration with subsituted placeholders
134+
│   ├── cache.xml
135+
│   └── gemfire.properties
136+
├── lib <-- custom Jars to add to each cluster instance classpath at runtime
137+
│   ├── my.jar
138+
└── var
139+
├── log <-- Geode/Gemfire instance logs
140+
│   ├── locator1
141+
│   │   ├── locator1-vf0.log
142+
│   │   └── meta-locator1-vf0-01.log
143+
│   └── server1
144+
│   ├── meta-server1-vf0-01.log
145+
│   ├── server1-vf0-01-00.marker
146+
│   ├── server1-vf0.gfs
147+
│   └── server1-vf0.log
148+
└── work <-- Geode/Gemfire work folders
149+
   ├── locator1
150+
   │   ├── ConfigDiskDir_locator1
151+
   │   │   ├── BACKUPcluster_config_1.crf
152+
   │   │   ├── BACKUPcluster_config_1.drf
153+
   │   │   ├── BACKUPcluster_config.if
154+
   │   │   └── DRLK_IFcluster_config.lk
155+
   │   ├── GemFire_root
156+
...
157+
   │   ├── locator10334state.dat
158+
   │   ├── locator10334views.log
159+
   │   └── vf.gf.locator.pid
160+
   └── server1
161+
   └── vf.gf.server.pid
162+
````
163+
164+
After deployment and startup step the file structure is identical on all cluster machines.
165+

Diff for: bin/cluster

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4+
5+
CMD=${1}
6+
7+
if [[ $# -eq 0 ]] ; then
8+
echo "Usage: $0 {start|stop|logs|deploy|clean}"
9+
exit 1
10+
fi
11+
12+
BIN_DIR=${DIR}/bin
13+
CONFIG_DIR=${DIR}/config
14+
FILE_READ_CMD=cat
15+
STAMP="logs_$(date +%F_%H%M%S)"
16+
17+
[[ ${CMD} == "stop" ]] && FILE_READ_CMD=tac
18+
[[ ${CMD} == "logs" ]] && mkdir -p ${DIR}/var/tmp/${STAMP}
19+
20+
TPUT='tput -T xterm-color'
21+
txtund=$(${TPUT} sgr 0 1) # Underline
22+
txtbld=$(${TPUT} bold) # Bold
23+
txtrst=$(${TPUT} sgr0) # Reset
24+
25+
${FILE_READ_CMD} ${CONFIG_DIR}/hostlist | while read -ra MAPPING; do
26+
27+
#IFS=" " read -ra MAPPING <<< "${line}"
28+
HOST="${MAPPING[0]}"
29+
ROLE="${MAPPING[1]}"
30+
NAME="${MAPPING[2]}"
31+
32+
case $CMD in
33+
clean)
34+
echo -e "${txtbld}\n######################################################"
35+
echo -e "# Cleaning Host: ${HOST} Instance: ${NAME}"
36+
echo "######################################################${txtrst}"
37+
COMMAND="rm -rf ${DIR}/var/log/${NAME}"
38+
ssh ${HOST} PATH=${PATH} COMMAND="'${COMMAND}'" 'bash -s' << 'END'
39+
$COMMAND
40+
END
41+
COMMAND="rm -rf ${DIR}/var/work/${NAME}"
42+
ssh ${HOST} PATH=${PATH} COMMAND="'${COMMAND}'" 'bash -s' << 'END'
43+
$COMMAND
44+
END
45+
;;
46+
deploy)
47+
if [[ "${HOST}" != "$(hostname -s)" ]]; then
48+
echo -e "${txtbld}\n######################################################"
49+
echo -e "# Copying config to Host: ${HOST}"
50+
echo "######################################################${txtrst}"
51+
52+
scp -r ${DIR}/lib ${HOST}:${DIR}
53+
scp -r ${BIN_DIR} ${HOST}:${DIR}
54+
scp -r ${CONFIG_DIR} ${HOST}:${DIR}
55+
fi
56+
;;
57+
logs)
58+
scp ${HOST}:${DIR}/var/log/${NAME}/*.log ${DIR}/var/tmp/${STAMP}
59+
scp ${HOST}:${DIR}/var/log/${NAME}/*.gfs ${DIR}/var/tmp/${STAMP}
60+
;;
61+
*)
62+
if [[ "${CMD}" == "start" ]]; then
63+
COMMAND="mkdir -p ${DIR}/var/log/${NAME}"
64+
ssh ${HOST} PATH=${PATH} COMMAND="'${COMMAND}'" 'bash -s' << 'END'
65+
$COMMAND
66+
END
67+
COMMAND="mkdir -p ${DIR}/var/work/${NAME}"
68+
ssh ${HOST} PATH=${PATH} COMMAND="'${COMMAND}'" 'bash -s' << 'END'
69+
$COMMAND
70+
END
71+
fi
72+
COMMAND="${BIN_DIR}/${CMD}-${ROLE} ${NAME}"
73+
echo -e "${txtbld}\n######################################################"
74+
echo -e "# Running command '${COMMAND}' on Host: ${HOST}"
75+
echo "######################################################${txtrst}"
76+
77+
ssh ${HOST} PATH=${PATH} COMMAND="'${COMMAND}'" 'bash -s' << 'END'
78+
$COMMAND
79+
END
80+
esac
81+
done
82+
83+
[[ ${CMD} == "logs" ]] && (tar -C ${DIR}/var/tmp -czvf ${STAMP}.tgz .; rm -rf ${DIR}/var/tmp)

Diff for: bin/start-locator

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4+
export NAME=${1}
5+
6+
CONFIG_DIR=${DIR}/config
7+
ETC_DIR=${DIR}/etc/${NAME}
8+
LOG_DIR=${DIR}/var/log/${NAME}
9+
WORK_DIR=${DIR}/var/work/${NAME}
10+
11+
export HOSTNAME=`hostname -s`
12+
export PORT=10334
13+
14+
export JAVA_OPTS="$JAVA_OPTS -Duser.language=en"
15+
export JAVA_OPTS="$JAVA_OPTS -Duser.country=US"
16+
17+
if [[ $# -eq 0 ]] ; then
18+
echo "Usage: $0 <instance_name>"
19+
exit 1
20+
fi
21+
22+
mkdir -p ${ETC_DIR}
23+
mkdir -p ${LOG_DIR}
24+
mkdir -p ${WORK_DIR}
25+
26+
cp ${CONFIG_DIR}/gemfire-locator.properties ${ETC_DIR}/gemfire.properties
27+
28+
for s in `printenv`; do
29+
IFS='=' read -ra ENVVAR <<< "${s}"
30+
if [[ ${ENVVAR[0]} != *"%"* && ${ENVVAR[1]} != *"%"* ]]; then
31+
#echo "s%{{${ENVVAR[0]}}}%${ENVVAR[1]}%g"
32+
sed -i "s%{{${ENVVAR[0]}}}%${ENVVAR[1]}%g" ${ETC_DIR}/gemfire.properties
33+
fi
34+
done
35+
36+
gfsh start locator --name=${NAME} --port=${PORT} --dir=${WORK_DIR} --properties-file=${ETC_DIR}/gemfire.properties

Diff for: bin/start-server

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4+
export NAME=${1}
5+
6+
CONFIG_DIR=${DIR}/config
7+
ETC_DIR=${DIR}/etc/${NAME}
8+
LOG_DIR=${DIR}/var/log/${NAME}
9+
WORK_DIR=${DIR}/var/work/${NAME}
10+
11+
export HOSTNAME=`hostname -s`
12+
export PORT=0
13+
export LOCATOR=vf0[10334]
14+
15+
export MAX_HEAP=2g
16+
export CLASSPATH="$(ls -1 ${DIR}/lib/*.jar | tr '\n' ':' | head -c -1)"
17+
18+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:MaxNewSize=768m"
19+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:NewSize=768m"
20+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+UseParNewGC"
21+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+UseConcMarkSweepGC"
22+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:ParallelGCThreads=6"
23+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+DoEscapeAnalysis"
24+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+CMSClassUnloadingEnabled"
25+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+UnlockDiagnosticVMOptions"
26+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:ParGCCardsPerStrideChunk=32768"
27+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+ScavengeBeforeFullGC"
28+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+OptimizeStringConcat"
29+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:MaxPermSize=128m"
30+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+DisableExplicitGC"
31+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-XX:+UseLargePages"
32+
export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-Xdebug --J='-agentlib:jdwp=transport=dt_socket,server=y,address=9000,suspend=n'"
33+
#export SERVER_JAVA_OPTS="$SERVER_JAVA_OPTS --J=-verbose:gc --J=-XX:+PrintGCDetails --J=-XX:+PrintGCDateStamps --J=-Xloggc:${LOG_DIR}/gc-${NAME}-${HOSTNAME}.log"
34+
35+
36+
if [[ $# -eq 0 ]] ; then
37+
echo "Usage: $0 <instance_name>"
38+
exit 1
39+
fi
40+
41+
mkdir -p ${ETC_DIR}
42+
mkdir -p ${LOG_DIR}
43+
mkdir -p ${WORK_DIR}
44+
45+
cp ${CONFIG_DIR}/gemfire-server.properties ${ETC_DIR}/gemfire.properties
46+
cp ${CONFIG_DIR}/cache.xml ${ETC_DIR}
47+
48+
for s in `printenv`; do
49+
IFS='=' read -ra ENVVAR <<< "${s}"
50+
if [[ ${ENVVAR[0]} != *"%"* && ${ENVVAR[1]} != *"%"* ]]; then
51+
#echo "s%{{${ENVVAR[0]}}}%${ENVVAR[1]}%g"
52+
sed -i "s%{{${ENVVAR[0]}}}%${ENVVAR[1]}%g" ${ETC_DIR}/gemfire.properties
53+
fi
54+
done
55+
56+
gfsh start server --name=${NAME} --server-port=${PORT} --dir=${WORK_DIR} \
57+
--cache-xml-file=${ETC_DIR}/cache.xml \
58+
--properties-file=${ETC_DIR}/gemfire.properties \
59+
--locators=$LOCATOR \
60+
--classpath=${CLASSPATH} \
61+
--max-heap=${MAX_HEAP} --initial-heap=${MAX_HEAP} \
62+
$SERVER_JAVA_OPTS
63+

Diff for: bin/stop-locator

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4+
5+
export NAME=${1}
6+
7+
if [[ $# -eq 0 ]] ; then
8+
echo "Usage: $0 <instance_name>"
9+
exit 1
10+
fi
11+
12+
WORK_DIR=${DIR}/var/work/${NAME}
13+
14+
gfsh stop locator --dir=${WORK_DIR}

Diff for: bin/stop-server

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4+
5+
export NAME=${1}
6+
7+
if [[ $# -eq 0 ]] ; then
8+
echo "Usage: $0 <instance_name>"
9+
exit 1
10+
fi
11+
12+
WORK_DIR=${DIR}/var/work/${NAME}
13+
14+
gfsh stop server --dir=${WORK_DIR}

Diff for: config/cache.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<cache xmlns="http://schema.pivotal.io/gemfire/cache"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://schema.pivotal.io/gemfire/cache http://schema.pivotal.io/gemfire/cache/cache-8.1.xsd"
5+
version="8.1">
6+
7+
8+
</cache>

0 commit comments

Comments
 (0)