redis安裝

jopen 10年前發布 | 25K 次閱讀 Redis NoSQL數據庫

安裝準備:redis2.8.7,redhat

只供參考

1.解壓


[root@dell1 soft]# tar -xzvf redis-2.8.7.tar.gz

2.進入解壓后的目錄,直接執行make命令


[root@dell1 soft]# cd redis-2.8.7
[root@dell1 redis-2.8.7]# pwd
/home/soft/redis-2.8.7
[root@dell1 redis-2.8.7]# make

 

3.執行make test

執行成功make命令后,會提示執行make test,如果沒有安裝tcl,則會報錯
報錯,提示沒有You need 'tclsh8.5' in order to run the Redis test,
所以接下來應該安裝tcl,這個不清楚是什么東西。下載tcl8.6.1
#cd tcl8.6.1/unix/
#./configure
#make
#make test
#make install
這樣應該完成安裝完tcl了

 

4.回到redis的安裝目錄重新執行make test


\o/ All tests passed without errors!
make test執行成功

Cleanup: may take some time... OK
make[1]: Leaving directory `/home/soft/redis-2.8.7/src'

 

5.執行make install


[root@dell1 redis-2.8.7]# make install

 

6.執行install_server.sh文件


[root@dell1 redis-2.8.7]# cd utils/
[root@dell1 utils]# ls
build-static-symbols.tcl  redis-copy.rb          speed-regression.tcl
generate-command-help.rb  redis_init_script      whatisdoing.sh
install_server.sh         redis_init_script.tpl
mkrelease.sh              redis-sha1.rb
[root@dell1 utils]# ./install_server.sh

Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
./install_server.sh: line 178: update-rc.d: command not found
exists, process is already running or crashed
Installation successful!

執行完成。這里使用了默認配置

 

7.啟動redis服務


[root@dell1 utils]# cd /usr/local/bin
[root@dell1 bin]# ls
event_rpcgen.py  memcached-debug  redis-check-aof   redis-cli     tclsh8.6
memcached        redis-benchmark  redis-check-dump  redis-server
[root@dell1 bin]# ./redis-server /etc/redis/6379.conf

8.查看服務是否啟動


[root@dell1 bin]# ps -ef | grep 6379
root      3206     1  0 13:06 ?        00:00:00 /usr/local/bin/redis-server *:6379             
root      7996  3294  0 13:45 pts/0    00:00:00 grep 6379

 

9.修改redis啟動文件


在init.d下有一個默認文件redis_6379,打開文件,修改后如下


#/bin/sh\n
#Configurations injected by install_server below....
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/etc/redis/6379.conf"
REDISPORT="6379"

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


保存退出

 

10更改redis_6379的名字


[root@dell1 init.d]# mv redis_6379 redis

 

11.剛才已經啟動服務,現在使用service關閉服務,開啟服務


[root@dell1 bin]# service redis stop
Stopping ...
Redis stopped
[root@dell1 bin]# service redis start
Starting Redis server...

 

12.使用redis-cli登錄


[root@dell1 bin]# cd /usr/local/bin
[root@dell1 bin]# ls
event_rpcgen.py  memcached-debug  redis-check-aof   redis-cli     tclsh8.6
memcached        redis-benchmark  redis-check-dump  redis-server
[root@dell1 bin]# ./redis-cli
127.0.0.1:6379> set key 122
OK
127.0.0.1:6379> get key
"122"
127.0.0.1:6379> exists key
(integer) 1

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!