2019-04-17 在Ubuntu1804 上安裝Redis


redis官網(wǎng):https://redis.io/。 redis的Github:github.com/antirez/redis。


前置:

make-guile
make
gcc


下載和解壓

#下載源碼,復(fù)制官網(wǎng)上的下載鏈接
wget http://59.80.44.48/download.redis.io/releases/redis-5.0.4.tar.gz

#解壓
tar -zxvf redis-5.0.4.tar.gz

編譯和安裝:

注意看Github上的README,其中有這樣一段話:

Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems.

意譯:默認(rèn)情況下,redis是針對libc malloc編譯和鏈接的,但在Linux系統(tǒng)上,默認(rèn)指向jemalloc。(選擇此默認(rèn)值是因為jemalloc已證明比libc malloc具有更少的碎片問題)。

我的Ubuntu只有libc分配器,所以需要強(qiáng)制libc malloc編譯:

#如果希望安裝在其他地方,則可以使用 make PREFIX=/some/other/directory install
make install MALLOC=libc

初始化配置

make install只會在系統(tǒng)中安裝二進(jìn)制文件,但不會在適當(dāng)?shù)奈恢门渲胕nit腳本和配置文件。
如果你正在為生產(chǎn)系統(tǒng)安裝redis,有一個腳本為Ubuntu和Debian系統(tǒng)執(zhí)行此配置操作:

cd utils
./install_server.sh

該腳本將向你提出幾個問題,并將設(shè)置你正確運行Redis作為后臺守護(hù)程序所需的一切,該守護(hù)程序?qū)⒃谙到y(tǒng)重新啟動時重新啟動。

# ./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] redis5.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]
Selected config:
Port           : 6379
Config file    : redis5.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Success!
Starting Redis server...
Installation successful!

完成后會生成一個配置文件,這個配置文件在utils目錄下:

redis端口(Port)  :6379
Config file    : /root/redis-5.0.4/utils/redis5.conf
Log file       : /var/log/redis_6379.log
數(shù)據(jù)目錄       : /var/lib/redis/6379
可執(zhí)行文件     : /usr/local/bin/redis-server
Cli 可執(zhí)行文件 : /usr/local/bin/redis-cli

你可以使用名為/etc/init.d/redis_u<portnumber>的腳本來停止和啟動redis,例如/etc/init.d/redis_6379

這里我把配置文件復(fù)制出來,然后改一下/etc/init.d/redis_6379文件,方便啟動(后端啟動方式):
CONF="redis5.conf"中的redis5.conf改成指定路徑(也可以不復(fù)制文件,直接指定配置文件的路徑)。

mkdir /usr/local/conf/
cp /root/redis-5.0.4/utils/redis5.conf /usr/local/conf/
sudo vi /etc/init.d/redis_6379 #把CONF="redis5.conf"中的redis5.conf改為/usr/local/conf/redis5.conf

這樣就可以使用腳本控制redis的啟動狀態(tài)了:

/etc/init.d/redis_6379 start       #啟動redis
/etc/init.d/redis_6379 stop       #停止redis
/etc/init.d/redis_6379 restart    #重啟redis

其他


前端啟動:redis-server
后端啟動:redis-server 配置文件路徑


參考文獻(xiàn):
[1] Salvatore Sanfilippo.Github - antirez/redis[EB/OL].[2019-4-17].https://github.com/antirez/redis.
[2] 過路人士甲.CentOS之Redis安裝[EB/OL].[2019-4-17].https://jingyan.baidu.com/article/36d6ed1fabe64b1bcf4883a4.html.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容