操作系統(tǒng)和redis安裝包版本
CentOS Linux release 7.4.1708 (Core)
redis-2.8.19.tar.gz
操作系統(tǒng)配置
關(guān)閉大頁
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
修改vm.overcommit_memory
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
修改somaconn
echo 511 > /proc/sys/net/core/somaxconn
安裝需要的庫
yum install -y epel-release
yum install jemalloc-devel
yum install gcc
epel的全稱叫 Extra Packages for Enterprise Linux 泌绣。是由 Fedora 社區(qū)打造,為 RHEL 及衍生發(fā)行版如 CentOS预厌、Scientific Linux 等提供高質(zhì)量軟件包的項目阿迈。裝上了 EPEL之后,就相當(dāng)于添加了一個第三方源轧叽,版本會比官方的包更新苗沧,而且還有一些官方?jīng)]有的包,比如jemalloc-devel炭晒。
redis解壓安裝
tar -zxvf redis-2.8.19.tar.gz
cd redis-2.8.19
make
cd src
make install
默認(rèn)安裝在/usr/local/bin
總用量 20968
-rwxr-xr-x. 1 501 games 13025336 5月 17 02:32 dbdeployer
-rwxr-xr-x. 1 root root 4091872 5月 19 09:51 redis-server
-rwxr-xr-x. 1 root root 2075616 5月 19 09:51 redis-benchmark
-rwxr-xr-x. 1 root root 2185184 5月 19 09:51 redis-cli
-rwxr-xr-x. 1 root root 56016 5月 19 09:51 redis-check-dump
-rwxr-xr-x. 1 root root 25168 5月 19 09:51 redis-check-aof
lrwxrwxrwx. 1 root root 27 5月 19 09:51 redis-sentinel -> /usr/local/bin/redis-server
創(chuàng)建配置文件待逞,目錄并且做成service
配置文件模版
把配置文件放到/app 目錄下redis.conf
pidfile "/app/redis/redis_6379.pid"
port 6379
logfile "/app/redis/redis.log"
daemonize yes
requirepass "xxxx"
databases 256
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 0 0 0
tcp-backlog 511
timeout 86400
tcp-keepalive 60
maxclients 10000
dir "/app/redis"
save 900 1
save 300 10
save 60 10000
dumpfile "dump.rdb"
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
auto-aof-rewrite-percentage 200
#memory
maxmemory 5gb
#slave-read-only yes
#slaveof 111.111.111.111
#masterauth "aldt2020"
#forbit command
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command KEYS ""
#slow log monitor
latency-monitor-threshold 1000 #1s
slowlog-log-slower-than 60000 #60s
拷貝redis_init_script到/etc/init.d目錄
cp ~/redis-2.8.19/utils/redis_init_script /etc/init.d/redis
修改redis_init_script文件里相關(guān)的配置PIDFILE和CONF
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/app/redis/redis_${REDISPORT}.pid
CONF="/app/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
啟動redis service redis start
常見安裝錯誤
- 1
cc: 錯誤:../deps/hiredis/libhiredis.a:沒有那個文件或目錄
cc: 錯誤:../deps/lua/src/liblua.a:沒有那個文件或目錄
cc: 錯誤:../deps/jemalloc/lib/libjemalloc.a:沒有那個文件或目錄
make[1]: *** [redis-server] 錯誤 1
make[1]: 離開目錄“/root/redis-2.8.19/src”
make: *** [all] 錯誤 2
解決辦法 make distclean
- 2
[root@localhost src]# make install
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命錯誤:jemalloc/jemalloc.h:沒有那個文件或目錄
#include <jemalloc/jemalloc.h>
^
編譯中斷。
make: *** [adlist.o] 錯誤 1
解決辦法 yum install jemalloc-devel
- 3
gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 錯誤 127
make[3]: 離開目錄“/root/redis-2.8.19/deps/hiredis”
make[2]: *** [hiredis] 錯誤 2
make[2]: 離開目錄“/root/redis-2.8.19/deps”
make[1]: [persist-settings] 錯誤 2 (忽略)
CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 錯誤 127
make[1]: 離開目錄“/root/redis-2.8.19/src”
make: *** [all] 錯誤 2
解決辦法 yum install gcc