Pika(哨兵)

Pika(哨兵)

1. 安装包

因为pika可以使用redis客户端来连接,所以需要下载redis

pika-linux-x86_64-v3.3.6.tar.bz2

redis-6.2.6.tar.gz

2. 解压

# tar -jxvf pika-linux-x86_64-v3.3.6.tar.bz2 -C /opt/
# 解压后文件名为output

# tar -zxf redis-6.2.6.tar.gz -C /opt

3. 修改配置文件

# cd output/conf

配置文件说明

pika.conf

port : 9221
thread-num : 1
thread-pool-size : 12
sync-thread-num : 6
log-path : ./log/
db-path : ./db/
write-buffer-size : 268435456
arena-block-size : 33554432
timeout : 60

# 登陆密码,通讯密码设置一致就可
requirepass : xxxxxx
masterauth : xxxxxx
userpass : xxxxxx
userblacklist : 
instance-mode : classic
databases : 1
default-slot-num : 1024
replication-num : 0
consensus-level : 0
dump-prefix : 

# 守护进程,后台运行
daemonize : yes
dump-path : ./dump/
dump-expire : 0
pidfile : ./pika.pid
maxclients : 20000
target-file-size-base : 20971520
expire-logs-days : 7
expire-logs-nums : 10
root-connection-num : 2
slowlog-write-errorlog : no
slowlog-log-slower-than : 10000
slowlog-max-len : 128
db-sync-path : ./dbsync/
db-sync-speed : 1024
slave-priority : 100

# Master不需要配置该项
# slaveof : localIP:9221

sync-window-size : 9000
max-conn-rbuf-size : 268435456


###################
## Critical Settings
###################
write-binlog : yes
binlog-file-size : 104857600
max-cache-statistic-keys : 0
small-compaction-threshold : 5000
max-write-buffer-size : 10737418240
max-write-buffer-number : 2
max-client-response-size : 1073741824
compression : snappy
max-background-flushes : 1
max-background-compactions : 2
max-cache-files : 5000
max-bytes-for-level-multiplier : 10

​ Master:不使用slaveof。

​ slaves:打开slaveof注解,slaveof : localhostIP:9221

sentinel.conf

port 26379
daemonize yes
pidfile "./../pika-sentinel.pid"
logfile "./../sentinel.log"

# 修改作为自己解压redis的位置
dir "/opt/redis-6.2.6/src"

# 使用MasterIP
sentinel monitor mymaster MasterIP 9221 2

# pika.conf中配置的有密码
sentinel auth-pass mymaster xxxxxx
acllog-max-len 128
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no

4. 远程发送

​ 注意以上配置文件的要求。

5. 启动

先启动pika,全部启动后再逐个启动哨兵。

# 启动pika
# cd output && ./bin/pika -c conf/pika.conf
# 查看pika信息
# cd redis/src && ./redis-cli info

# 启动sentinel
# cd redis/src && ./redis-sentinel /opt/output/conf/sentinel.conf
# 查看sentinel
# cd redis/src && ./redis-cli -p 26379 info sentinel

使用RDM客户端连接。

6. Exception

启动失败,可尝试用下面方法。

  1. 安装rsync,手动启动,确保正常运行,然后kill。

link:centos下安装rsync

    # mkdir /etc/rsyncd
    # touch /etc/rsyncd/rsyncd.conf          #主配置文件
    # touch /etc/rsyncd/rsyncd.secrets      #用户名密码文件,一组用户一行,用户名和密码使用 : 分割
    # chmod 0600 /etc/rsyncd/rsyncd.secrets  #rsyncd服务的密码文件权限必须是600
    # touch /etc/rsyncd/rsyncd.motd         #非必须,连接上rsyncd显示的欢迎信息,此文件可不创建
编辑rsyncd.conf
######################################################################################################
    #                      ******进程相关全局配置******
    ######################################################################################################
    # = 后面的值可根据自己的实际情况更改
    #    pid file 守护进程pid文件
    #    port 守护进程监听端口,可更改,由xinetd允许rsyncd时忽略此参数
    #    address 守护进程监听的本机ip,由xinetd允许rsyncd时忽略此参数
    pid file = /usr/local/var/run/rsyncd.pid
    port = 873
    address = 192.168.44.13
    #模块验证密码文件
    secrets file=/etc/rsyncd/rsyncd.secrets
    #rsyncd 守护进程运行系统用户全局配置,也可在具体的块中独立配置,
    uid = root
    gid = root
    #允许 chroot,提升安全性,客户端连接模块,首先chroot到模块path参数指定的目录下
    #chroot为yes时必须使用root权限,且不能备份path路径外的链接文件
    use chroot = yes
    #只读
    read only = no
    #只写
    write only = no
    #允许访问rsyncd服务的ip,ip端或者单独ip之间使用空格隔开
    hosts allow = 192.168.44.12 192.168.44.11
    #不允许访问rsyncd服务的ip,*是全部(不涵盖在hosts allow中声明的ip,注意和hosts allow的先后顺序)
    hosts deny = *
    #客户端最大连接数
    max connections = 5
    #欢迎文件路径,可选的
    #motd file = /etc/rsyncd/rsyncd.motd
    #日志相关
    #    log file 指定rsync发送消息日志文件,而不是发送给syslog,如果不填这个参数默认发送给syslog
    #    transfer logging 是否记录传输文件日志
    #    log format 日志文件格式,格式参数请google
    #    syslog facility rsync发送消息给syslog时的消息级别,
    #    timeout连接超时时间
    log file = /usr/local/logs/rsyncd.log
    transfer logging = yes
    log format = %t %a %m %f %b
    syslog facility = local3
    timeout = 300
    
    ######################################################################################################
    #                      ******模块配置(多个)******
    ######################################################################################################
    #模块 模块名称必须使用[]环绕,比如要访问mysqlData,则地址应该是mysqlDatauser@192.168.1.2::mysqlData
    [mysqlData]
    #模块根目录,必须指定
    path=/home/mysql201608/
    #是否允许列出模块里的内容
    list=yes
    #忽略错误
    ignore errors
    #模块验证用户名称,可使用空格或者逗号隔开多个用户名
    auth users = phper1021
    #注释
    comment = some description about this moudle
    #排除目录,多个之间使用空格隔开
    exclude = test1/ test2/
    
    [codeTmp]
    path = /tmp/code
    list=no
    auth users = lamper1021
编辑rsyncd.secrets
    #格式   用户名:口令,该用户不要求是系统用户
    #注意:该密码文件里面每行不要有空格,不然同步的时候一直报错auth failed on module
    phper1021:123456
    lamper1021:123456
安装rsync
    # 安装客户端
    # yum -y install rsync
    # 同步命令
    # -a 参数,相当于-rlptgoD
    #   -r 是递归 -l 是链接文件,意思是拷贝链接文件;-p 表示保持文件原有权限
    #   -t 保持文件原有时间;-g 保持文#件原有用户组;-o 保持文件原有属主;-D 相当于块设备文件
    # -z 传输时压缩;
    # -P 传输进度;
    # -v 传输时的进度等信息,和-P有点关系,自己试试。可以看文档;
启动rsync服务
    # /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf       #默认配置文件是/etc/rsyncd.conf,所以需要显式的指定配置文件
    # nohup /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf    #假设使用putty,xshell终端操作,保证终端断开进程仍然执行
    #为了保证开机时自动启动,需要手动加上面的命令(/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf)加入 /etc/rc.local 文件中
    #如果服务器开启了防火墙,必须保证端口能穿过防火墙
    # iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT
查看是否运行
    # netstat -an | grep 873
    # ps -aux|grep rsync
  1. kill rsync,重新启动pika。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值