redis 安装常见问题
参考:https://www.runoob.com/redis/redis-install.html
https://blog.csdn.net/q1035331653/article/details/79077260
https://www.cnblogs.com/zjz20/p/11587376.html
https://download.redis.io/releases/redis-6.2.1.tar.gz?_ga=2.130829327.140621251.1615359349-1114377242.1615359349
service redis does not support chkconfig的解决办法:
https://www.cnblogs.com/goodspeed/archive/2012/10/18/2729615.html
查看操作系统版本信息:
https://www.cnblogs.com/vaelailai/p/7545166.html
防火墙:
https://blog.csdn.net/xu215740578/article/details/89045797
1:安装
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
tar -xzf redis-6.2.1.tar.gz
cd redis-6.2.1
make
error1:cc: Command not found
yum install gcc
https://www.cnblogs.com/richerdyoung/p/8066373.html
erron2:
【Redis】编译错误zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
make MALLOC=libc
后端启动:
2.编译完成后,在Src目录下,有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf将其拷贝到一个目录下。
# mkdir /usr/redis
# cp redis-server /usr/redis
# cp redis-benchmark /usr/redis
# cp redis-cli /usr/redis
# cp ../redis.conf /usr/redis
# cd /usr/redis
3.启动服务
# ./redis-server redis.conf
提示错误 -bash :redis-server:command not found
建立软连接
# ln -s /usr/redis/redis-server /usr/bin/redis-server
# ln -s /usr/redis/redis-cli /usr/bin/redis-cli
重新启动
# redis-server /usr/redis/redis.conf
redis 自启动脚本:
vi /etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/redis/redis-server
REDIS_CLI=/usr/redis/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/redis/redis.conf"
AUTH="password123"
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 exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN sleep 2
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
(3)设置权限
# chmod 755 redis
(4)启动
# /etc/init.d/redis start
提示错误 /etc/init.d/redis:permission denied
# chmod a+x /etc/init.d/redis
a+x 是给所有人加上可执行权限,包括所有者,所属组,和其他人
o+x 只是给其他人加上可执行权限
重新启动后显示
(5)设置开机自启动
# chkconfig redis on
提示错误 service redis does not support chkconfig
把下面两行注释放在/etc/init.d/redis文件靠前的注释中:
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
(6)关机重启测试
5.设置启动redis为后台启动
开机自启动参考:
https://blog.csdn.net/xu215740578/article/details/89045797
service redis does not support chkconfig的解决办法
问题解决办法如下:
必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中:
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
上面的注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。
6:chkconfig用法
chkconfig命令可以用来检查、设置系统的各种服务
使用语法:
chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
参数用法:
–add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
–del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
–level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕。
使用范例:
chkconfig –list 列出所有的系统服务
chkconfig –add redis 增加redis服务
chkconfig –del redis 删除redis 服务
chkconfig –level redis 2345 on 把redis在运行级别为2、3、4、5的情况下都是on(开启)的状态。