-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathredis-install.sh
executable file
·328 lines (304 loc) · 11 KB
/
redis-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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
######################################################
# redis installer
# written by George Liu (eva2000) centminmod.com
######################################################
# variables
#############
DT=$(date +"%d%m%y-%H%M%S")
REDIS_SOURCEVER='6.2.6'
REDIS_THREADIO='n'
OSARCH=$(uname -m)
SRCDIR=/svr-setup
DEVTOOLSETFOUR='n'
DEVTOOLSETSIX='n'
DEVTOOLSETSEVEN='n'
DEVTOOLSETEIGHT='n'
DEVTOOLSETNINE='n'
DEVTOOLSETTEN='y'
DEVTOOLSETELEVEN='n'
GOLDLINKER='n'
FLTO='n'
DWARF='n'
HOIST='y'
######################################################
# functions
#############
if [ ! -d "$SRCDIR" ]; then
mkdir -p "$SRCDIR"
fi
if [ "$OSARCH" != 'x86_64' ]; then
echo
echo "64bit OS only"
echo "aborting..."
exit
fi
CENTOSVER=$(awk '{ print $3 }' /etc/redhat-release)
if [ "$CENTOSVER" == 'release' ]; then
CENTOSVER=$(awk '{ print $4 }' /etc/redhat-release | cut -d . -f1,2)
if [[ "$(cat /etc/redhat-release | awk '{ print $4 }' | cut -d . -f1)" = '7' ]]; then
CENTOS_SEVEN='7'
elif [[ "$(cat /etc/redhat-release | awk '{ print $4 }' | cut -d . -f1)" = '8' ]]; then
CENTOS_EIGHT='8'
fi
fi
if [[ "$(cat /etc/redhat-release | awk '{ print $3 }' | cut -d . -f1)" = '6' ]]; then
CENTOS_SIX='6'
fi
# Check for Redhat Enterprise Linux 7.x
if [ "$CENTOSVER" == 'Enterprise' ]; then
CENTOSVER=$(awk '{ print $7 }' /etc/redhat-release)
if [[ "$(awk '{ print $1,$2 }' /etc/redhat-release)" = 'Red Hat' && "$(awk '{ print $7 }' /etc/redhat-release | cut -d . -f1)" = '7' ]]; then
CENTOS_SEVEN='7'
REDHAT_SEVEN='y'
fi
fi
if [[ -f /etc/system-release && "$(awk '{print $1,$2,$3}' /etc/system-release)" = 'Amazon Linux AMI' ]]; then
CENTOS_SIX='6'
fi
if [ -f /etc/almalinux-release ]; then
CENTOSVER=$(awk '{ print $3 }' /etc/almalinux-release)
if [[ "$(echo $CENTOSVER | cut -d . -f1)" -eq '8' ]]; then
CENTOS_EIGHT='8'
ALMALINUX_EIGHT='8'
elif [[ "$(echo $CENTOSVER | cut -d . -f1)" -eq '9' ]]; then
CENTOS_NINE='9'
ALMALINUX_NINE='9'
fi
fi
if [ -f /etc/rocky-release ]; then
CENTOSVER=$(awk '{ print $4 }' /etc/rocky-release)
if [[ "$(echo $CENTOSVER | cut -d . -f1)" -eq '8' ]]; then
CENTOS_EIGHT='8'
ROCKYLINUX_EIGHT='8'
elif [[ "$(echo $CENTOSVER | cut -d . -f1)" -eq '9' ]]; then
CENTOS_NINE='9'
ROCKYLINUX_NINE='9'
fi
fi
if [ ! -d /etc/systemd/system ]; then
echo
echo "systemd not detected aborting..."
echo
exit
fi
if [ ! -f /etc/yum.repos.d/remi.repo ]; then
echo
echo "redis REMI YUM repo not installed"
echo "installing..."
wget -cnv https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
fi
if [ ! -f /etc/yum.repos.d/epel.repo ]; then
echo
echo "epel YUM repo not installed"
echo "installing..."
yum -y install epel-release
fi
if [ -f /proc/user_beancounters ]; then
CPUS=$(grep -c "processor" /proc/cpuinfo)
if [[ "$CPUS" -gt '8' ]]; then
CPUS=$(echo $(($CPUS+2)))
else
CPUS=$(echo $(($CPUS+1)))
fi
MAKETHREADS=" -j$CPUS"
else
CPUS=$(grep -c "processor" /proc/cpuinfo)
if [[ "$CPUS" -gt '8' ]]; then
CPUS=$(echo $(($CPUS+4)))
elif [[ "$CPUS" -eq '8' ]]; then
CPUS=$(echo $(($CPUS+2)))
else
CPUS=$(echo $(($CPUS+1)))
fi
MAKETHREADS=" -j$CPUS"
fi
redisinstall() {
echo "install redis server..."
if [[ "$CENTOS_SEVEN" -eq 7 && -f /etc/yum/pluginconf.d/priorities.conf && "$(grep 'enabled = 1' /etc/yum/pluginconf.d/priorities.conf)" ]]; then
yum -y install redis --enablerepo=remi --disableplugin=priorities
else
yum -y install redis --enablerepo=remi
fi
sed -i 's|LimitNOFILE=.*|LimitNOFILE=524288|' /etc/systemd/system/redis.service.d/limit.conf
# echo -e "[Service]\nExecStartPre=/usr/sbin/sysctl vm.overcommit_memory=1" > /etc/systemd/system/redis.service.d/vm.conf
# mkdir -p /redis/tools
# echo '#!/bin/bash' > /redis/tools/disable_thp.sh
# echo "/usr/bin/echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled" >> /redis/tools/disable_thp.sh
# chmod +x /redis/tools/disable_thp.sh
# chown -R redis:redis /redis/tools
# echo -e "[Service]\nExecStartPre=-/redis/tools/disable_thp.sh" > /etc/systemd/system/redis.service.d/execstartpre.conf
# echo -e "[Unit]\nAfter=network.target rc.local" > /etc/systemd/system/redis.service.d/after-rc-local.conf
cat > "/etc/systemd/system/redis.service.d/user.conf" <<EOF
[Service]
User=redis
Group=nginx
EOF
cat > "/etc/systemd/system/disable-thp.service" <<EOF
[Unit]
Description=Disable Transparent Huge Pages (THP)
After=network.target
[Service]
Type=simple
ExecStart=/bin/sh -c "/usr/bin/echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled"
[Install]
WantedBy=multi-user.target
EOF
if [ -f /etc/systemd/system/disable-thp.service ]; then
systemctl daemon-reload
systemctl start disable-thp
systemctl enable disable-thp
fi
# echo "d /var/run/redis/ 0755 redis nginx" > /etc/tmpfiles.d/redis.conf
mkdir -p /var/run/redis
chown redis:nginx /var/run/redis
chmod 755 /var/run/redis
systemctl daemon-reload
systemctl restart redis
systemctl enable redis
systemctl restart redis
systemctl enable redis
if [[ "$(sysctl -n vm.overcommit_memory)" -ne '1' ]]; then
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
fi
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
if [[ -z "$(grep 'transparent_hugepage\/enabled' /etc/rc.local)" ]]; then
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
fi
fi
sysctl -p
echo "redis server installled"
}
redisinstall_source() {
echo "source install redis server..."
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETFOUR" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-4/root/usr/bin/gcc && -f /opt/rh/devtoolset-4/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-4/enable
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETSIX" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-6/root/usr/bin/gcc && -f /opt/rh/devtoolset-6/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-6/enable
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETSEVEN" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-7/root/usr/bin/gcc && -f /opt/rh/devtoolset-7/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-7/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETEIGHT" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-8/root/usr/bin/gcc && -f /opt/rh/devtoolset-8/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-8/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETEIGHT" = [yY] ]]; then
if [[ -f /opt/gcc8/bin/gcc && -f /opt/gcc8/bin/g++ ]]; then
source /opt/gcc8/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETNINE" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-9/root/usr/bin/gcc && -f /opt/rh/devtoolset-9/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-9/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETTEN" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-10/root/usr/bin/gcc && -f /opt/rh/devtoolset-10/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-10/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_SEVEN" -eq 7 && "$DEVTOOLSETELEVEN" = [yY] ]]; then
if [[ -f /opt/rh/devtoolset-11/root/usr/bin/gcc && -f /opt/rh/devtoolset-11/root/usr/bin/g++ ]]; then
source /opt/rh/devtoolset-11/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_EIGHT" -eq 8 && "$DEVTOOLSETNINE" = [yY] ]]; then
if [[ -f /opt/rh/gcc-toolset-9/root/usr/bin/gcc && -f /opt/rh/gcc-toolset-9/root/usr/bin/g++ ]]; then
source /opt/rh/gcc-toolset-9/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$CENTOS_EIGHT" -eq 8 && "$DEVTOOLSETTEN" = [yY] ]]; then
if [[ -f /opt/rh/gcc-toolset-10/root/usr/bin/gcc && -f /opt/rh/gcc-toolset-10/root/usr/bin/g++ ]]; then
source /opt/rh/gcc-toolset-10/enable
if [[ "$HOIST" = [yY] ]]; then
HOIST_OPT=' -fcode-hoisting'
fi
EXTRA_CFLAGS=" -Wimplicit-fallthrough=0${HOIST_OPT} -Wno-maybe-uninitialized -Wno-stringop-truncation -Wno-lto-type-mismatch -Wno-misleading-indentation -Wno-format-truncation"
fi
fi
if [[ "$FLTO" = [yY] ]]; then
FLTO_OPT=' -flto -ffat-lto-objects'
fi
if [[ "$GOLDLINKER" = [yY] ]]; then
GOLDLINKER_OPT=' -fuse-ld=gold'
fi
if [[ "$DWARF" = [yY] ]]; then
DWARF_OPT=' -gsplit-dwarf'
fi
export OPT=-03
export CFLAGS="-march=native${FLTO_OPT}${GOLDLINKER_OPT} -fvisibility=hidden${DWARF_OPT}${EXTRA_CFLAGS}"
export CXXFLAGS="$CFLAGS"
cd "$SRCDIR"
rm -rf redis-${REDIS_SOURCEVER}*
rm -rf redis-${REDIS_SOURCEVER}-threaded*
REDIS_THREADIO='n'
if [[ "$REDIS_THREADIO" = [yY] ]]; then
git clone -b threaded-io --depth=1 https://github.com/redis/redis redis-${REDIS_SOURCEVER}-threaded
cd redis-${REDIS_SOURCEVER}-threaded
else
wget http://download.redis.io/releases/redis-${REDIS_SOURCEVER}.tar.gz
tar xzf redis-${REDIS_SOURCEVER}.tar.gz
cd redis-${REDIS_SOURCEVER}
fi
make distclean
make clean
make${MAKETHREADS}
make install
echo "redis server source installled"
}
######################################################
case "$1" in
install )
redisinstall
;;
install-source )
redisinstall_source
;;
* )
echo
echo "Usage:"
echo
echo "$0 {install|install-source}"
echo
;;
esac
exit