環境:Centos7+Redis 5.0,如果環境不符合,本篇僅供參考。
1、準備工作
作者習慣軟件安裝包放在單獨路徑,解壓路徑也放在單獨路徑。
下載路徑:mkdir -p /data/softwore
cd /data/software
2、軟件下載
redis包下載地址,可以下載後用ftp工具導入下載路徑中,也可以使用wget直接下載。
作者:wget http://download.redis.io/redis-stable.tar.gz
注:wget下載軟件,如果沒有指明路徑,會存放在當前路徑下(pwd查詢)。
3、解壓
tar -zxvf redis-stable.tar.gz -C /usr/local
4、編譯
cd /usr/local/redis-stable
make
提示如下就算完成。
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/usr/local/redis-5.0.0/src'
5、安裝
make install
提示如下就算完成。
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis-5.0.0/src'
6、設置配置文件路徑
mkdir -p /etc/redis
cp redis.conf /etc/redis
7、修改配置文件
vi /etc/redis/redis.conf
daemonize 設置爲yes
先註釋bind 127.0.0.1,不然不能連接別的ip
appendonly 設置爲yes
關閉防火牆
systemctl stop firewalld.service #關閉防火牆
firewall-cmd --state #查看防火牆是否關閉 not running
8、啓動
/usr/local/bin/redis-server /etc/redis/redis.conf
9、查看運行情況
ps -ef | grep redis
下圖說明redis安裝成功,且只能本機(127.0.0.1)運行
10、設置開機啓動
編寫開機自啓動腳本
vim /etc/init.d/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=6379 #端口號,這是默認的,如果你安裝的時候不是默認端口號,則需要修改
REDISPATH=/usr/local/bin/ #redis-server啓動腳本的所在目錄,你如果忘了可以用find / -name redis-server 或whereis redis-server找到
EXEC=${REDISPATH}/redis-server
CLIEXEC=${REDISPATH}/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid #在redis.conf中可找到該路徑
CONF="${REDISPATH}/redis.conf" #redis.conf的位置, 如果不和redis-server在同一目錄要修改成你的redis.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
設置可執行權限:
chmod 777 /etc/init.d/redis
啓動redis:
/etc/init.d/redis start
查看redis是否成功啓動.
ps aux|grep redis
設置開機啓動:
chkconfig redis on
關機重啓測試:
reboot