本文來源 https://blog.csdn.net/qq_20989105/article/details/76390367 ,轉載前請先聯繫原作者並聲明出處。 一、安裝gcc 1、Redis在linux上的安裝首先必須先安裝gcc,這個是用來編譯redis的源文件的。首先需要先切換的到root用 ...
本文來源 https://blog.csdn.net/qq_20989105/article/details/76390367 ,轉載前請先聯繫原作者並聲明出處。
一、安裝gcc
1、Redis在linux上的安裝首先必須先安裝gcc,這個是用來編譯redis的源文件的。首先需要先切換的到root用戶:
[cheny@localhost ~]$ su
Password:
[root@localhost cheny]#
2、然後開始安裝gcc:
[root@localhost /]# yum install gcc-c++
//這個命令是線上安裝的,所以在這之前你的VM必須能夠上網,需要在 VM中把網卡設置成NAT模式 ,因為我使用的是centos,在網路設置中需要把網卡開啟,反正我在裝完系統之後它是預設關閉的
3、之後便會出現下載文件界面:
4、會出現2次確認界面,輸入y即可
5、之後會進行更新檢查,進行更新驗證等等操作,等他自動完成即可。
6、出現如下代碼即是安裝成功:
Installed:
gcc-c++.x86_64 0:4.8.5-11.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-11.el7
gcc.x86_64 0:4.8.5-11.el7
glibc-devel.x86_64 0:2.17-157.el7_3.5
glibc-headers.x86_64 0:2.17-157.el7_3.5
kernel-headers.x86_64 0:3.10.0-514.26.2.el7
libmpc.x86_64 0:1.0.1-3.el7
libstdc++-devel.x86_64 0:4.8.5-11.el7
Dependency Updated:
glibc.x86_64 0:2.17-157.el7_3.5
glibc-common.x86_64 0:2.17-157.el7_3.5
Complete!
二、解壓redis的源文件
[root@localhost cheny]# cd Desktop/
[root@localhost Desktop]# ls
redis-4.0.1.tar.gz
[root@localhost Desktop]# tar zxvf redis-4.0.1.tar.gz
redis-4.0.1/
redis-4.0.1/.gitignore
redis-4.0.1/00-RELEASENOTES
redis-4.0.1/BUGS
redis-4.0.1/CONTRIBUTING
.......等等
三、進入redis的解壓目錄
[root@localhost Desktop]# ls
redis-4.0.1 redis-4.0.1.tar.gz
[root@localhost Desktop]# cd redis-4.0.1/
四、使用make命令編譯
[root@localhost redis-4.0.1]# make
//
出現以下信息即是編譯成功
CC notify.o
CC setproctitle.o
CC blocked.o
CC hyperloglog.o
CC latency.o
CC sparkline.o
CC redis-check-rdb.o
CC redis-check-aof.o
CC geo.o
CC lazyfree.o
CC module.o
CC evict.o
CC expire.o
CC geohash.o
CC geohash_helper.o
CC childinfo.o
CC defrag.o
CC siphash.o
CC rax.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
五、進入解壓的src目錄下
[root@localhost redis-4.0.1]# cd src
六、
1、運行make test測試是否可以安裝
[root@localhost src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
2、在這裡發現有錯誤
TCL(Tool Command Language)工具腳本語言,是Linux內的一種語言包。,這裡需要先安裝tcl。
1、先下載TCL:
linux 安裝redis need tcl 8.5 or newer
- wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz //直接下載
2. sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
3. cd /usr/local/tcl8.6.1/unix/
4. sudo ./configure
5. sudo make
6. sudo make install
這個時候在命令行就可以輸入tclsh進入tcl解釋器
tcl就可以使用了。
繼續redis安裝
3、再次測試make test
這裡反正檢查的一大堆,都是綠色的ok。這就可以了
4、安裝
[root@localhost src]# make PREFIX=/usr/local/redis install
安裝成功!
框框中標出的都是一個個工具命令
七、把解壓的redis路徑下的redis.conf文件拷貝到安裝路徑下麵
[root@localhost Desktop]# cd redis-4.0.1/
[root@localhost redis-4.0.1]# ls
00-RELEASENOTES INSTALL runtest tests
BUGS Makefile runtest-cluster utils
CONTRIBUTING MANIFESTO runtest-sentinel
COPYING README.md sentinel.conf
deps redis.conf src
[root@localhost redis-4.0.1]# cp redis.conf /usr/local/redis
[root@localhost redis-4.0.1]# cd /usr/local/redis
[root@localhost redis]# ls
bin redis.conf
到這裡redis已經安裝成功了。
八、啟動redis
第一種方法:進入安裝路徑下的bin
[root@localhost redis]# cd bin
[root@localhost bin]# ./redis-server
這樣其實已經啟動成功了,但是這屬於前端啟動,啟動redis之後,我們的控制台就不能進行任何操作了。只能ctrl+c停止啟動。
第二種方法:
後端啟動
1、首先編輯redis.conf
[root@localhost redis]# vim redis.conf
- 1
2、找到daemonize no將其改為yes(在vim中插入數據按鍵盤上的i或者insert)
效果如下:
3、按esc退出insert模式,再按:,並且輸入wq。代表保存並且退出
4、再次啟動
[root@localhost redis]# ls
bin redis.conf
[root@localhost redis]# ./bin/redis-server ./redis.conf
//這裡載入配置文件
80167:C 30 Jul 16:01:58.145 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
80167:C 30 Jul 16:01:58.145 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=80167, just started
80167:C 30 Jul 16:01:58.145 # Configuration loaded
這樣redis就啟動了
可以通過
ps -ef | grep -i redis
來查看是否啟動
5、關閉redis
[root@localhost redis]# ./bin/redis-cli shutdown
九、簡單的使用
//首先鏈接客戶端
[root@localhost redis]# ./bin/redis-cli
//檢查網路是否可以
127.0.0.1:6379> ping
PONG
//設置一個鍵值對
127.0.0.1:6379> set name cheny
OK
//獲取剛剛設置的鍵值對
127.0.0.1:6379> get name
"cheny"
//查看所有的鍵
127.0.0.1:6379> keys *
1) "name"
//刪除name這個鍵
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>
-------------------------------END---------------------------------
非常感謝原作者,讓我少走了不少彎路。。。