-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·187 lines (146 loc) · 5.92 KB
/
install.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
#!/bin/bash
set -eu
v_program="${0##*/}"
v_self="$(readlink -f "${BASH_SOURCE[0]}")"
[[ $UID == 0 ]] || exec sudo -p "$v_program must be run as root. Please enter the password for %u to continue: " -- "$BASH" -- "$v_self"
v_trust_ip="`last -1w | grep $USER | awk '{ print $3 }'`"
v_ssh_port="`cat /etc/ssh/sshd_config 2>/dev/null | grep Port | awk '{ print $2 }' | head -n 1`"
read -p "Enter IP to allow ssh,algod,kmd access (default '$v_trust_ip'): " -i $v_trust_ip -e v_trust_ip
# Run the commands in a noninteractive mode
export DEBIAN_FRONTEND=noninteractive
# update system packages
apt-get update -y
apt-get upgrade -y
# install required system packages
apt-get install -y ca-certificates curl nftables
# configure nftables
cat <<EOF > /etc/nftables.conf
table ip filter {
set trust_ipset {
type ipv4_addr
elements = { $v_trust_ip }
}
chain input {
type filter hook input priority filter; policy drop;
iifname "lo" accept
iifname != "lo" ip saddr 127.0.0.0/24 reject with icmp type prot-unreachable
iifname "eth0" ip protocol icmp ct state { established, related } accept
iifname "eth0" udp sport 53 ct state established accept
iifname "eth0" tcp sport 53 ct state established accept
iifname "eth0" tcp sport { 80, 443 } ct state established accept
iifname "eth0" icmp type echo-request ip saddr @trust_ipset ct state new accept
iifname "eth0" tcp dport { $v_ssh_port, 9090, 9091, 9100 } ip saddr @trust_ipset ct state { established, new } accept
}
chain output {
type filter hook output priority filter; policy drop;
oifname "lo" accept
oifname "eth0" ip protocol icmp ct state { established, new } accept
oifname "eth0" udp dport 53 ct state { established, new } accept
oifname "eth0" tcp dport 53 ct state { established, new } accept
oifname "eth0" tcp dport { 80, 443 } ct state { established, new } accept
oifname "eth0" tcp sport { $v_ssh_port, 9090, 9091, 9100 } ip daddr @trust_ipset ct state established accept
}
}
EOF
systemctl enable nftables.service
systemctl start nftables.service
# create algorand user
useradd --system \
-M \
--user-group \
--shell /sbin/nologin \
algorand
# install algorand node
mkdir -p /opt/algorand/node
curl -L -o /opt/algorand/node/update.sh \
https://raw.githubusercontent.com/algorand/go-algorand-doc/master/downloads/installers/update.sh
chmod 500 /opt/algorand/node/update.sh
cd /opt/algorand/node/ \
&& ./update.sh -i -n -c stable \
-p /opt/algorand/node/ \
-d /opt/algorand/node/data/
# configure algod
cat <<EOF > /opt/algorand/node/data/config.json
{
"Archival": false,
"CatchupBlockDownloadRetryAttempts": 100000,
"DNSBootstrapID": "<network>.algorand.network",
"DNSSecurityFlags": 1,
"EnableDeveloperAPI": true,
"EnableMetricReporting": true,
"EndpointAddress": ":9090",
"FallbackDNSResolverAddress": "8.8.8.8",
"GossipFanout": 8,
"NodeExporterListenAddress": ":9100",
"NodeExporterPath": "./node_exporter --no-collector.diskstats"
}
EOF
chown root:root /opt/algorand/node/data/config.json
chmod 0644 /opt/algorand/node/data/config.json
cat <<EOF > /opt/algorand/node/data/algod.token
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
EOF
chown root:root /opt/algorand/node/data/algod.token
chmod 0644 /opt/algorand/node/data/algod.token
cat <<EOF > /opt/algorand/node/data/algod.admin.token
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
EOF
chown root:root /opt/algorand/node/data/algod.admin.token
chmod 0644 /opt/algorand/node/data/algod.admin.token
# configure kmd
cat <<EOF > /opt/algorand/node/data/kmd-v0.5/kmd_config.json
{
"address":":9091",
"allowed_origins": ["*"],
"session_lifetime_secs": 60
}
EOF
chown root:root /opt/algorand/node/data/kmd-v0.5/kmd_config.json
chmod 0644 /opt/algorand/node/data/kmd-v0.5/kmd_config.json
cat <<EOF > /opt/algorand/node/data/kmd-v0.5/kmd.token
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
EOF
chown root:root /opt/algorand/node/data/kmd-v0.5/kmd.token
chmod 0644 /opt/algorand/node/data/kmd-v0.5/kmd.token
chown -R algorand:algorand /opt/algorand
chmod 700 /opt/algorand/node/data/kmd-v0.5
# configure systemd
cat <<EOF > /etc/default/algod
ALGORAND_DATA="/opt/algorand/node/data"
EOF
chown root:root /etc/default/algod
chmod 0644 /etc/default/algod
cat <<EOF > /lib/systemd/system/algod.service
[Unit]
Description=Algorand daemon under /opt/algorand/node/data
Wants=network.target
After=network.target
AssertFileIsExecutable=/opt/algorand/node/algod
AssertPathExists=/opt/algorand/node/data
[Service]
WorkingDirectory=/opt/algorand/node/
User=algorand
Group=algorand
EnvironmentFile=/etc/default/algod
ExecStartPre=bash -c "[[ ! -f /opt/algorand/node/data/system.json ]] && echo '{\"shared_server\":true,\"systemd_managed\":true}' > /opt/algorand/node/data/system.json || :"
ExecStart=/opt/algorand/node/algod
# Let systemd restart this service always
Restart=always
RestartSec=5s
ProtectSystem=false
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
EOF
chown root:root /lib/systemd/system/algod.service
chmod 0644 /lib/systemd/system/algod.service
systemctl enable algod
systemctl start algod
timeout 30 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' 127.0.0.1 9090
catchpoint=$(curl "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint")
ALGORAND_DATA=/opt/algorand/node/data /opt/algorand/node/goal node catchup "${catchpoint}"
ALGORAND_DATA=/opt/algorand/node/data /opt/algorand/node/goal node status