Linux 下安装redis
?
記錄一下linux下的安裝步驟,還是比較復雜的
?
1. 下載redis-2.8.19.tar.gz:
ftp傳到linux01上;
解壓:
tar –zxvf redis-2.8.19.tar.gz
2. 安裝相關軟件
命令: yum install wget? make gcc gcc-c++?
3.安裝后在redis-2.8.19目錄src下make,應該會出現以下錯誤
原因分析
在README 有這個一段話。
Allocator ?
--------- ?
?
Selecting a non-default memory allocator when building Redis is done by setting ?
the `MALLOC` environment variable. Redis is compiled and linked against libc ?
malloc by default, with the exception of jemalloc being the default on Linux ?
systems. This default was picked because jemalloc has proven to have fewer ?
fragmentation problems than libc malloc. ?
?
To force compiling against libc malloc, use: ?
?
??? % make MALLOC=libc ?
?
To compile against jemalloc on Mac OS X systems, use: ?
?
??? % make MALLOC=jemalloc
說關于分配器allocator, 如果有MALLOC ?這個 環境變量, 會有用這個環境變量的 去建立Redis。
而且libc 并不是默認的 分配器, 默認的是 jemalloc, 因為 jemalloc 被證明 有更少的?fragmentation problems 比libc。
但是如果你又沒有jemalloc 而只有 libc 當然 make 出錯。 所以加這么一個參數。
?
解決辦法
make MALLOC=libc
繼續在src,make
可能報錯:
?
繼續解決:
1、jemalloc下可能要先運行./configure,然后make (我沒有運行這一步,可能有的需要這一步,視情況而定)
2、分別進入redis下的deps下的hiredis、lua 運行make
3、回到src目錄運行 make ? make test
? 可能會出現以下錯誤:
解決辦法:
安裝tcl命令:?yum -y install tcl?
4. ?繼續進入redis目錄src下make 和make test
5. ?使用Redis命令行:
redis/src目錄下: ??make install 和 make test
, 進入?/usr/local/bin/目錄下查看 ls,出現下圖,就安裝成功了!
?
?
?6,配置啟動服務
1)、編輯redis.conf文件
命令: ?vi redis.conf
2)、修改daemonize no改成yes。
3)、我們手動復制redis.conf到/etc目錄下
命令: ?cp redis.conf /etc
4). 進入/etc/init.d目錄下 創建redisd文件,貼入以下內容
vim redisd
########################### #chkconfig: 2345 10 90 #description: Start and Stop redis PATH=/usr/local/bin:/sbin:/usr/bin:/binREDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cliPIDFILE=/var/run/redis.pid CONF="/etc/redis.conf"case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Redis server..."$EXEC $CONFfiif [ "$?"="0" ] thenecho "Redis is running..."fi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$REDIS_CLI -p $REDISPORT SHUTDOWNwhile [ -x ${PIDFILE} ]doecho "Waiting for Redis to shutdown ..."sleep 1doneecho "Redis stopped"fi;;restart|force-reload)${0} stop${0} start;;*)echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2exit 1 esac ##############################
修改權限,可以運行
? 命令: ?chmod +x /etc/init.d/redis? // u可以省略
設置開機自動啟動服務
命令: ?chkconfig redisd on ?//開自啟動
service redis start ? ? //啟動
service redis stop //關閉服務
? 到此配置linux下的redis算是基本完成了,外網連接需要關閉防火墻
測試redis
service redis start? 測試命令: ? redis-benchmark -n 10000 -c 60 ? 向redis服務器發送100000個請求,每個請求附帶60個并發客戶端
客戶端連接
在redis解壓目錄的src目錄下 ./redis –cli –p 6379 |? ./redis-cli (進入默認的redis客戶端)
?
?
ok,完成!
?
轉載于:https://www.cnblogs.com/xujingyang/p/7076956.html
總結
以上是生活随笔為你收集整理的Linux 下安装redis的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【bzoj 2002】弹飞绵羊
- 下一篇: Asp.Net Core 缓存的使用(译