linux下安裝redis的詳細過程


先安裝一些組件:

yum -y install gcc gcc-c++ libstdc++-devel

下載並安裝:

# wget http://download.redis.io/releases/redis-2.8.19.tar.gz
# tar xzf redis-2.8.19.tar.gz
# cd redis-2.8.19
# make && make install

如果有報錯信息:

錯誤1:

[root@localhost redis-2.8.19]# make && make install
cd src && make all
make[1]: Entering directory `/data/software/redis-2.8.19/src'
    CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data/software/redis-2.8.19/src'
make: *** [all] Error 2

解決方法:

# make MALLOC=libc
# make && make install

錯誤2:

[3116] 21 Jan 15:19:46.366 # Server started, Redis version 2.8.19
[3116] 21 Jan 15:19:46.366 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

根據提示可以編輯 /etc/sysctl.conf 文件,在文件底部添加如下內容:
vm.overcommit_memory = 1

然后執行 /sbin/sysctl vm.overcommit_memory=1,使之生效。

可以通過 /sbin/sysctl -p 來查看是否添加成功!

錯誤3:

[3590] 21 Jan 15:47:14.324 # Server started, Redis version 2.8.19
[3590] 21 Jan 15:47:14.324 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[3590] 21 Jan 15:47:14.324 * DB loaded from disk: 0.000 seconds
[3590] 21 Jan 15:47:14.324 * The server is now ready to accept connections on port 6379

限制了接收新 TCP 連接偵聽隊列的大小。對於一個經常處理新連接的高負載 web服務環境來說,默認的 128 太小了。大多數環境這個值建議增加到 1024 或者更多。
服務進程會自己限制偵聽隊列的大小(例如 sendmail(8) 或者 Apache),常常在它們的配置文件中有設置隊列大小的選項。大的偵聽隊列對防止拒絕服務 DoS 攻擊也會有所幫助。
我們可以通過來修改這個參數。

解決方法:

# echo 1000 > /proc/sys/net/core/somaxconn

錯誤4:

[3234] 06 May 02:46:22.059 # Server started, Redis version 2.8.19
[3234] 06 May 02:46:22.059 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[3234] 06 May 02:46:22.059 * DB loaded from disk: 0.000 seconds
[3234] 06 May 02:46:22.059 * The server is now ready to accept connections on port 6379

解決方法:

# echo never > /sys/kernel/mm/transparent_hugepage/enabled

 

啟動redis:

# redis-server /data/redis/redis.conf

測試設置:

# redis-cli
127.0.0.1:6379> set name redisdev
OK
127.0.0.1:6379> get name
"redisdev"

關閉redis:

# redis-cli shutdown

加入服務,並開機自啟動:

# vim /etc/init.d/redis

添加以下腳本:

# chkconfig: 2345 90 10
# description: service of redis for start and stop add by tomener

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/data/redis/redis.conf"
AUTH="1234"

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
                if [ "$?"="0" ]
                then
                        echo "Redis is running..."
                fi
                ;;
        stop)
                if [ ! -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is not running."
                else
                        PID=$(cat $PIDFILE)
                        echo "Stopping..."
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN
                        sleep 2
                       while [ -x $PIDFILE ]
                       do
                                echo "Waiting for Redis to shutdown..."
                               sleep 1
                        done
                        echo "Redis stopped"
                fi
                ;;
        restart|force-reload)
        ${0} stop
                ${0} start
                ;;
        *)
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
                exit 1
esac
# chmod 0755 /etc/init.d/redis
# /etc/init.d/redis start
# chkconfig --add redis
# chkconfig --level 235 redis on

#使用該命令能愉快的玩耍了 # service redis start
|stop|restart

 

到此安裝完成。那么您肯定會用到命令,附詳細的命令大全。我也拿來參考用,防長時間忘記。

http://www.cnblogs.com/xsi640/p/3755133.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM