redis上线 准备(安装遇到的问题+优化)


Redis上线(安装,主从复制,高可用,优化项注意事项)


1.内核目录为空 ,手动安装
yum install kernel-devel,安装完成后ls命令查看
[root@cloudstack01 include]# ls /usr/src/kernels/
2.6.32-642.6.2.el6.x86_64


2.redis通过VIP 连接redis
执行命令:redis-cli -h 192.168.1.45 INFO
connected_slaves:1
slave0:ip=192.168.1.252,port=6379,state=online,offset=15,lag=1


3.查看redis主库角色:
   ./redis-cli  -h 192.168.1.29 info   
   可见:
   role:master
connected_slaves:1
slave0:ip=192.168.1.252,port=6379,state=online,offset=273,lag=1
 查看redis从库角色:
   # Replication
role:slave
master_host:192.168.1.29
master_port:6379


4.redis 依赖gcc,Linux 基本操作系统basic system下安装redis ,需要先安装gcc
yum install gcc -y
5.redis安装步骤make时候报错:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
处理方式:make MALLOC=libc
6.关闭redis: killall -9 redis-server 开启 nohup ./redis-server &
7.如果主库因为异常down机,从库将接管主库,角色转换为主库,继续提供服务,等待主库恢复以后,可以重启keepalived 原来的主库再切换回来充当主库的角色,从库还继续充当从库;




8.redis优化
(1)# 默认情况下 redis 不是作为守护进程运行的,如果你想让它在后台运行,你就把它改成 yes。
# 当redis作为守护进程运行的时候,它会写一个 pid 到 /var/run/redis.pid 文件里面。
daemonize no      -------优化1 -----》daemonize yes


(2)# 指定在一个 client 空闲多少秒之后关闭连接(0 就是不管它)
timeout 0         -------优化2------> timeout 300
 
(3)# tcp 心跳包。
#
# 如果设置为非零,则在与客户端缺乏通讯的时候使用 SO_KEEPALIVE 发送 tcp acks 给客户端。
# 这个之所有有用,主要由两个原因:
#
# 1) 防止死的 peers
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 60 seconds.
# 推荐一个合理的值就是60秒
tcp-keepalive 0   ----------优化3-----> tcp-keepalive 60


(4)# 定义日志级别。
# 可以是下面的这些值:
# debug (适用于开发或测试阶段)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (适用于生产环境)
# warning (仅仅一些重要的消息被记录)
loglevel notice
(5)# 指定日志文件的位置
logfile ""       ----------优化4-----> logfile "/var/log/redis/redis.log"
(6)# 要想把日志记录到系统日志,就把它改成 yes,
# 也可以可选择性的更新其他的syslog 参数以达到你的要求
# syslog-enabled no
(7)# 设置数据库的数目。
# 默认数据库是 DB 0,你可以在每个连接上使用 select <dbid> 命令选择一个不同的数据库,
# 但是 dbid 必须是一个介于 0 到 databasees - 1 之间的值
databases 16
(8)################################ 快照 ################################
#
# 存 DB 到磁盘:
#
#   格式:save <间隔时间(秒)> <写入次数>
#
#   根据给定的时间间隔和写入次数将数据保存到磁盘
#
#   下面的例子的意思是:
#   900 秒内如果至少有 1 个 key 的值变化,则保存
#   300 秒内如果至少有 10 个 key 的值变化,则保存
#   60 秒内如果至少有 10000 个 key 的值变化,则保存
#  
#   注意:你可以注释掉所有的 save 行来停用保存功能。
#   也可以直接一个空字符串来实现停用:
#   save ""
 
save 900 1
save 300 10
save 60 10000
(9)# 默认情况下,如果 redis 最后一次的后台保存失败,redis 将停止接受写操作,
# 这样以一种强硬的方式让用户知道数据不能正确的持久化到磁盘,
# 否则就会没人注意到灾难的发生。
#
# 如果后台保存进程重新启动工作了,redis 也将自动的允许写操作。
#
# 然而你要是安装了靠谱的监控,你可能不希望 redis 这样做,那你就改成 no 好了。
stop-writes-on-bgsave-error yes


(10)是否在 dump .rdb 数据库的时候使用 LZF 压缩字符串
# 默认都设为 yes
# 如果你希望保存子进程节省点 cpu ,你就设置它为 no ,
# 不过这个数据集可能就会比较大
rdbcompression yes
(11)# 是否校验rdb文件
rdbchecksum yes
(12)# 设置 dump 的文件位置
dbfilename dump.rdb
(13)# 工作目录
# 例如上面的 dbfilename 只指定了文件名,
# 但是它会写入到这个目录下。这个配置项一定是个目录,而不能是文件名。
dir ./
(14)################################# 主从复制 #################################
 
# 主从复制。使用 slaveof 来让一个 redis 实例成为另一个reids 实例的副本。
# 注意这个只需要在 slave 上配置。
#
 slaveof <masterip> <masterport>
 (15)# 如果 master 需要密码认证,就在这里设置
# masterauth <master-password>
(16)# 当一个 slave 与 master 失去联系,或者复制正在进行的时候,
# slave 可能会有两种表现:
#
# 1) 如果为 yes ,slave 仍然会应答客户端请求,但返回的数据可能是过时,
#    或者数据可能是空的在第一次同步的时候
#
# 2) 如果为 no ,在你执行除了 info he salveof 之外的其他命令时,
#    slave 都将返回一个 "SYNC with master in progress" 的错误,
#
slave-serve-stale-data yes
 (17)# 你可以配置一个 slave 实体是否接受写入操作。
# 通过写入操作来存储一些短暂的数据对于一个 slave 实例来说可能是有用的,
# 因为相对从 master 重新同步数而言,据数据写入到 slave 会更容易被删除。
# 但是如果客户端因为一个错误的配置写入,也可能会导致一些问题。
#
# 从 redis 2.6 版起,默认 slaves 都是只读的。
#
# Note: read only slaves are not designed to be exposed to untrusted clients
# on the internet. It's just a protection layer against misuse of the instance.
# Still a read only slave exports by default all the administrative commands
# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
# security of read only slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
# 注意:只读的 slaves 没有被设计成在 internet 上暴露给不受信任的客户端。
# 它仅仅是一个针对误用实例的一个保护层。
slave-read-only yes
(18)redis最大连接数
# 一旦达到最大限制,redis 将关闭所有的新连接
# 并发送一个‘max number of clients reached’的错误。
(19)# 最大使用内存,redis的maxmemory参数用于控制redis可使用的最大内存容量。如果超过maxmemory的值,就会动用淘汰策略来处理expaire字典中的键
# maxmemory <bytes>
(20) #是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按照上面save条件来进行同步的,所以有的数据会在一段时间内只存在于内存中。默认是no
       appendonly no   --------优化----> appendonly yes
       
 (21) 同步方式,三种:(默认是everysec)
 
       
# no: don't fsync, just let the OS flush the data when it wants. Faster. //等待OS进行数据缓存同步到硬盘


# always: fsync after every write to the append only log . Slow, Safest. //每次更新操作后调用fsync()将数据写到磁盘


# everysec: fsync only if one second passed since the last fsync. Compromise. //每秒同步一次


appendfsync everysec 
(22)no-appendfsync-on-rewrite no (默认是no)
#yes : 在日志重写时,不进行命令追加操作,而只是将其放在缓冲区里,避免与命令的追加造成DISK IO上的冲突。
#no : 在日志重写时,命令追加操作照常进行
(23)keepalived 日志默认写到系统日志/var/log/messages










































































































































































mongodb启动:./mongod -f /usr/local/slave/mongodb/conf/mongodb.conf
       关闭:./mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()" 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值