forked from oysterprotocol/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhk_install_centos7.sh
293 lines (248 loc) · 9.48 KB
/
hk_install_centos7.sh
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
#
# v1.0 - Initial release - 2018-02-18
# v1.1 - Added version locking for golang package - 2018-02-19
# v1.2 - Changed firewall port information slightly - 2018-02-19
# v1.3 - Addessed a permissions issue in the IOTA systemd file and change nelson to listen on all interfaces - 2018-02-19
#
# This script is heavily based on these:
# https://github.com/oysterprotocol/scripts/blob/master/iota_nelson_install.sh
# https://github.com/oysterprotocol/scripts/blob/master/hk2go.sh
#
# Modified for CentOS by: Eric Schewe (eric@pickysysadmin.ca)
# Donations:
# PRL - 0x89d501e6857318b64FfB09CBE8cC2a3B9D236ED7
# ETH - 0x3d6448fda5ec668c34d18b602b932d4bd3b1611e
# BTC - 1M7X411T2FE5uHneRe2bKdkCuCMJjmh1RW
# LTC - LMqvw577aYh6DQbgefs9zSpQvcVhdchWCU
#
# Original script can be found in this Github repo: https://github.com/oysterprotocol/scripts
# Additional information can be found here: https://www.pickysysadmin.ca/2018/02/18/script-to-install-oyster-protocol-prl-hooknode/
#
# Check if SELinux is disabled
selinuxCheck=`grep -i SELINUX=disabled /etc/selinux/config | wc -l`
if [ $selinuxCheck -ne 1 ]
then
clear
echo "SELinux is not disabled, please disable it, reboot and try running this script again"
echo "To disable SELinux run this command: \"sudo sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config\""
echo "Then reboot by running: \"shutdown -r now\""
echo "Once you've doen all that run this script again"
exit
fi
#
# OS section start
#
# Lets install some missing bits
# wget - so we can download things
# vim - so we can edit things
# deltarpm - to save some bandwidth
# yum-cron - to automate security updates
# ntp - to keep the clock right
# open-vm-tools - this is a VM after all
# policycoreutils-python - So we can do things with selinux instest of disabling it
# git - So we can clone repos and do other git like things
yum -y install wget vim deltarpm yum-cron ntp open-vm-tools policycoreutils-python git bind-utils yum-plugin-versionlock
# Configure yum-cron to install automatic security updates
cp /etc/yum/yum-cron.conf /etc/yum/yum-cron.conf.orig
sed -i -e 's/update_cmd = default/update_cmd = security/g' /etc/yum/yum-cron.conf
sed -i -e 's/apply_updates = no/apply_updates = yes/g' /etc/yum/yum-cron.conf
# Start and enable yum-cron
systemctl start yum-cron.service
systemctl enable yum-cron.service
# Enable NTP
systemctl start ntpd
systemctl enable ntpd
# Disable root logins for SSH
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sed -i -e 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
systemctl reload sshd
# Lets get the OS updated right out of the gate
yum -y update
#
# OS section end
#
#
# IOTA/NELSON section start
#
# Install NodeJS LTS
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs gcc-c++ make
# Intall Java 8
yum install -y java-1.8.0-openjdk
# Install IRI
useradd iota
su - iota -c "mkdir -p /home/iota/node /home/iota/node/ixi /home/iota/node/mainnetdb"
# Find latest IRI release
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/iotaledger/iri/releases/latest)
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
lv_nov=${LATEST_VERSION:1}
iri_v="iri-"$lv_nov".jar"
IRI_URL="https://github.com/iotaledger/iri/releases/download/"$LATEST_VERSION"/"$iri_v
dir_iri="/home/iota/node/"$iri_v
su - iota -c "wget -O $dir_iri $IRI_URL"
# Find RAM in MB
phymem=$(awk -F":" '$1~/MemTotal/{print $2}' /proc/meminfo )
phymem=${phymem:0:-2}
#allot about 75% of RAM to java
phymem=$((($phymem/1333) + ($phymem % 1333 > 0)))
xmx="Xmx"
xmx_end="m"
xmx=$xmx$phymem$xmx_end
# Set up Systemd service
cat <<EOF | tee /lib/systemd/system/iota.service
[Unit]
Description=IOTA (IRI) full node
After=network.target
[Service]
WorkingDirectory=/home/iota/node
User=iota
PrivateDevices=yes
#ProtectSystem=full # Currently bugged? https://github.com/iotaledger/iri/issues/548
Type=simple
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=60
ExecStart=/usr/bin/java -$xmx -Djava.net.preferIPv4Stack=true -jar $iri_v -c iota.ini
SyslogIdentifier=IRI
Restart=on-failure
RestartSec=30
[Install]
WantedBy=multi-user.target
Alias=iota.service
EOF
# Configure IRI
cat <<EOF | su - iota -c "tee /home/iota/node/iota.ini"
[IRI]
PORT = 14265
UDP_RECEIVER_PORT = 14600
TCP_RECEIVER_PORT = 15600
API_HOST = 0.0.0.0
IXI_DIR = ixi
HEADLESS = true
DEBUG = false
TESTNET = false
DB_PATH = mainnetdb
RESCAN_DB = false
REMOTE_LIMIT_API = "interruptAttachingToTangle, attachToTangle, setApiRateLimit"
# We don't need to add normal neighbors as we're going to be using Nelson
EOF
# Download the last known Tangle database
clear
echo ""
echo "Downloading latest Tangle database"
echo "Please be patient. This might take a while depending on your internet connection speed"
echo ""
echo ""
curl -L http://db.iota.partners/IOTA.partners-mainnetdb.tar.gz -o /tmp/IOTA.partners-mainnetdb.tar.gz
su - iota -c "tar xzfv /tmp/IOTA.partners-mainnetdb.tar.gz -C /home/iota/node/mainnetdb"
rm /tmp/IOTA.partners-mainnetdb.tar.gz
# Install Nelson
npm install -g nelson.cli
# Start IOTA and enable it on boot
service iota start
systemctl start iota.service
systemctl enable iota.service
# Install cronjob to automatically update IRI
echo '*/15 * * * * "curl -s https://gist.githubusercontent.com/zoran/48482038deda9ce5898c00f78d42f801/raw | bash"' | tee /etc/cron.d/iri_updater > /dev/null
# Start Nelson with pm2
npm install pm2 -g
pm2 startup
pm2 start nelson -- --getNeighbors --apiHostname 0.0.0.0
pm2 save
#
# IOTA/NELSON section end
#
#
# Oyster/Hooknode section start
#
service iota stop
# Install the latest 1.9.3 go
# Hooknode won't compile if you're using v1.9.4 or newer
rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO
curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo
# Comment this out if newer than 1.9.3 becomes supported, see next few lines for your options
yum install -y golang-1.9.3-0.el7.centos
yum versionlock golang-*
# Uncomment these two lines if newer than 1.9.3 becomes supported but not 1.10.x
#goVersionNumber=`yum --showduplicates list golang |grep -oP '1.9\.[0-9].*centos?' | sort |tail -n 1`
#yum install -y golang-$goVersionNumber
# Uncomment this line if 1.10.x ever becomes supported
#yum install -y golang
# Create a user for hooknode and setup go
adduser hooknode
su - hooknode -c "echo \"export GOROOT=/usr/lib/golang\" >> /home/hooknode/.bash_profile"
su - hooknode -c "echo \"export GOPATH=/home/hooknode/go\" >> /home/hooknode/.bash_profile"
su - hooknode -c "echo \"export PATH=/home/hooknode/go/bin:\$PATH\" >> /home/hooknode/.bash_profile"
su - hooknode -c "mkdir -p /home/hooknode/go/src"
su - hooknode -c "mkdir -p /home/hooknode/go/bin"
# Install the go dependancy manager
su - hooknode -c "go get -u github.com/golang/dep/cmd/dep"
# Pull the hooknode repo
su - hooknode -c "mkdir -p /home/hooknode/go/src/github.com/oysterprotocol"
su - hooknode -c "cd /home/hooknode/go/src/github.com/oysterprotocol; git clone https://github.com/oysterprotocol/hooknode.git"
su - hooknode -c "cp /home/hooknode/go/src/github.com/oysterprotocol/hooknode/.env.example /home/hooknode/go/src/github.com/oysterprotocol/hooknode/.env"
su - hooknode -c "cd /home/hooknode/go/src/github.com/oysterprotocol/hooknode/; make install-deps"
su - hooknode -c "cd /home/hooknode/go/src/github.com/oysterprotocol/hooknode/; go build -o ./bin/main.go"
# Setup systemd service
cat <<EOF | tee /lib/systemd/system/hooknode.service
[Unit]
Description=Oyster Hooknode in Golang
After=network.target
[Service]
WorkingDirectory=/home/hooknode/go/src/github.com/oysterprotocol/hooknode
User=hooknode
PrivateDevices=yes
ProtectSystem=full
Type=simple
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=60
ExecStart=/home/hooknode/go/src/github.com/oysterprotocol/hooknode/bin/main.go
SyslogIdentifier=HOOKN
Restart=on-failure
RestartSec=30
[Install]
WantedBy=multi-user.target
Alias=hooknode.service
EOF
# Start service
service hooknode start
systemctl start hooknode.service
systemctl enable hooknode.service
# Start iota again
service iota start
# Open the firewall for incoming connections
firewall-cmd --zone=public --add-port=14600/udp --permanent
firewall-cmd --zone=public --add-port=15600/tcp --permanent
firewall-cmd --zone=public --add-port=18600/tcp --permanent
firewall-cmd --reload
# Get IPs
externalIps="$(dig +short myip.opendns.com @resolver1.opendns.com)"
internalIps="$(hostname -I)"
internalIps="$(echo -e "${internalIps}" | tr -d '[:space:]')"
# Prepare and show confirmation message
echo "Installation complete!"
echo ""
echo "You will now need to open the appropriate ports on your firewall/router:"
echo "Port 14600 - UDP"
echo "Port 15600 - TCP"
echo "Port 18600 - TCP - Optional if you want to view your node status remotely"
echo ""
echo "This servers internal IP is: $internalIps"
echo "This servers external IP is: $externalIps"
echo ""
echo "You can view your nodes status via http://$internalIps:18600"
echo "If you open port 18600 on your firewall you can view your nodes status via http://$externalIps:18600"
echo ""
echo "Copy/paste the above information and store it some place for reference."
echo "It is recommended you reboot this server to finish installation by running \"shutdown -r now\""
echo ""
echo "Donations are always welcome."
echo " PRL - 0x89d501e6857318b64FfB09CBE8cC2a3B9D236ED7"
echo " ETH - 0x3d6448fda5ec668c34d18b602b932d4bd3b1611e"
echo " BTC - 1M7X411T2FE5uHneRe2bKdkCuCMJjmh1RW"
echo " LTC - LMqvw577aYh6DQbgefs9zSpQvcVhdchWCU"
echo ""