-
Notifications
You must be signed in to change notification settings - Fork 2
/
neo4j.tftpl
150 lines (132 loc) · 7.5 KB
/
neo4j.tftpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash -x
## 0 - Wait 30 seconds before starting script execution
sleep 30
#ONLY USED FOR TESTING
#OVERRIDE_VERSION=5.2.0
## 1 - Variable Setting and Test
INSTALL_GDS=${install_gds}
INSTALL_BLOOM=${install_bloom}
GDS_KEY=${gds_key}
BLOOM_KEY=${bloom_key}
NEO4J_PASSWORD=${neo4j_password}
NODE_COUNT=${node_count}
LB_FQDN=${lb_fqdn}
NEO4J_VERSION=${neo4j_version}
TARGET_REGION=${target_region}
LB_ARN=${lb_arn}
THIS_INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
ENV_PREFIX=${env_prefix}
function aws_get_private_ips {
aws ec2 describe-instances\
--output=text\
--region=$TARGET_REGION\
--filters Name=tag:Terraform,Values=true\
--filters Name=tag:Name,Values=$ENV_PREFIX-instance\
--query "Reservations[].Instances[].PrivateIpAddress"
}
PRIVATE_IPS=$(aws_get_private_ips)
for ip in $PRIVATE_IPS ; do
private_ip_array+=("$ip:5000,")
done
CORE_MEMBERS=$(echo $${private_ip_array[@]} | sed 's/,$//' | sed 's/ //g')
function existing_version_tag {
aws elbv2 describe-tags\
--resource-arns $LB_ARN\
--region=$TARGET_REGION\
--query 'TagDescriptions[*].Tags[?Key==`Neo4j_Built_Version`].Value'\
--output=text
}
EXISTING_VERSION_TAG="$(existing_version_tag)"
## 2 - Install Neo4j using yum
echo " - [ Installing Graph Database ] - "
export NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
if [[ ! -z $OVERRIDE_VERSION && $OVERRIDE_VERSION =~ ^[0-9]\.[0-9]\.[0-9]$ ]]; then
echo " - [ Installing OVERRIDE_VERSION: $OVERRIDE_VERSION ] - "
yum install -y neo4j-enterprise-$OVERRIDE_VERSION
sleep 1
aws elbv2 add-tags --resource-arns $LB_ARN --tags Key=Neo4j_Built_Version,Value=$(/usr/share/neo4j/bin/neo4j --version) --region=$TARGET_REGION
elif [[ $EXISTING_VERSION_TAG =~ ^[0-9]\.[0-9]\.[0-9]$ ]]; then
echo " - [ Existing version tag already exists, building with version $EXISTING_VERSION_TAG to preserve cluster version ] - "
yum install -y neo4j-enterprise-$EXISTING_VERSION_TAG
else
echo "No valid existing version set - assuming initial deployment"
PACKAGE_VERSION=$(curl --fail http://versions.neo4j-templates.com/target.json | jq -r ".aws[\"$NEO4J_VERSION\"]" || echo "")
if [[ ! -z $PACKAGE_VERSION && $PACKAGE_VERSION != "null" ]]; then
echo " - [ Found PACKAGE_VERSION from http://versions.neo4j-templates.com : PACKAGE_VERSION=$PACKAGE_VERSION ] - "
yum install -y neo4j-enterprise-$PACKAGE_VERSION
sleep 1
aws elbv2 add-tags --resource-arns $LB_ARN --tags Key=Neo4j_Built_Version,Value=$(/usr/share/neo4j/bin/neo4j --version) --region=$TARGET_REGION
else
echo '- [ Failed to resolve Neo4j version from http://versions.neo4j-templates.com, using PACKAGE_VERSION=latest ] - '
yum install -y "neo4j-enterprise"
aws elbv2 add-tags --resource-arns $LB_ARN --tags Key=Neo4j_Built_Version,Value=$(/usr/share/neo4j/bin/neo4j --version) --region=$TARGET_REGION
fi
fi
systemctl enable neo4j
if [[ "$PACKAGE_VERSION" == "latest" ]]; then
PACKAGE_VERSION=$(/usr/share/neo4j/bin/neo4j --version)
fi
## 3 - Extension Config
echo " - [ Configuring extensions and security in neo4j.conf ] - "
sed -i s~#server.unmanaged_extension_classes=org.neo4j.examples.server.unmanaged=/examples/unmanaged~server.unmanaged_extension_classes=com.neo4j.bloom.server=/bloom,semantics.extension=/rdf~g /etc/neo4j/neo4j.conf
sed -i s/#dbms.security.procedures.unrestricted=my.extensions.example,my.procedures.*/dbms.security.procedures.unrestricted=gds.*,apoc.*,bloom.*/g /etc/neo4j/neo4j.conf
echo "dbms.security.http_auth_allowlist=/,/browser.*,/bloom.*" >> /etc/neo4j/neo4j.conf
echo "dbms.security.procedures.allowlist=apoc.*,gds.*,bloom.*" >> /etc/neo4j/neo4j.conf
## 4 - Neo4j Main Configuration
echo " - [ Neo4j Main (Network & Cluster Configuration ] - "
THIS_PRIVATE_IP="$(hostname -i | awk '{print $NF}')"
sed -i s/#server.default_listen_address=0.0.0.0/server.default_listen_address=0.0.0.0/g /etc/neo4j/neo4j.conf
sed -i s/#server.default_advertised_address=localhost/server.default_advertised_address="$LB_FQDN"/g /etc/neo4j/neo4j.conf
sed -i s/#server.discovery.advertised_address=:5000/server.discovery.advertised_address="$THIS_PRIVATE_IP":5000/g /etc/neo4j/neo4j.conf
sed -i s/#server.cluster.advertised_address=:6000/server.cluster.advertised_address="$THIS_PRIVATE_IP":6000/g /etc/neo4j/neo4j.conf
sed -i s/#server.cluster.raft.advertised_address=:7000/server.cluster.raft.advertised_address="$THIS_PRIVATE_IP":7000/g /etc/neo4j/neo4j.conf
sed -i s/#server.routing.advertised_address=:7688/server.routing.advertised_address="$THIS_PRIVATE_IP":7688/g /etc/neo4j/neo4j.conf
sed -i s/#server.discovery.listen_address=:5000/server.discovery.listen_address="$THIS_PRIVATE_IP":5000/g /etc/neo4j/neo4j.conf
sed -i s/#server.routing.listen_address=0.0.0.0:7688/server.routing.listen_address="$THIS_PRIVATE_IP":7688/g /etc/neo4j/neo4j.conf
sed -i s/#server.cluster.listen_address=:6000/server.cluster.listen_address="$THIS_PRIVATE_IP":6000/g /etc/neo4j/neo4j.conf
sed -i s/#server.cluster.raft.listen_address=:7000/server.cluster.raft.listen_address="$THIS_PRIVATE_IP":7000/g /etc/neo4j/neo4j.conf
sed -i s/#server.bolt.listen_address=:7687/server.bolt.listen_address="$THIS_PRIVATE_IP":7687/g /etc/neo4j/neo4j.conf
sed -i s/#server.bolt.advertised_address=:7687/server.bolt.advertised_address="$THIS_PRIVATE_IP":7687/g /etc/neo4j/neo4j.conf
neo4j-admin server memory-recommendation >> /etc/neo4j/neo4j.conf
echo "server.metrics.enabled=true" >> /etc/neo4j/neo4j.conf
echo "server.metrics.jmx.enabled=true" >> /etc/neo4j/neo4j.conf
echo "server.metrics.prefix=neo4j" >> /etc/neo4j/neo4j.conf
echo "server.metrics.filter=*" >> /etc/neo4j/neo4j.conf
echo "server.metrics.csv.interval=5s" >> /etc/neo4j/neo4j.conf
echo "dbms.routing.default_router=SERVER" >> /etc/neo4j/neo4j.conf
if [[ $NODE_COUNT == 1 ]]; then
echo "- [ Running on a single node ] -"
else
echo " - [ Running on multiple nodes. Configuring membership in neo4j.conf ] - "
sed -i s/#initial.dbms.default_primaries_count=1/initial.dbms.default_primaries_count=3/g /etc/neo4j/neo4j.conf
sed -i s/#initial.dbms.default_secondaries_count=0/initial.dbms.default_secondaries_count=$(expr $NODE_COUNT - 3)/g /etc/neo4j/neo4j.conf
sed -i s/#server.bolt.listen_address=:7687/server.bolt.listen_address="$THIS_PRIVATE_IP":7687/g /etc/neo4j/neo4j.conf
echo "dbms.cluster.minimum_initial_system_primaries_count=$NODE_COUNT" >> /etc/neo4j/neo4j.conf
sed -i s/#dbms.cluster.discovery.endpoints=localhost:5000,localhost:5001,localhost:5002/dbms.cluster.discovery.endpoints=$CORE_MEMBERS/g /etc/neo4j/neo4j.conf
fi
## 5 - Install Graph Data Science
if [[ "$INSTALL_GDS" == true && $NODE_COUNT == 1 ]]; then
echo " - [ Installing Graph Data Science] - "
cp /var/lib/neo4j/products/neo4j-graph-data-science-*.jar /var/lib/neo4j/plugins
fi
if [[ $GDS_KEY != None ]]; then
echo " - [ Writing GDS license key ] - "
mkdir -p /etc/neo4j/licenses
echo "$GDS_KEY" > /etc/neo4j/licenses/neo4j-gds.license
sed -i '$a gds.enterprise.license_file=/etc/neo4j/licenses/neo4j-gds.license' /etc/neo4j/neo4j.conf
fi
## 6 - Install Bloom
if [[ $INSTALL_BLOOM == true ]]; then
echo " - [ Installing Bloom ] - "
cp /var/lib/neo4j/products/bloom-plugin-*.jar /var/lib/neo4j/plugins
fi
if [[ $BLOOM_KEY != None ]]; then
echo " - [ Writing Bloom license key ] - "
mkdir -p /etc/neo4j/licenses
echo "$BLOOM_KEY" > /etc/neo4j/licenses/neo4j-bloom.license
sed -i '$a dbms.bloom.license_file=/etc/neo4j/licenses/neo4j-bloom.license' /etc/neo4j/neo4j.conf
fi
## 7 - Start Neo4j
echo " - [ Starting Neo4j ] - "
service neo4j start
neo4j-admin dbms set-initial-password "$NEO4J_PASSWORD"