Note
说好的更新大数据…
抱歉,加班去搞了个redis集群…
我把搞redis踩的坑都给你们说一下…
BigData 和 微服务 后续更新
小编昨晚搞到晚上3点… 给点面子… 转载请注明作者~
写代码跟炒菜差不多。先准备好所有的东西,知识,材料就像菜一样,准备好了再去慢慢炒菜。一开始不好吃,练习练习着会越来越有味道。并且是带着自己味道的菜。
爬坑准备
- Redis-3.2.12 源码包
- Ruby 2.2.2以上
- RubyGems
- 三台互通主机
- centos-release-7-5.1804.el7.centos.x86_64.rpm
- wget-1.14-15.el7_4.1.x86_64.rpm
踩过的坑
小编Linux不太好…所以还没深究太多,
这些坑只是表面现象。
很有可能是我自己没配置好。
- 我安装的centos7.4 minimal,没安装好…
- yum仓库失效…
- weg命令minimal里面没有…
- make install 编译有坑…
- Node 192.168.31.60:7000 is not empty
- You need tcl 8.5 or newer in order to run the Redis test
Core - Code
-
准备三台主机
-
创建好用户redis,密码(账号,安装路径自己根据习惯)
$ useradd redis $ passwd redis
-
进入安装目录上传redis源码包上去,并解压
$ cd /home/redis $ tar -zxvf redis-3.2.12.tar.gz
-
创建文件夹存放配置等文件(后面看配置文件会一一对应这些文件夹)
# 用于存放后面一些配置文件 $ mkdir local $ cd local $ mkdir redis-3.2.12 $ cd redis-3.2.12 # 创建..创建..创建.. $ mkdir pid $ mkdir redis-cluster $ mkdir sbin
-
编译一下源码
$ cd /home/redis/redis-3.2.12/src $ make install PREFIX=/home/redis/local/redis-3.2.12/sbin/
-
创建配置文件
# 端口作为文件夹名字 $ mkdir /home/redis/local/redis-3.2.12/redis-cluster/{7000,7001,7002} # 进入每个文件夹创建配置文件 7000为例 $ cd /home/redis/local/redis-3.2.12/redis-cluster/7000 # 方法一自己创建redis.conf文件 好处:没那么多注释,容易看 $ touch redis.conf $ vi redis.conf # 方法二cp官方给的配置文件 (推荐) 好处: 防止自己配置错,官方就是官方 $ cp /home/redis/redis-3.2.12/redis.conf /home/redis/local/redis-3.2.12/redis-cluster/7000/ $ vi /home/redis/local/redis-3.2.12/redis-cluster/7000/redis.conf # 在vim下用/找到配置然后修改
-
vi redis.conf 写入(修改)以下内容
# 端口7000,7001,7002,与目录对应 port 7000 #默认ip为127.0.0.1,需要改为其他节点机器可访问的ip,否则创建集群时无法访问对应的端口,无法创建集群 bind 192.168.31.60 #redis后台运行 daemonize yes #开启集群 cluster-enabled yes #集群的配置,配置文件首次启动自动生成 7000,7001,7002 cluster-config-file nodes_7000.conf #请求超时,默认15秒,可自行设置 cluster-node-timeout 8000 #开启aof持久化模式,每次写操作请求都追加到appendonly.aof文件中 appendonly yes #每次有写操作的时候都同步 appendfsync always #redis服务日志 logfile "/home/redis/local/redis-3.2.12/pid/redis.log" #pidfile文件对应7000,7001,7002 pidfile /home/redis/local/redis-3.2.12/pid/redis_7000.pid
-
编写启动节点(集群模式)脚本
$ cd /home/redis/local/redis-3.2.12/sbin/bin/ $ vi start-redis.sh
-
脚本内容
for((i=0;i<3;i++)); do /usr/local/bin/redis-server /home/redis/local/redis-3.2.12/redis-cluster/700$i/redis.conf; done
-
启动脚本
$ sh start-redis.sh
-
查看进程和端口监听
#查看是否启动成功 $ ps -ef | grep redis #可以看到redis监听端口 $ netstat -tnlp | grep redis
-
另外两台主机
# 创建用户,设置密码这些都一样 $ scp -r /home/redis/local 192.169.31.61@redis:/home/redis $ scp -r /home/redis/local 192.169.31.62@redis:/home/redis
-
需要修改的地方 redis.conf
# redis.conf # 61 主机 bind 192.168.31.61 # 62 主机 bind 192.168.31.61 # 7000端口,文件名等对应修改
-
启动集群
# 在其中一台主机 我在192.168.31.60 $ /home/redis/redis-3.2.12/src/redis-trib.rb create --replicas 1 192.168.31.60:7000 192.168.31.60:7001 192.168.31.60:7002 192.168.31.61:7000 192.168.31.61:7001 192.168.31.61:7002 192.168.31.62:7000 192.168.31.62:7001 192.168.31.62:7002
爬坑日志
-
执行make install的时候报错
/bin/sh: cc: command not found make[1]: *** [adlist.o] Error 127
原因:
redis用C语音写的,Linux系统没有安装GCC编译组件
解决:
$ yum install -y gcc g++ gcc-c++ make
-
make test 失败缺少tcl 8.5 以上版本
解决:
$ yum install tcl
-
make install 失败,/usr/local/redis/redis-server no permissions
# 使用redis账号,没权限访问该目录 # 不推荐install在这里,管理好自己的文件夹,指定自己文件夹路径 $ make install PREFIX=/home/redis/local/redis-3.2.12/sbin/
-
weg命令在centos 7.4 minimal里面没有
#这里很简单,但是当时发现了yum无法使用 引发下面坑5 $ yum install wget
-
yum仓库失效
我可能捣鼓的不一定对,但是后来yum弄好了,主要归功这篇文章。https://blog.csdn.net/shaoqiufeng/article/details/78785806,大家可以参考一下
# rpm 找到自己需要的包下载 http://mirrors.163.com/centos/ # 下载内容(对应自己系统) centos-release-7-5.1804.el7.centos.x86_64.rpm # backup $ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup # 执行命令 $ rpm -ivh centos-release-7-5.1804.el7.centos.x86_64.rpm # 如果报freely redistributed under the terms of the GNU GPL $ rpm -ivh centos-release-7-5.1804.el7.centos.x86_64.rpm --nodeps --force $ rpm -ivh yum-* $ yum clean all $ yum makecache
-
启动集群失败,Node 192.168.31.60:7000 is not empty
原因:
redis服务器会读取node.conf,dump.rdb,appendonly.aof这些文件
分别是节点信息,持久化的数据,持久化操作一些操作的日志用于系统持久化数据恢复到内存。
解决方案:
$ cd /home/redis/local/redis-3.2.12/sbin/bin $ rm *.conf $ rm *.aof $ rm *.rdb $ /home/redis/redis-3.2.12/src/redis-trib.rb create --replicas 1 192.168.31.60:7000 192.168.31.60:7001 192.168.31.60:7002 192.168.31.61:7000 192.168.31.61:7001 192.168.31.61:7002 192.168.31.62:7000 192.168.31.62:7001 192.168.31.62:7002
总结
遇到问题就查。哪怕不知道为什么可以这样解决,先记录下来吧。
我的博客为的是自己进步,也为帮别人解决问题。
欢迎随时交流。
linux操作系统多学点。
学习不是Ctrl+C+V
转载注明一下,尊重下作者,谢谢