一、安裝必要的軟件
1.安裝gcc
yum install gcc-c++
2.安裝TCL(Tool Command Language)工具腳本語言,是Linux內的一種語言包
#在瀏覽器裏打開下載
http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
二、解壓、安裝redis
1.解壓redis
2.make編譯
3.cd src make test測試
有可能會出錯,如下:
實際情況,就是,調了還是不能make test正常通過,囧。我就接着安裝了。
4.make install
這步呢,其實也就是,將redis相關的應用程序,安裝到指定位置。
make PREFIX=/home/programfiles/redis install
目錄下的文件結構,如下:
三、redis服務自啓動
1.redis_init_script文件內容,如下:
服務腳本命令
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/home/program-files/redis/bin/redis-server
CLIEXEC=/home/program-files/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF=/home/program-files/redis/${REDISPORT}.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
2.將redis_init_script文件複製到/etc/init.d下,重命名爲redis。
3.chkconfig redis on
4.服務啓動命令
#打開服務
service redis start
#關閉服務
service redis stop
四、redis服務啓動遇到的問題
1.本以爲會順利啓動,結果失敗,沒有進程。因爲6379.conf文件中bind格式不正確。
假如:你要限制N個IP可以訪問,正確的格式爲如下:
#第一行爲本機地址
bind 192.168.1.100 127.0.0.1
bind 192.168.1.101 192.168.1.102
......