CentOS 6.5 64位下安裝Redis3.0.2的具體步驟
系統(tǒng)環(huán)境:CentOS 6.5 64位
安裝方式:編譯安裝
防火墻:開(kāi)啟
Redis版本:Redis 3.0.2
一、環(huán)境準(zhǔn)備
1、安裝 gcc gcc-c++
[root@iZ94ebgv853Z ~]# yum install gcc gcc-c++ -y
2、下載redis-3.0.2.tar.gz
[root@iZ94ebgv853Z ~]# wget http://download.redis.io/releases/redis-3.0.2.tar.gz
二、安裝Redis
[root@iZ94ebgv853Z ~]# tar xf redis-3.0.2.tar.gz #解壓 [root@iZ94ebgv853Z ~]# cd redis-3.0.2 [root@iZ94ebgv853Z redis-3.0.2]# make [root@iZ94ebgv853Z redis-3.0.2]# make test
報(bào)錯(cuò)如下:
cd src&& make test
make[1]:Entering directory `/root/redis-3.0.2/src'
You needtcl 8.5 or newer in order to run the Redis test
make[1]:*** [test] Error 1
make[1]:Leaving directory `/root/redis-3.0.2/src'
make: *** [test] Error 2
原因:需要安裝tcl
[root@iZ94ebgv853Zredis-3.0.2]# yum install tcl –y [root@iZ94ebgv853Z redis-3.0.2]# make test [root@iZ94ebgv853Zredis-3.0.2]# cp redis.conf /etc/ #復(fù)制配置文件
如果需自定義配置redis,可修改其配置文件/etc/redis.conf
三、在redis3.0.2文件夾下,安裝redis的最后一步:
[root@localhost redis-3.0.2]# ls [root@localhost redis-3.0.2]# cd src [root@localhost src]# make install
四、啟動(dòng)redis
[root@iZ94ebgv853Z ~]# redis-server /etc/redis.conf
五、設(shè)置防火墻
###################################### # Firewall configuration written bysystem-config-firewall # Manual customization of this file is notrecommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --stateESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp--dport 22 -j ACCEPT -A INPUT -j REJECT --reject-withicmp-host-prohibited -A FORWARD -j REJECT --reject-withicmp-host-prohibited COMMIT #####################################
把文本框內(nèi)容寫(xiě)入到/etc/sysconfig/iptables,覆蓋原來(lái)的內(nèi)容(如果有的話)。
[root@iZ94ebgv853Z ~]# service iptables start #啟動(dòng)防火墻 [root@iZ94ebgv853Z ~]# iptables -I INPUT 1 -p tcp --dport6379 -j ACCEPT #開(kāi)啟6379端口 [root@iZ94ebgv853Z ~]# service iptables save #保存防火墻的配置
六、設(shè)置開(kāi)機(jī)啟動(dòng)
[root@iZ94ebgv853Z~]# chkconfig iptables on #設(shè)置iptables開(kāi)機(jī)啟動(dòng)
設(shè)置redis開(kāi)機(jī)啟動(dòng):
在/etc/rc.local中添加:/usr/local/bin/redis-server /etc/redis.conf > /dev/null &
(Linux的redis服務(wù)的開(kāi)啟關(guān)閉
1.啟動(dòng):redis-server(redis-server redis.conf)
2.登陸:redis-cli(redis-cli -p 6379)
3.關(guān)閉:redis-cli shutdown
查看redis進(jìn)程:ps aux | grep redis
殺死進(jìn)程的方式:kill -9 PID )
七、redis密碼設(shè)置
首先關(guān)閉redis服務(wù),上面有;
然后去解壓后的redis-3.0.2中 查看當(dāng)前目錄:[root@localhost redis-3.0.2]# ls ;
找到redis.conf配置文件,編輯redis.conf: [root@localhost redis-3.0.2]# vim redis.conf
找到內(nèi)容#requirepass foobared 去掉注釋,foobared改為自己的密碼,我在這里改為:requirepass 123456
然后 保存 退出 重啟redis服務(wù)
(注意:由于redis中配置內(nèi)容多而雜,不容易找到注釋#requirepass foobared ,但
1、
注釋#requirepass foobared在
################################ LUA SCRIPTING ###############################此注釋的下面第十三行處;
2、注釋#requirepass foobared在
################################ LIMITS ###############################此注釋的上面第二十行處;
3、redis-3.0.2此版本的redis.conf配置文件 共有937行內(nèi)容此#requirepass foobared注釋即在第391行
)
八、Jedis連接redis
java 代碼方式
//連接redis服務(wù)器,192.168.0.100:6379
jedis = new Jedis("ip", 6379);
//權(quán)限認(rèn)證
jedis.auth("password");
配置文件方式
<bean id=”jedisConnectionFactory”
class=”org.springframework.data.redis.connection.jedis.JedisConnectionFactory”>
<property name=”hostName” value=”${redis.host}” />
<property name=”port” value=”${redis.port}” />
<property name=”password” value=”${redis.pass}” />
</bean>
redis的其他命令。
如果需要關(guān)閉redis:
[root@iZ94jzcra1hZ bin]# pkill redis
如果需要開(kāi)啟redis:
[root@iZ94jzcra1hZ bin]# redis-server &
加&符號(hào)的作用是為了讓此進(jìn)程轉(zhuǎn)換為后臺(tái)進(jìn)程,不占用shell的服務(wù)。
總結(jié)
以上所述是小編給大家介紹的CentOS 6.5 64位下安裝Redis3.0.2的具體步驟,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Redis隊(duì)列和阻塞隊(duì)列的實(shí)現(xiàn)
本文主要介紹了Redis隊(duì)列和阻塞隊(duì)列的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-11-11
redis key過(guò)期監(jiān)聽(tīng)的實(shí)現(xiàn)示例
在Redis中,我們可以為Key設(shè)置過(guò)期時(shí)間,當(dāng)Key的過(guò)期時(shí)間到達(dá)后,Redis會(huì)自動(dòng)將該Key標(biāo)記為已失效,本文就來(lái)介紹一下redis key過(guò)期監(jiān)聽(tīng)的實(shí)現(xiàn)示例,感興趣的可以了解一下2024-03-03
CentOS系統(tǒng)安裝Redis及Redis的PHP擴(kuò)展詳解
這篇文章主要介紹了CentOS系統(tǒng)下安裝Redis數(shù)據(jù)的教程,以及詳解了Redis數(shù)據(jù)庫(kù)的PHP擴(kuò)展,文中介紹的很詳細(xì),相信對(duì)大家的理解和學(xué)習(xí)具有一定的參考借鑒價(jià)值,有需要的朋友們可以參考借鑒,下面來(lái)一起看看吧。2016-12-12
利用Redis統(tǒng)計(jì)網(wǎng)站在線活躍用戶的方法
Redis支持對(duì)String類型的value進(jìn)行基于二進(jìn)制位的置位操作。通過(guò)將一個(gè)用戶的id對(duì)應(yīng)value上的一位,通過(guò)對(duì)活躍用戶對(duì)應(yīng)的位進(jìn)行置位,就能夠用一個(gè)value記錄所有活躍用戶的信息。下面這篇文章主要介紹了利用Redis統(tǒng)計(jì)網(wǎng)站在線活躍用戶的方法,需要的朋友可以參考。2017-01-01
redis不能訪問(wèn)本機(jī)真實(shí)ip地址的解決方案
這篇文章主要介紹了redis不能訪問(wèn)本機(jī)真實(shí)ip地址的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07
Redis實(shí)戰(zhàn)之Lettuce的使用技巧詳解
Lettuce?是?Redis?的一款高級(jí)?Java?客戶端,與?Jedis?并列成為最熱門(mén)的客戶端之一,目前已成為?SpringBoot?2.0?版本默認(rèn)的?redis?客戶端。本文主要和大家講講Lettuce的使用技巧,感興趣的可以了解一下2022-12-12
Redis實(shí)現(xiàn)分布式Session管理的機(jī)制詳解
這篇文章主要介紹了Redis實(shí)現(xiàn)分布式Session管理的機(jī)制詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
關(guān)于分布式鎖的三種實(shí)現(xiàn)方式
這篇文章主要介紹了關(guān)于分布式鎖的三種實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08

