Centos7安裝Redis5.0.5
1盒让、下載redis
redis官網(wǎng)
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
或者
下載好上傳服務(wù)器,這里我上傳到 /usr/local/software 目錄下
2呀非、進入目錄解壓進
[root@VM_0_14_centos ~]# cd /usr/local/software/
[root@VM_0_14_centos software]# tar -zxvf redis-5.0.5.tar.gz
3前联、安裝gcc【如果之前沒有安裝過】
因為redis
是由C語言編寫,編譯時需要gcc缨该,如果機器還沒有安裝的話,執(zhí)行命令安裝gcc川背。
[root@VM_0_14_centos software]# yum install gcc -y
4贰拿、編譯&安裝
進入解壓后的redis-5.0.5
目錄編譯并安裝【安裝在/usr/local/redis
目錄下】
[root@VM_0_14_centos software]# cd redis-5.0.5
[root@VM_0_14_centos redis-5.0.5]# make PREFIX=/usr/local/redis install
5、復(fù)制配置文件redis.conf
我這里把配置文件放到 /usr/local/redis/conf
目錄下熄云,你也可以放到etc目錄下
[root@VM_0_14_centos redis-5.0.5]# cd /usr/local/redis
[root@VM_0_14_centos redis]# mkdir conf
[root@VM_0_14_centos redis]# cd /usr/local/software/redis-5.0.5
[root@VM_0_14_centos redis-5.0.5]# cp redis.conf /usr/local/redis/conf/
6膨更、修改配置文件【簡單修改】
1、注釋掉 bind 127.0.0.1 這一行【解決只能特定網(wǎng)段連接的限制】
2缴允、將 protected-mode 屬性改為 no 【關(guān)閉保護模式荚守,不然會阻止遠程訪問】
3、將 daemonize 屬性改為 yes 【這樣啟動時就在后臺啟動】
4练般、requirepass redis123456 設(shè)置密碼矗漾,【可不設(shè)置】
5、在/usr/local/redis 創(chuàng)建 data 目錄并改為如下配置薄料,保存數(shù)據(jù)路徑【可以用默認】
dir /usr/local/redis/data
6敞贡、配置為aof 模式 【可用默認的rdb】
appendfilename "appendonly.aof"
7、啟動
進入/usr/local/redis/bin/
目錄
[root@VM_0_14_centos bin]# ./redis-server ../conf/redis.conf &
8都办、查看redis
是否啟動
[root@VM_0_14_centos bin]# ps -ef|grep redis
root 1663 1 0 14:40 ? 00:00:06 /usr/local/redis/bin/redis-server *:6379
root 1744 1621 0 15:26 pts/0 00:00:00 grep --color=auto redis
# 客戶端連接
[root@VM_0_14_centos bin]# ./redis-cli
127.0.0.1:6379>
9嫡锌、防火墻配置
這里我就先將防火墻關(guān)閉
systemctl stop firewalld
10虑稼、開機自啟設(shè)置
在redis
的解壓目錄下, 即/usr/local/software/redis-5.0.5
目錄下包含有琳钉,/utils/redis_init_script
文 件, 將此文件復(fù)制到/etc/init.d
目錄下并改名為redis
[root@VM_0_14_centos redis-5.0.5]# cp utils/redis_init_script /etc/init.d/redis
11、復(fù)制/usr/local/redis/conf/
目錄下的redis.conf
配置文件到/etc/reids/6379
[root@VM_0_14_centos redis-5.0.5]# cd /usr/local/redis/conf
[root@VM_0_14_centos conf]# mkdir /etc/redis
[root@VM_0_14_centos conf]# cp redis.conf /etc/redis/6379.conf
12蛛倦、進入/etc/init.d
目錄歌懒,修改redis
文件
修改EXEC
、CLIEXEC
溯壶、CONF
, 分別修改為redis服務(wù)腳本的路徑及皂、客戶端腳本的路徑甫男、配置文件的路徑.
[root@VM_0_14_centos redis-5.0.5]# cd /etc/init.d/
[root@VM_0_14_centos init.d]# vim redis
...
REDISPORT=6379
#指定自己的redis服務(wù)器腳本位置
EXEC=/usr/local/redis/bin/redis-server
#指定自己的redis客戶端腳本位置
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
#指定redis配置文件的路徑位置,注意${REDISPORT} 取得是6379验烧,所以配置文件為6379.conf板驳,也可以寫死
CONF="/etc/redis/${REDISPORT}.conf
手動開啟/停止redis服務(wù),systemctl start redis/systemctl stop redis
13碍拆、開機自啟【關(guān)閉是off】
chkconfig redis on