redis
redis 4.*
部署步骤
-
下载源码:
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
-
编译安装:
yum -y install gcc tar -xaf redis-4.0.14.tar.gz cd redis-4.0.14 make MALLOC=libc cp src/redis-server src/redis-cli src/redis-trib.rb ${redispath} (redispath为目标安装位置) # cd src;cp redis-server redis-sentinel redis-benchmark redis-check-rdb redis-check-aof /usr/local/bin/ copy 配置文件redis.conf到安装位置,根据需要修改配置文件
集群版:redis.conf(单节点修改cluster-enabled no)
protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile "redis.pid" loglevel notice logfile "redis.log" databases 16 always-show-logo yes stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "." slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no appendonly yes appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 512mb aof-load-truncated yes aof-use-rdb-preamble no lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes cluster-enabled yes #绑定的ip地址 bind 0.0.0.0 #实例最大内存 maxmemory 6gb
调整内核参数:
-
关闭THP
echo never > /sys/kernel/mm/transparent_hugepage/enabled echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >>/etc/rc.local
-
修改sysctl.conf
vi /etc/sysctl.conf ------------------------------- vm.overcommit_memory = 1 net.core.somaxconn = 2048
-
使内核参数生效
sysctl -p
新建系统服务: 新建下面文件,复制下面内容
vi /lib/systemd/system/redis.service --------------------------------------- [Unit] Description=redis After=network.target [Service] Type=forking WorkingDirectory=/home/admin/redis PIDFile=/home/admin/redis/redis.pid ExecStart=/home/admin/redis/redis-server /home/admin/redis/redis.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true LimitNOFILE=64000 [Install] WantedBy=multi-user.target
systemctl daemon-reload systemctl enable redis systemctl restart redis
集群版复制二进制文件到相应节点、添加对系统服务器并启动 初始化集群步骤:
-
安装rvm(ruby管理器)
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB curl -sSL https://get.rvm.io | bash -s stable source /etc/profile.d/rvm.sh rvm install ruby-2.6.3
-
yum -y install gem
-
gem install redis
-
初始化集群:
./redis-trib.rb create --replicas 1 10.8.140.43:6379 10.8.140.44:6379 10.8.140.45:6379 10.8.140.44:6380 10.8.140.45:6380 10.8.140.43:6380
-
redis 5.*
安装步骤和4.*一致初始化集群时直接使用redis-cli初始化,不需要使用ruby redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1