标签:bind netstat 修改 kill make chm 手动 方便 roc
下载网址
yum install gcc-c++
mkdir redis
cd redis
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
tar xzf redis-5.0.4.tar.gz
cd redis-5.0.4
# 指定内存池类型,提高性能
make MALLOC=libc
cd src
make PREFIX=/usr/local/redis install
mkdir -p /usr/local/redis/6379
cp redis.conf /usr/local/redis/6379/
vi /etc/profile
# 在最后行添加:
export PATH="$PATH:/usr/local/redis/bin"
cd src
cp redis-trib.rb /usr/local/redis/bin/
#设置占用最大内存 数字为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
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=/usr/local/bin:/sbin:/usr/bin:/bin
# redis端口号
REDISPORT=6379
# redis-server所在目录的绝对路径
EXEC=/usr/local/redis/bin/redis-server
# redis-cli所在目录的绝对路径
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/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
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
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日志开启 有需要就开启,它会每次写操作都记录一条日志
./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
ps -ef | grep redis //查看redis启动情况
netstat -tnlp | grep redis//查看redis端口开启情况
./redis-cli --cluster create --cluster-replicas 1 10.104.132.37:7001 10.104.132.37:7002 10.104.132.37:7003 10.104.132.52:7004 10.104.132.52:7005 10.104.132.52:7006
运行界面如上,则表示配置成功
./redis-cli -h 10.104.132.37 -c -p 7001
./redis-cli -h 10.104.132.52 -c -p 7005
关闭所有节点
pkill -9 redis
标签:bind netstat 修改 kill make chm 手动 方便 roc
原文地址:https://www.cnblogs.com/hyry/p/11927557.html