redis主从

主机名

ip

node01(主)

192.168.6.71

node02(从)

192.168.6.72

  • 分别在两台机器上面安装redis
wget https://codeload.github.com/antirez/redis/tar.gz/2.8.21
  mv 2.8.21  redis-2.8.21.tar.gz
  rsync -av redis-2.8.21.tar.gz node02:/root/
  tar xf redis-2.8.21.tar.gz -C  /usr/local/src/
  cd /usr/local/src/
  cd redis-2.8.21/
  make
  make PREFIX=/usr/local/redis   install
 useradd -s /sbin/nologin redis
 mkdir /usr/local/redis/etc/
  mkdir /usr/local/redis/var/
  vim /etc/init.d/redis
#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:   - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
name="redis-server"
basedir="/usr/local/redis"
exec="$basedir/bin/$name"
pidfile="$basedir/var/redis.pid"
REDIS_CONFIG="$basedir/etc/redis.conf"
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
  echo -n $"Starting $name: "
    daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
  retval=$?
  echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
  echo -n $"Stopping $name: "
    killproc -p $pidfile $name
  retval=$?
  echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
  stop
  start
}
reload() {
  false
}
rh_status() {
    status -p $pidfile $name
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
  start)
        rh_status_q && exit 0
  $1
        ;;
  stop)
        rh_status_q || exit 0
  $1
        ;;
  restart)
  $1
        ;;
    reload)
        rh_status_q || exit 7
  $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
  restart
        ;;
    *)
  echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
  exit 2
esac
exit $?
  chmod 755 /etc/init.d/redis
  chmod 777 /usr/local/redis/var
  service redis start
  vim /etc/profile
  export PATH=/usr/local/redis/bin/:$PATH
  vim  /usr/local/redis/etc/redis.conf
daemonize yes
pidfile /usr/local/redis/var/redis.pid
port 6379
timeout 300
loglevel debug
logfile /usr/local/redis/var/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /usr/local/redis/var/
appendonly no
appendfsync always
  启动redis
  ps aux | grep redis
redis      4435 0.0  0.7 137376 7472 ?        Ssl  13:45   0:00 /usr/local/redis/bin/redis-server *:6379                         
root       4440 0.0  0.0 103304 892 pts/0    S+ 13:45   0:00 grep redis  
  • 主从配置

主[root@node01]# vim /usr/local/redis/etc/redis.confdaemonize yespidfile /usr/local/redis/var/redis.pidport 6379timeout 300loglevel debuglogfile /usr/local/redis/var/redis.logdatabases 16save 900 1save 300 10save 60 10000rdbcompression yesdbfilename dump.rdbdir /usr/local/redis/var/appendonly noappendfsync alwaysrequirepass alex从[root@node02 ~]# vim /usr/local/redis/etc/redis.confdaemonize yespidfile /usr/local/redis/var/redis.pidport 6379timeout 300loglevel debuglogfile /usr/local/redis/var/redis.logdatabases 16save 900 1save 300 10save 60 10000rdbcompression yesdbfilename dump.rdbdir /usr/local/redis/var/appendonly noappendfsync alwaysslaveof 192.168.6.71 6379masterauth alex

  • 重启服务 [root@node01 ~]# service redis restart[root@node02 ~]# service redis restart
  • 查看日志 [root@node01]# tailf /usr/local/redis/var/redis.log[4507] 19 Jun 13:58:55.688 - Accepted 192.168.6.72:45249[4507] 19 Jun 13:58:55.689 * Slave 192.168.6.72:6379 asks for synchronization[4507] 19 Jun 13:58:55.689 * Full resync requested by slave 192.168.6.72:6379[4507] 19 Jun 13:58:55.690 * Starting BGSAVE for SYNC with target: disk[4507] 19 Jun 13:58:55.690 * Background saving started by pid 4512[4512] 19 Jun 13:58:55.702 * DB saved on disk[4512] 19 Jun 13:58:55.702 * RDB: 6 MB of memory used by copy-on-write[4507] 19 Jun 13:58:55.747 * Background saving terminated with success
  • 测试数据 [root@node01 redis]# redis-cli -a alex127.0.0.1:6379> keys *(empty list or set)127.0.0.1:6379> set key1 alexOK127.0.0.1:6379> get key1"alex"127.0.0.1:6379> sadd set1 123(integer) 1127.0.0.1:6379> sadd set1 222(integer) 1127.0.0.1:6379> sad set1 333(error) ERR unknown command 'sad'127.0.0.1:6379> sadd set1 333(integer) 1127.0.0.1:6379> keys *1) "key1"2) "set1"[root@node02 ~]# redis-cli -a alex127.0.0.1:6379> keys *1) "key1"2) "set1"127.0.0.1:6379> SMEMBERS set11) "123"2) "222"3) "333"127.0.0.1:6379> get key1"alex"
    • 成功了

原文发布于微信公众号 - 从零开始的linux(gh_4a9d788f5f27)

原文发表时间:2017-06-19

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏华仔的技术笔记

Boinc for Linux,在服务器上一边科研,一边挖矿

https://www.toutiao.com/i6589514965932048910/

3851
来自专栏圣杰的专栏

.NET Core+MySql+Nginx 容器化部署

1. 引言 上两节我们通过简单的demo学习了docker的基本操作。这一节我们来一个进阶学习,完成ASP.NET Core + MySql + Nginx的容...

4388
来自专栏Golang语言社区

使用Docker和热加载运行Go API

This is a quick discussion of how to set up a local development environment for ...

1311
来自专栏FreeBuf

使用Docker构建Web渗透测试工具容器

? Docker是世界领先的软件集装化平台,针对不同的渗透测试类型,我们完全可以使用Docker创建相应的环境。有了Docker容器,你可以把测试环境放到U盘...

3059
来自专栏我的博客

ThinkPHP3.2使用cli模式

php if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); ...

4916
来自专栏杨建荣的学习笔记

使用shell定制awr脚本(r3笔记第32天)

大家在做性能问题诊断的时候,awr是不可或缺的工具,使用?/rdbms/admin/awrrpt.sql可能大家使用的多了,可能有时候感觉输入参数还是有些太繁琐...

2884
来自专栏木制robot技术杂谈

Ubuntu 使用 Docker 安装 Gitlab

最近帮公司重新搭建了 Gitlab,中间遇到了一些坑,折腾了不少时间,在此记录供大家参考。

3614
来自专栏乐沙弥的世界

CRS-1006 , CRS-0215 故障一例

    安装好sles 10 sp3 + Oracle 10g RAC之后,在配置监听器时,总是提示主机bo2dbp上的监听服务已经在运行,忽略错误之后手动在b...

693
来自专栏散尽浮华

openstack虚拟机迁移的操作记录

需求说明: 计算节点linux-node1.openstack:192.168.1.8   计算节点linux-node2.openstack:192.168....

7899
来自专栏landv

烽火R2600交换机配置脚本

1582

扫码关注云+社区

领取腾讯云代金券