1、redis已经自己写好了make file ,故不需要configure操作了
(1)下载安装包并解压
wget http://download.redis.io/releases/redis-4.0.0.tar.gz tar -xvf redis-4.0.0.tar.gz
(2)移动包到/usr/local/redis
mv ./redis-4.0.0 /usr/local/redis
(3)生成
cd /usr/local/redis make
(4)测试,时间较长
cd /usr/local/redis/src make test
(5)安装,将Redis的命令安装到/usr/local/bin/目录
make PREFIX=/usr/local/redis install
(6)配置文件拷贝到/usr/local/redis/etc下
mkdir /usr/local/redis/etc sudo cp ~/redis-4.0.0/redis.conf /usr/local/redis/etc
注意:如果在make test过程中报错:
!!! WARNING The following tests failed:
*** [err]: ZSCAN with encoding skiplist in tests/unit/scan.tcl
Expected condition '$k eq "key:$v"' to be true (key:0 eq "key:nan")
Cleanup: may take some time... OK
make: *** [test] Error 1
[root@localhost src]# cd ..
[root@localhost redis]# make install
cd src && make install
make[1]: Entering directory `/usr/local/redis/src'
Hint: It's a good idea to run 'make test' ;)
解决方法:直接拷贝172.18.2.63的redis到本地机器,改下redis.conf配置即可运行【172.18.5.149既是如此解决】
2、参数文件配置
vi /usr/local/redis/etc/redis.conf
[root@master1 etc]# vi redis.conf daemonize yes pidfile "redis.pid" port 4590 bind 172.18.5.159 timeout 86400 tcp-keepalive 60 loglevel warning logfile "redis.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error no rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" #dir "/apps/svr/redis/redis_4501" slave-serve-stale-data yes slave-read-only yes slave-priority 100 maxmemory 1024mb maxmemory-policy allkeys-lru appendonly yes appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 hash-max-ziplist-entries 1024 hash-max-ziplist-value 2048 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 requirepass 123456 masterauth 123456
10、启动
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
三、systemctl启动盘配置
2、更改配置
更改redis配置
sudo vim /usr/local/redis/etc/redis.conf
#将redis改为以守护进程的方式运行
daemonize yes
添加环境变量
sudo echo 'export PATH="$PATH:/usr/local/redis/bin"'>> /etc/profile
sudo source /etc/profile
3、设置systemctl方式启动
添加配置启动脚本
sudo vim /etc/rc.d/init.d/redis
#!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/etc/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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
4、给脚本增加运行权限
sudo chmod +x /etc/init.d/redis
5、查看服务列表
sudo chkconfig --list
6、添加服务
sudo chkconfig --add redis
7、配置启动级别
sudo chkconfig --level 2345 redis on
8、启动服务并查看
sudo systemctl start redis
sudo systemctl status redis
文章评论