1. 程式人生 > >redis(1)——Ubuntu下安裝redis

redis(1)——Ubuntu下安裝redis

redis安裝

1、首先需要安裝gcc,一般Ubuntu系統都已經提前安裝好了

sudo apt-get install gcc

2、把下載好的redis-3.2.11.tar放到 /usr/local 資料夾下

3、進行解壓 tar -zxvf redis-3.2.11.tar

4、進入到redis-3.2.11目錄下,進行編譯 make,這個地方需要使用sudo指令,不然會報錯。

cd src && make all

touch: cannot touch ‘release.h’: Permissiondenied

cat: release.h: No such file or directory

./mkreleasehdr.sh: 8: ./mkreleasehdr.sh:cannot create release.h: Permission denied

./mkreleasehdr.sh: 9: ./mkreleasehdr.sh:cannot create release.h: Permission denied

./mkreleasehdr.sh: 10: ./mkreleasehdr.sh:cannot create release.h: Permission denied

touch: cannot touch ‘release.c’: Permissiondenied

make[1]: Entering directory`/usr/local/redis-3.2.11/src'

rm -rf redis-server redis-sentinelredis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno*.gcov redis.info lcov-html

(cd ../deps && make distclean)

make[2]: Entering directory`/usr/local/redis-3.2.11/deps'

(cd hiredis && make clean) >/dev/null || true

(cd linenoise && make clean) >/dev/null || true

(cd lua && make clean) >/dev/null || true

(cd geohash-int && make clean) >/dev/null || true

(cd jemalloc && [ -f Makefile ]&& make distclean) > /dev/null || true

(rm -f .make-*)

make[2]: Leaving directory`/usr/local/redis-3.2.11/deps'

(rm -f .make-*)

echo STD=-std=c99 -pedantic-DREDIS_STATIC='' >> .make-settings

/bin/sh: 1: cannot create .make-settings:Permission denied

make[1]: *** [persist-settings] Error 2

make[1]: Leaving directory`/usr/local/redis-3.2.11/src'

make: *** [all] Error 2

5、進入到src下繼續安裝 make install ,驗證(檢視src下的目錄,有redis-server、redis-cil)

Hint: It's a good idea to run 'make test';)

    INSTALL install

install: cannot remove‘/usr/local/bin/redis-server’: Permission denied

make: *** [install] Error 1

 6、建立兩個問價夾存放redis命令和配置檔案

sudo mkdir -p /usr/local/redis/etc

sudo mkdir -p /usr/local/redis/bin

6、把redis-3.2.11下的redis.conf 移動到 /usr/local/redis/etc下

sudo cp redis.conf /usr/local/redis/etc/

7、把redis-3.2.11/src裡的mkreleasehdr.sh、redis-benchmark、redis-check-aof、redis-check-rdb、redis-cli、redis-server檔案移動到bin下,命令:

sudo mv mkreleasehdr.sh redis-benchmarkredis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin

redis-server:Redis伺服器

redis-cli:Redis命令列客戶端

redis-check-aof:AOF檔案修復工具

redis-check-rdb:RDB檔案檢測工具,3.0.0版本之前為redis-check-dump

Redis.conf:資料庫配置檔案

8、啟動時並制定配置檔案:usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf(注意要使用後臺啟動)

6617:signal-handler (1507899314) ReceivedSIGINT scheduling shutdown...

6617:M 13 Oct 05:55:14.492 # User requestedshutdown...

6617:M 13 Oct 05:55:14.492 * Saving thefinal RDB snapshot before exiting.

6617:M 13 Oct 05:55:14.492 # Failed openingthe RDB file dump.rdb (in server root dir /usr/local/redis/bin) for saving:Permission denied

6617:M 13 Oct 05:55:14.492 # Error tryingto save the DB, can't exit.

6617:M 13 Oct 05:55:14.492 # SIGTERMreceived but errors trying to shut down the server, check the logs for moreinformation

啟動停止不了,需要修改usr/local/redis資料夾許可權

sudo chmod 777 -R redis

9、修改redis.conf配置檔案

1) 設定為後臺啟動:

修改daemonize為yes

2)設定日誌檔案、資料檔案的儲存目錄:

修改dir ./為dir/usr/local/redis/etc

10、驗證啟動是否成功

ps -ef|grep redis 檢視是否有redis服務或者檢視介面:metstat -tunpl | grep 6379

進入redis客戶端bin/redis-cli 退出客戶端quit

退出redis服務有以下幾種方式:

pkill redis-server

kill程序號

/user/local/redis/bin/redis-cli shutdown