图形界面下载网址
https://github.com/cc20110101/RedisView/releases
Redis需要gcc环境(如果已经有该环境跳过此步骤)
yum install gcc-c++
在/usr/local下创建redis文件夹
mkdir redis cd redis下载、解压、编译Redis:
wget tar xzf redis-5.0.4.tar.gz cd redis-5.0.4 # 指定内存池类型,提高性能 make MALLOC=libc cd src make PREFIX=http://www.likecs.com/usr/local/redis install拷贝redis.conf配置文件到特定目录;
mkdir -p /usr/local/redis/6379 cp redis.conf /usr/local/redis/6379/添加redis到命令到全局变量,方便在任何目录执行;
vi /etc/profile # 在最后行添加: export PATH="$PATH:/usr/local/redis/bin"将 redis-trib.rb 复制到 /usr/local/bin 目录下
cd src cp redis-trib.rb /usr/local/redis/bin/对redis.conf文件修改如下
#设置占用最大内存 数字为bytes 该值为0.75G maxmemory 751619276 # redis 内存回收机制 默认noeviction:拒绝更多内存,当前为回收已经过期的key,并且优先回收存活时间(TTL)较短的键 maxmemory-policy volatile-ttl # 开启AOF持久化 appendonly yes # AOF追写策略 appendfsync everyse #是否同步重写问件 yes性能更好,有概率丢失文件 no-appendfsync-on-rewrite no # 设置AOF增长比例和最小触发文件大小,即至(64*100% + 64)mb时触发重写文件 auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb # 注释掉RDB持久化参数 #save 900 1 #save 300 10 #save 60 10000 # 删除目录下的dump.rdb rm -rf dump.rdb # 手动重写AOF 执行 bgrewriteaof启动验证redis
cd /usr/local/redis/ bin/redis-server 6379/redis.conf性能测试
# 启动5个连接,发起100000个请求,每个请求的大小为10bytes bin/redis-benchmark -t get -h localhost -p 6379 -c 5 -n 100000 -d 10设置开机自启
vi /etc/init.d/redis # 填入以下内容 #!/bin/sh # chkconfig: 2345 56 26 # description: Redis Service ### BEGIN INIT INFO # Provides: Redis # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts Redis # Description: starts the BT-Web ### END INIT INFO # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. PATH=http://www.likecs.com/usr/local/bin:/sbin:/usr/bin:/bin # redis端口号 REDISPORT=6379 # redis-server所在目录的绝对路径 EXEC=http://www.likecs.com/usr/local/redis/bin/redis-server # redis-cli所在目录的绝对路径 REDIS_CLI=http://www.likecs.com/usr/local/redis/bin/redis-cli PIDFILE=http://www.likecs.com/var/run/redis.pid # redis.conf所在目录的绝对路径 CONF="/usr/local/redis/6379/redis.conf" AUTH="nginx" 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 -a $AUTH 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 chmod 755 redis chkconfig redis on service redis start在redis文件夹下创建redis-cluster,并且在redis-cluster文件夹下创建7004 7005 7006文件夹
将redis5.0.4的文件夹下redis.conf文件复制到刚刚创建的7004 7005 7006文件夹下
cp redis.conf /usr/local/redis/redis-cluster/7004 cp redis.conf /usr/local/redis/redis-cluster/7005 cp redis.conf /usr/local/redis/redis-cluster/7006修改刚刚复制的三个配置文件redis.conf
port 7000 //端口7000,7002,7003 bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群 daemonize yes //redis后台运行 pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002 cluster-enabled yes //开启集群 把注释#去掉 cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002 把注释#去掉 cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置 把注释#去掉 appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志在/usr/local/redis/bin目录下启动各个节点
./redis-server /usr/local/redis/redis-cluster/7004/redis.conf ./redis-server /usr/local/redis/redis-cluster/7005/redis.conf ./redis-server /usr/local/redis/redis-cluster/7006/redis.conf检查redis启动情况
ps -ef | grep redis //查看redis启动情况 netstat -tnlp | grep redis//查看redis端口开启情况