Redis 运维篇+安装单实例
发布日期:2021-06-29 12:02:36 浏览次数:3 分类:技术文章

本文共 5345 字,大约阅读时间需要 17 分钟。

说明:本文为面向Redis安装的指导手册

标签:Redis安装、安装Redis、Linux Redis、Centos Redis、Linux 6、Redis 4.0.2
注意:文中删去了不需要的多余部分,让初学者一目了然一学就会
温馨提示:如果您发现本文哪里写的有问题或者有更好的写法请留言或私信我进行修改优化


★ 前言

※ 该文档架构采用:单机1主2从架构(相当于3个redis)
※ 系统信息:Centos 6.3 x86_64 4GB内存
※ 为了方便初学者学习了解redis本文简化了所有步骤
※ Redis全称“remote dictionary server”中文远程字典服务
※ Redis属于NoSql数据库中的key-value类型
※ Redis的哨兵机制是redis2.8开始支持,而集群模式是redis3.0开始支持。
※ Redis的sentinel系统用于管理多个redis服务器,该系统主要执行三个任务:监控、提醒、自动故障转移。
※ Redis的更多参数介绍参考本人其他相关文档

★ 相关文章

★ 环境简介
※ 操作系统 :centos 6.3
※ Redis版本:redis-4.0.2
※ gcc版本  :gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) (系统自带)

★ 安装Redis
※ 系统准备
gcc -v
yum install -y gcc

★ 准备Redis
※ 下载
http://download.redis.io/releases/redis-4.0.2.tar.gz
※ 解压
su - root
mkdir /soft
cd /soft
tar xvf redis-4.0.2.tar.gz
※ 编译安装
--需要配置make的分配器allocator,因为libc并不是默认的分配器
cd /soft/redis-4.0.2/src/
make MALLOC=libc

★ 修改配置文件
※ 设置关键参数
vi /soft/redis-4.0.2/redis.conf        
注释“bind 127.0.0.1”容许任何IP访问(默认只允许本机连接)
修改“protected-mode yes”为“protected-mode no”表示允许公网访问redis(默认不对外)
修改“daemonize no”为“daemonize yes”容许Redis后台运行(默认前台运行)

★ 测试运行
※ 拉起Redis服务
su - root
/soft/redis-4.0.2/src/redis-server
※ redis命令行工具
/soft/redis-4.0.2/src/redis-cli
※ 执行命令查看运行状态
echo "info replication" | /soft/redis-4.0.2/src/redis-cli -p 6379

★ 常用参数

【通用】
※ 端口配置 port 6380
※ 进程编号 pidfile /var/run/redis_6380.pid
※ 指向主库 slaveof 172.16.48.129 6379
※ 访主密码 masterauth "123456789"
※ 白名单IP bind 172.19.131.247
※ 最多连接 maxclients 1000
※ 内存上限 maxmemory 1000
※ 虚拟内存 vm-enabled
※ VM最大值 vm-max-memory
※ swap文件 vm-swap-file
※ swap大小 vm-page-size 32
※ swap数量 vm-pages 999999999
※ swap线程 vm-max-threads 4
※ 网络打包 glueoutputbuf yes
※ 内存压缩 hash-max-zipmap-entries
※ 动态hash activerehashing yes
※ 数据库ID databases 0
※ 镜像频率 save 60 10000
※ 镜像压缩 rdbcompression yes
※ 镜像名称 dbfilename dump.rdb
※ 镜像路径 dir ./rdb
※ 日志级别 loglevel notice/debug/verbose/warning
※ 保护模式 protected-mode no
※ 访问超时 timeout 5000
※ 访问密码 requirepass "123456789"
※ 后台运行 daemonize yes
※ 持久模式
    打开AOF持久化支持 appendonly yes
    打开RDB持久化支持 save
※ AOF 频率 appendfsync always/everysec/no
※ AOF 文件 appendfilename record.aof
【哨兵】
※ 监控主库 sentinel monitor mymaster 127.0.0.1 6379 2
※ 主库密码 sentinel auth-pass mymaster 123456789
※ 判定宕机 sentinel down-after-milliseconds mymaster 5000
※ 再同步数 sentinel parallel-syncs mymaster 2
※ 切换超时 sentinel failover-timeout mymaster 15000
※ 自动配置 查看任意哨兵配置文件:cat sentinel_26380.conf
    # 每次重新选主后版本号自动更新+1(版本号越大代表配置/操作越新)
    sentinel config-epoch mymaster 9
    sentinel leader-epoch mymaster 9
    # 自动列出当前的从节点信息
    sentinel known-slave mymaster 127.0.0.1 6381
    sentinel known-slave mymaster 127.0.0.1 6382
    # 自动列出当前的其他哨兵节点信息
    sentinel known-sentinel mymaster 127.0.0.1 26381 ebf587d185f909842728436242aa7d695ebde911
    sentinel known-sentinel mymaster 127.0.0.1 26382 aacdd53340e758d782c9ecdda94adafcca0d4c43
    # 每次重新选主后版本号自动更新+1(版本号越大代表配置/操作越新)
    sentinel current-epoch 9
※ 

★ 案例

[root@localhost src]# ./redis-server 3945:C 25 Feb 20:02:48.985 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo3945:C 25 Feb 20:02:48.985 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=3945, just started3945:C 25 Feb 20:02:48.985 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf3945:M 25 Feb 20:02:48.988 * Increased maximum number of open files to 10032 (it was originally set to 1024).                _._                                                             _.-``__ ''-._                                                   _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit  .-`` .-```.  ```\/    _.,_ ''-._                                    (    '      ,       .-`  | `,    )     Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379 |    `-._   `._    /     _.-'    |     PID: 3945  `-._    `-._  `-./  _.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |           http://redis.io          `-._    `-._`-.__.-'_.-'    _.-'                                    |`-._`-._    `-.__.-'    _.-'_.-'|                                   |    `-._`-._        _.-'_.-'    |                                    `-._    `-._`-.__.-'_.-'    _.-'                                         `-._    `-.__.-'    _.-'                                                 `-._        _.-'                                                         `-.__.-'                                               3945:M 25 Feb 20:02:49.013 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.3945:M 25 Feb 20:02:49.013 # Server initialized3945:M 25 Feb 20:02:49.014 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.3945:M 25 Feb 20:02:49.014 * Ready to accept connections^C3945:signal-handler (1614254627) Received SIGINT scheduling shutdown...3945:M 25 Feb 20:03:47.949 # User requested shutdown...3945:M 25 Feb 20:03:47.949 * Saving the final RDB snapshot before exiting.3945:M 25 Feb 20:03:47.967 * DB saved on disk3945:M 25 Feb 20:03:47.968 # Redis is now ready to exit, bye bye...[root@localhost src]#

※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~

over

转载地址:https://blog.csdn.net/zzt_2009/article/details/114394750 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Redis HA篇 +主从搭建
下一篇:Oracle 开发篇+追踪PL/SQL执行情况(层次分析器)

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月18日 15时59分22秒