注意:本文系統(tǒng)環(huán)境 CentOS 7.7 64位
官網(wǎng):https://redis.io/download 下載穩(wěn)定版本
本文以--- redis-4.0.8.tar.gz ---為例
新建目錄 mkdir /usr/local/redis/
長傳文件 /usr/local/redis/
解壓
tar xzf redis-4.0.8.tar.gz
指令
gcc -v
如果沒有則不顯示
1.離線安裝
1.1獲取相關(guān)rpm包,將其存放到服務(wù)器上某一路徑 (網(wǎng)址: http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/)
1.2 安裝rpm包。在rpm目錄下執(zhí)行指令
rpm -Uvh *.rpm --nodeps --force
2.在線安裝, 指令如下
yum install gcc-c++
3.檢測安裝是否成功, 指令如下
gcc -v
1.進(jìn)入剛解壓的redis目錄, 輸入指令
[root@localhost redis-4.0.8]# make && make install
2.拷貝配置文件/usr/local/redis/redis-4.0.8/utils/redis_init_script到/etc/init.d, 目的:設(shè)置開機(jī)自啟
[root@localhost utils]# cp redis_init_script /etc/init.d/
3.拷貝配置文件/usr/local/redis/redis-4.0.8/redis.conf 到 /usr/local/redis/
[root@localhost redis-4.0.8]# cp redis.conf /usr/local/redis/
4.修改/usr/local/redis/redis.conf 配置文件
4.1 修改綁定IP改為 0.0.0.0 ,目的可以遠(yuǎn)程連接,不受ip限制
4.2修改 daemonize no -> daemonize yes,目的讓redis在linux后臺(tái)運(yùn)行
4.3修改redis工作目錄(查看日志等信息) dir /usr/local/redis/working
4.4修改密碼,默認(rèn)無密碼 requirepass 123456
5.重命名/usr/local/redis/redis.conf 為 6379.conf
[root@localhost redis]# mv redis.conf 6379.conf
6.修改/etc/init.d/redis_init_script 指定對(duì)應(yīng)的conf設(shè)置 CONF="/usr/local/redis/${REDISPORT}.conf"
7.為redis啟動(dòng)腳本添加執(zhí)行權(quán)限,隨后運(yùn)行啟動(dòng)redis:
配置權(quán)限:
[root@localhost init.d]# chmod 777 redis_init_script
啟動(dòng)redis:
[root@localhost init.d]# ./redis_init_script start
8.檢測redis
[root@localhost init.d]# ps -ef | grep redis
9.最后一步設(shè)置linux開機(jī)自啟 etc/init.d/redis_init_script
9.1添加新內(nèi)容
redis服務(wù)必須在運(yùn)行級(jí)2,3,4,5下被啟動(dòng)或關(guān)閉,啟動(dòng)的優(yōu)先級(jí)是90,關(guān)閉的優(yōu)先級(jí)是10。
#chkconfig: 22345 10 90
#description: Start and Stop redis
9.2 執(zhí)行配套命令以讓腳本每次開機(jī)都執(zhí)行
【chkconfig --add redis_init_script】 //服務(wù)的形式啟動(dòng)和關(guān)閉redis
【chkconfig redis_init_script on】 //加入開機(jī)自啟服務(wù)
例如:【service redisd start】 啟動(dòng)redis
【chkconfig --list】 //查看所有注冊的腳本文件
操作過程:
[root@localhost init.d]# chkconfig --add redis_init_script
[root@localhost init.d]# chkconfig redis_init_script on
[root@localhost init.d]# chkconfig --list
注:該輸出結(jié)果只顯示 SysV 服務(wù),并不包含
原生 systemd 服務(wù)。SysV 配置數(shù)據(jù)
可能被原生 systemd 配置覆蓋。
要列出 systemd 服務(wù),請執(zhí)行 'systemctl list-unit-files'。
查看在具體 target 啟用的服務(wù)請執(zhí)行
'systemctl list-dependencies [target]'。
jexec 0:關(guān) 1:開 2:開 3:開 4:開 5:開 6:關(guān)
netconsole 0:關(guān) 1:關(guān) 2:關(guān) 3:關(guān) 4:關(guān) 5:關(guān) 6:關(guān)
network 0:關(guān) 1:關(guān) 2:開 3:開 4:開 5:開 6:關(guān)
redis_init_script 0:關(guān) 1:關(guān) 2:開 3:開 4:開 5:開 6:關(guān)
10.可以重啟測試是否成功
指令 reboot
linux 運(yùn)行級(jí)別含義:
運(yùn)行級(jí)別就是操作系統(tǒng)當(dāng)前正在運(yùn)行的功能級(jí)別。這個(gè)級(jí)別從0到6 ,具有不同的功能。這些級(jí)別在/etc/inittab文件里指定。這個(gè)文件是init程序?qū)ふ业闹饕募?,最先運(yùn)行的服務(wù)是那些放在/etc/rc.d 目錄下的文件。
不同的運(yùn)行級(jí)定義如下:(可以參考Linux里面的/etc/inittab)
# 缺省的運(yùn)行級(jí),RHS用到的級(jí)別如下:
0:關(guān)機(jī)
1:單用戶模式
2:無網(wǎng)絡(luò)支持的多用戶模式
3:有網(wǎng)絡(luò)支持的多用戶模式
4:保留,未使用
5:有網(wǎng)絡(luò)支持有X-Window支持的多用戶模式
6:重新引導(dǎo)系統(tǒng),即重啟
通俗的解釋:
0 為停機(jī),機(jī)器關(guān)閉。
1 為單用戶模式,就像Win9x下的安全模式類似。
2 為多用戶模式,但是沒有NFS支持。
3 為完整的多用戶模式,是標(biāo)準(zhǔn)的運(yùn)行級(jí)。
4 一般不用,在一些特殊情況下可以用它來做一些事情。
例如在筆記本 電腦的電池用盡時(shí),可以切換到這個(gè)模式來做一些設(shè)置。
5 就是X11,進(jìn)到X Window系統(tǒng)了。
6 為重啟,運(yùn)行init 6機(jī)器就會(huì)重啟。
聯(lián)系客服