redis2.8安装

2020-05-19  本文已影响0人  a50426d44eac

操作系统和redis安装包版本

CentOS Linux release 7.4.1708 (Core)

redis-2.8.19.tar.gz

操作系统配置

关闭大页
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 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源,版本会比官方的包更新,而且还有一些官方没有的包,比如jemalloc-devel。

redis解压安装

tar -zxvf redis-2.8.19.tar.gz
cd redis-2.8.19
make
cd src
make install

默认安装在/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

创建配置文件,目录并且做成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文件里相关的配置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

常见安装错误

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

[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

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

上一篇下一篇

猜你喜欢

热点阅读