使用军哥的安装脚本LNMP1.7安装和使用redis
cd
cd lnmp1.7
#执行
./addons.sh install redis
#直接回车安装最新稳定版本
以上安装成功,并加入开机启动,因为一台服务器后续要用到,所以先安装一下redis
安装完成后,默认无密码,只允许本机访问:127.0.0.1 端口6379
如果你需要使用密码
vi /usr/local/redis/etc/redis.conf
#搜索requirepass,将requirepass注释去掉,后面修改为你想要的密码
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
启动脚本就无法stop了,提示(error) NOAUTH Authentication required,因为redis自启动命令没有密码连接设置
vi /etc/init.d/redis
#搜索shudown
42 if [ ! -f "$PIDFILE" ]; then
43 echo "$PIDFILE does not exist, process is not running"
44 else
45 PID=$(cat $PIDFILE)
46 echo "Stopping Redis server..."
47 $REDIS_CLI -p $REDISPORT -a password shutdown
48 if [ "$?"="0" ]; then
49 echo " done"
50 else
51 echo " failed"
52 fi
53 fi
#设置密码后必须有密码才能在cli下进行操作
#编辑 /etc/init.d/redis 查找shutdown在前面加上 -a 密码 ,-a前面和密码后面都有空格
如果需要外网访问:
除了要修改 /usr/local/redis/etc/redis.conf 里将bind 127.0.0.1 改成 bind 0.0.0.0 重启redis
还需要将防火墙里redis的端口 6379的禁止访问规则去掉,参考iptables教程:https://www.vpser.net/security/linux-iptables.html
允许外网访问一定要做好相关安全措施!!!!!!!!!!
redis重启的2种方式
service redis restart
或者
/etc/init.d/redis restart