redis
2021-08-20 本文已影响0人
古飞_数据
安装redis
#!/bin/bash
#安装必要工具包
yum -y install gcc jemalloc-devel
#配置必要的环境
#tcp-backlog
#backlog 参数控制的是三次握手后server端收到的client ack确认号之后的队列值,即全连接队列(accept queue)
#根据警告提示修改为大于511以上的值即可
echo 'net.core.somaxconn=1024' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_max_syn_backlog=1024' >> /etc/sysctl.conf
#vm.overcommit_memory
#内核控制进程的内存申请的策略,有0,1,2三种。
#0表示内核会检查是否有足够的物理内存,有就允许,没有就拒绝;
#1表示内核允许分配所有物理内存而不管当前内存使用状态如何;
#2表示内核允许分配超过物理内存和交换空间总和的内存。
echo 'vm.overcommit_memory=1' >> /etc/sysctl.conf
sysctl -p
#Transparent Huge Pages
#大页内存动态分配
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
chmod +x /etc/rc.local
. /etc/rc.local
cd /usr/local/src/
wget https://download.redis.io/releases/redis-4.0.8.tar.gz
tar xf redis-4.0.8.tar.gz
cd redis-4.0.8/
make PREFIX=/usr/local/redis install
echo 'PATH=/usr/local/redis/bin:$PATH' > /etc/profile.d/redis.sh
. /etc/profile.d/redis.sh
mkdir /data/redis/{etc,log,data,run} -p
#cp /usr/local/src/redis-4.0.8/redis.conf /data/redis/etc/
cat >/data/redis/etc/redis.conf <<EOF
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/redis/run/redis_6379.pid
loglevel notice
logfile /data/redis/log/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/data
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 no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
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
EOF
#启动数据库
redis-server /data/redis/etc/redis.conf
#vim /data/redis/etc/redis.conf
#bind 0.0.0.0 #绑定监听IP
#daemonize yes #后台启动redis
#logfile /usr/local/redis/log/redis.log #log日志存放路径
#dir /usr/local/redis/data #RDB,AOF文件存放路径
#pidfile /usr/local/redis/run/redis_6379.pid #pidfile存放路径
管理redis
[root@VM-0-108-centos ~]# redis-cli
127.0.0.1:6379> info
127.0.0.1:6379> shutdown
echo 'requirepass 123456b' >> /data/redis/etc/redis.conf
shutdown
redis-server /data/redis/etc/redis.conf
echo 'masterauth 123456b' >> /data/redis/etc/redis.conf
echo 'slaveof 10.206.0.204 6379' >> /data/redis/etc/redis.conf
shutdown
redis-server /data/redis/etc/redis.conf
info replication