溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

linux下redis安裝

發(fā)布時間:2020-08-01 19:32:29 來源:網(wǎng)絡(luò) 閱讀:4048 作者:M_ling 欄目:數(shù)據(jù)庫

安裝環(huán)境:

linux:centos6.9 64位

redis版本:redis-4.0.2.tar.gz


Redis安裝

redis官網(wǎng)地址:http://www.redis.io/

目前最新版本是4.0.2

1、下載源碼,解壓后編譯源碼

[root@localhost ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz

[root@localhost ~]# tar -xfredis-4.0.2.tar.gz

[root@localhost ~]# cd redis-4.0.2

[root@localhost redis-4.0.2]# make? 編譯

2、make編譯完成后,我們看到如下界面,說明我們安裝成功了。

linux下redis安裝

????我們在redis-4.0.2/src目錄下會看到多了幾個可執(zhí)行文件,其中redis-server是用來啟動服務(wù)用的,redis-cli是用來啟動客戶端用的,其他的還不清楚,大家可以查一下。

????默認(rèn)make完后,我們啟動redis服務(wù)的話,每次都要進(jìn)入到安裝目錄,這樣很繁瑣,所以我們可以make之后在執(zhí)行make install,就會把生成的二進(jìn)制文件放到/usr/local/bin目錄

make install

linux下redis安裝

1、make install? 會在/usr/local/bin路徑下生成文件(我運(yùn)行的這個) ,redis 可執(zhí)行文件將被復(fù)制到/usr/local/bin/

2、make PREFIX=/opt/redis install? 指定安裝目錄,會在/opt/redis下生成一個bin路徑,下面是可執(zhí)行文件?

注:如果是普通用戶執(zhí)行make install是需要需要root權(quán)限的,要用sudo make install


3、設(shè)置服務(wù)

首先將redis-4.0.2/utils/redis_init_script文件復(fù)制到/etc/init.d下,同時易名為redis。執(zhí)行命令

cp?redis-4.0.2/utils/redis_init_script??/etc/init.d/redis

vi?/etc/rc.d/init.d/redis

在文檔第二行添加

# chkconfig: 234580 90。

確保/usr/local/redis/bin中有redis-server和redis-cli文件(如果有些人安裝是沒有用make install命令,是需要在安裝目錄下復(fù)制redis-server和redis-cli到/usr/local/redis/bin目錄下,否則服務(wù)啟動時找不到redis-server)下圖第二個紅框所示。

linux下redis安裝

可以看到在/etc/init.d/redis文件中有這么一行:CONF="/etc/redis/${REDISPORT}.conf"。于是將redis配置文件拷貝到/etc/redis/下,同時易名為7200.conf。

mkdir?/etc/redis
cp?redis-4.0.2/redis.conf?/etc/redis/7200.conf


拷貝redis.conf到安裝目錄
cp?redis.conf?/opt/redis

注:CONF="/etc/redis/${REDISPORT}.conf"?這里就需要修改成你的安裝路徑的配置文件


4、修改7200.conf配置文件

#?指定redis運(yùn)行的端口,默認(rèn)是6379
port?7200
#daemonize?no?默認(rèn)情況下,redis不是在后臺運(yùn)行的,如果需要在后臺運(yùn)行,把該項(xiàng)的值更改為yes
daemonize?yes
?
#?當(dāng)redis在后臺運(yùn)行的時候,Redis默認(rèn)會把pid文件放在/var/run/redis.pid,你可以配置到其他地址。
#?當(dāng)運(yùn)行多個redis服務(wù)時,需要指定不同的pid文件和端口
#pidfile?/var/run/redis_6379.pid
?
pidfile?/var/run/redis_7200.pid?
?
#?指定redis只接收來自于該IP地址的請求,如果不進(jìn)行設(shè)置,那么將處理所有請求,
#?在生產(chǎn)環(huán)境中最好設(shè)置該項(xiàng)
#?bind?127.0.0.1
#?設(shè)置客戶端連接時的超時時間,單位為秒。當(dāng)客戶端在這段時間內(nèi)沒有發(fā)出任何指令,那么關(guān)閉該連接
#?0是關(guān)閉此設(shè)置
timeout?0
?
#?指定日志記錄級別
#?Redis總共支持四個級別:debug、verbose、notice、warning,默認(rèn)為verbose
#?debug????????記錄很多信息,用于開發(fā)和測試
#?varbose??????有用的信息,不像debug會記錄那么多
#?notice??普通的verbose,常用于生產(chǎn)環(huán)境
#?warning??????只有非常重要或者嚴(yán)重的信息會記錄到日志
loglevel?debug
?
#?配置log文件地址
#?默認(rèn)值為stdout,標(biāo)準(zhǔn)輸出,若后臺模式會輸出到/dev/null
#修改生成默認(rèn)日志文件位置
#logfile?""
logfile?"/var/log/redis/redis.log"

#配置持久化文件存放位置
dir?/opt/data/redisData


5、后臺啟動兩種方法

默認(rèn)redis啟動服務(wù)會獨(dú)占輸入屏,若想在后臺啟動有兩種方式:

a、在/etc/init.d/redis中找到$EXEC?$CONF?后邊加一個&,表示讓redis作為后臺服務(wù)啟動

b、修改redis的配置文件?.conf(/etc/redis/7200.conf)將#daemonize?no些選項(xiàng)是配置前臺還是后臺
啟動的,如果后臺啟動設(shè)置為yes)


6、加入service服務(wù)管理

完成上面的操作之后,即可注冊服務(wù):

chkconfig?--add?redis

然后啟動redis服務(wù)

service?redis?start

linux下redis安裝

這樣我們就將redis服務(wù)注冊好了。


如果service redis stop ,有提示/var/run/redis_7200.pid does not exist, process is not running

linux下redis安裝

這說明在run下沒有這個文件,我們進(jìn)入到/var/run下發(fā)先真的沒有這個文件,但是有redis.pid文件。

解決方法:

a、將/etc/rc.d/init.d/redis文件中的redis_${REDISPORT}.pid修改為redis.pid

b、修改7200.conf配置文件里面的pidfile?/var/run/redis.pid為pidfile?/var/run/redis_7200.pid,
刪除之前生成pid,重新啟動就會生成redis_7200.pid文件了。

這樣我們重啟服務(wù)后,在用該命令關(guān)閉就可以了。到這里我們的redis服務(wù)就安裝好了,并做好了一個服務(wù)。

以上就是Linux下安裝Redis的全過程,希望對大家安裝Redis有所幫助。


附redis啟動腳本:

#!/bin/sh
#?chkconfig:?2345?80?90
#
#?Simple?Redis?init.d?script?conceived?to?work?on?Linux?systems
#?as?it?does?use?of?the?/proc?filesystem.

REDISPORT=7200
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI