redis rdb文件查看
1.安装rdb文件转换工具
linux下命令:pip install rdbtools python-lzf
2.转换rdb文件
rdb --command memory dump.rdb > memory.csv
3、限制ip访问redis
//只允许127.0.0.1访问6379
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 6379 -j ACCEPT
//其他ip访问全部拒绝
iptables -A INPUT -p TCP --dport 6379 -j REJECT
redis安装:
1.下载合适的redis版本:https://download.redis.io/releases/
安装gcc
yum install gcc-c++ -y
查看gcc版本:gcc -v
2.解压
tar -zxvf redis-5.0.5.tar.gz
cd redis-5.0.5
编译:make 出现错误,执行make MALLOC=libc
编译完成后,进入src进行redis安装
执行命令:make PREFIX=/usr/local/redis install
PREFIX=/usr/local/redis 指定redis可执行文件bin存放目录
修改redis.conf配置文件
注释掉:
修改保护模式:protected-mode no
设置密码:
在redis.conf配置文件中修改:requirepass yourpasswd
启动:
./redis-server /usr/local/redis/redis.conf &
设置开机启动:
根据启动脚本,将修改好的配置文件复制到指定目录下,用root用户进行操作:
vi /etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/app/redis-5.0.5/bin/redis-server
CLIEXEC=/app/redis-5.0.5/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/app/redis-5.0.5/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
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是10,关闭的优先级是90。
添加权限:chmod 755 redis
启动:service redis start
加入开机启动:chkconfig redis on
查看加入开机启动是否成功:chkconfig --list
systemctl方式:
vi /usr/lib/systemd/system/redis6379.service
[Unit]
Description=redis6379
After=network.target
[Service]
Type=forking
PIDFile=/app/redis-cluster/6379/redis.pid
ExecStart=/app/redis-cluster/bin/redis-server /app/redis-cluster/6379/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=5
User=redis
Group=redis
RuntimeDirectory=redis6379
RuntimeDirectoryMode=0755
PrivateTmp=true
[Install]
WantedBy=default.target
保存后执行以下命令:
systemctl daemon-reload
systemctl enable redis6379.service
systemctl status redis6379
systemctl restart redis6379
创建集群:
./redis-cli --cluster create 172.50.2.34:7000 172.50.2.35:7001 172.50.2.36:7002 172.50.2.11:7003 172.50.2.12:7004 172.50.2.13:7005 --cluster-replicas 1