forked from BorderlessNomad/DataPlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.sh
61 lines (43 loc) · 1.2 KB
/
redis.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
#!/bin/bash
# This is setup script for Redis server.
set -ex
if [ "$(id -u)" != "0" ]; then
echo >&2 "Error: This script must be run as user 'root'";
exit 1
fi
timestamp () {
date +"%F %T,%3N"
}
setuphost () {
HOSTNAME=$(hostname)
HOSTLOCAL="127.0.1.1"
echo "$HOSTLOCAL $HOSTNAME" >> /etc/hosts
}
install_redis () {
mkdir -p /home/ubuntu && cd /home/ubuntu
apt-get update
apt-get install -y redis-server
cp /etc/redis/redis.conf /etc/redis/redis.conf.backup
sed -i "s/bind 127.0.0.1/bind 0.0.0.0/" /etc/redis/redis.conf # Allow external connections
/etc/init.d/redis-server restart
}
install_redis_admin () {
npm install -g redis-commander
nohup redis-commander > redis-commander.log 2>&1&
}
update_iptables () {
# Redis Ports
iptables -A INPUT -p tcp --dport 6379 -j ACCEPT # Socket connections
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT # Redis Commander
iptables-save
}
echo "[$(timestamp)] ---- 1. Setup Host ----"
setuphost
echo "[$(timestamp)] ---- 2. Install Redis ----"
install_redis
echo "[$(timestamp)] ---- 3. Install Redis Admin ----"
install_redis_admin
echo "[$(timestamp)] ---- 4. Update IPTables rules ----"
update_iptables
echo "[$(timestamp)] ---- Completed ----"
exit 0