CentOS 编译安装 Redis (实测 笔记 Centos 7.3 + redis 5.0.5)
环境:
系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡)
系统版本:CentOS-7.0-1406-x86_64-DVD.iso
安装步骤:
1.准备
1.1 显示系统版本
[root@centos ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@centos ~]# uname -r
3.10.0-514.6.1.el7.x86_64
1.2 安装基本软件包
[root@centos ~]# yum install vim wget lsof gcc gcc-c++ -y
1.3 显示IP地址
[root@centos ~]# ip addr|grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.1.10/24 brd 192.168.1.255 scope global ens160
2.安装redis
2.1 安装依赖
[root@centos ~]# yum install tcl -y
[root@centos ~]# cd /usr/local/src
[root@centos ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
[root@centos ~]# tar -zxvf redis-5.0.5.tar.gz && cd redis-5.0.5
[root@centos ~]# make && make PREFIX=/opt/redis install
[root@centos ~]# groupadd redis
[root@centos ~]# useradd -g redis redis -s /sbin/nologin -M
[root@centos ~]# mkdir -p /opt/redis/logs
[root@centos ~]# cp redis.conf /opt/redis
[root@centos ~]# ll /opt/redis
[root@centos ~]# chown -R redis:redis /opt/redis
[root@centos ~]# vim /opt/redis/redis.conf
找到相关的行,修改
#bind 127.0.0.1
protected-mode no
requirepass redispwd
daemonize no
supervised no
pidfile /opt/redis/redis_6379.pid
logfile /opt/redis/redis_6379.log
dbfilename dump.rdb
dir /opt/redis
保存,退出
[root@centos ~]# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
Type=simple
PIDFile=/opt/redis/redis_6379.pid
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure
User=redis
[Install]
WantedBy=multi-user.target
保存,退出
[root@centos ~]# systemctl enable redis && systemctl daemon-reload && systemctl start redis
[root@centos ~]# systemctl status firewalld
配置打开端口
[root@centos ~]# iptables -L --line-numbers|grep ACCEPT
[root@centos ~]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
**************************************************************************************************
指定IP可以访问
[root@centos ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"
显示所有规则
[root@centos ~]# firewall-cmd --list-all
移除指定IP可以访问
[root@centos ~]# firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"
**************************************************************************************************
[root@centos ~]# firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT
安装完成后,打开客户端
[root@centos ~]# /opt/redis/bin/redis-cli -h 127.0.0.1 -p 6379
输入以下命令,测试写入及读取
127.0.0.1:6379 > auth redispwd
127.0.0.1:6379 > set name abc123
127.0.0.1:6379 > get name
退出
quit
手动持久化(保存到硬盘)
[root@centos ~]# /opt/redis/bin/redis-cli save
redis-benchmark -h 127.0.0.1 -p 6379 -a 123456 -n 10000000 -t set -q
性能测试(redis-benchmark)
/opt/redis/bin/redis-benchmark -h 127.0.0.1 -p 6379 -c 100 -n 100000 -q
PING_INLINE: 128369.71 requests per second
PING_BULK: 124688.28 requests per second
SET: 124069.48 requests per second
GET: 110253.59 requests per second
INCR: 97276.27 requests per second
LPUSH: 127388.53 requests per second
RPUSH: 129533.68 requests per second
LPOP: 124223.60 requests per second
RPOP: 125470.52 requests per second
SADD: 126742.72 requests per second
HSET: 129198.97 requests per second
SPOP: 130208.34 requests per second
LPUSH (needed to benchmark LRANGE): 127388.53 requests per second
LRANGE_100 (first 100 elements): 127388.53 requests per second
LRANGE_300 (first 300 elements): 128700.12 requests per second
LRANGE_500 (first 450 elements): 126903.55 requests per second
LRANGE_600 (first 600 elements): 125786.16 requests per second
MSET (10 keys): 123762.38 requests per second
redis.conf 的配置信息
1、daemonize 如果需要在后台运行,把该项改为yes
2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid
3、bind 绑定ip,设置后只接受来自该ip的请求
4、port 监听端口,默认是6379
5、loglevel 分为4个等级:debug verbose notice warning
6、logfile 用于配置log文件地址
7、databases 设置数据库个数,默认使用的数据库为0
8、save 设置redis进行数据库镜像的频率。
9、rdbcompression 在进行镜像备份时,是否进行压缩
10、dbfilename 镜像备份文件的文件名
11、Dir 数据库镜像备份的文件放置路径
12、Slaveof 设置数据库为其他数据库的从数据库
13、Masterauth 主数据库连接需要的密码验证
14、Requriepass 设置 登陆时需要使用密码
15、Maxclients 限制同时使用的客户数量
16、Maxmemory 设置redis能够使用的最大内存
17、Appendonly 开启append only模式
18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)
19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)
20、vm-swap-file 设置虚拟内存的交换文件路径
21、vm-max-memory 设置redis使用的最大物理内存大小
22、vm-page-size 设置虚拟内存的页大小
23、vm-pages 设置交换文件的总的page数量
24、vm-max-threads 设置VM IO同时使用的线程数量
25、Glueoutputbuf 把小的输出缓存存放在一起
26、hash-max-zipmap-entries 设置hash的临界值
27、Activerehashing 重新hash
redis【持久化】配置:
http://blog.csdn.net/vtopqx/article/details/46833513
1、rdb
save 900 1
save 300 10
save 60 10000
2、aof
appendfsync always
appendfsync everysec
appendfsync no
redis【主从】配置:
http://blog.csdn.net/yilukuangpao/article/details/52004257
vi etc/redis.conf
#绑定IP地址
bind 192.168.88.128
#若当前服务为slave,在此处设置主服务的ip及端口
slaveof 10.10.10.200 6379
#若当前服务为slave,设置主服务的认证密码
masterauth 01130229
127.0.0.1:6379> slaveof 10.10.10.200 6379
显示ok,也就OK了
redis【集群】配置:
http://blog.csdn.net/jhq0113/article/details/44134833
http://blog.csdn.net/zj0116/article/details/44673017
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis_6379.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis
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
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush 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