iRedis集群搭建指南CLI实现细节(redis集群搭建 cl)

iRedis是一款功能强大的缓存数据库,经常用作分布式计算任务的一部分,用来存储和处理大量的数据。iRedis 集群的搭建方式很多,其中最简单有效的是通过 CLI 命令来搭建,下面详细介绍 iRedis 集群搭建指南:CLI 实现细节:

一、安装iRedis

1、安装必要依赖包:yum install gcc,make,gcc-c++,git,automake,ncurses-devel

2、使用git安装iRedis: git clone https://github.com/antirez/redis-stable.git

3、重新编译安装iRedis:cd redis-stable,make && make install

二、创建服务文件

1、添加服务文件:touch /etc/init.d/redis ,并将下面内容拷贝到此文件中:

#!/bin/sh
# chkconfig: - 85 15
# description: redis service
#
# processname: redis
# config: /etc/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

exec="/usr/local/bin/redis-cli"
prog="redis-cli"

REDIS_CONF_FILE="/etc/redis.conf"

[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis

start() {
[ -x $exec ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $exec $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}

reload() {
restart
}

force_reload() {
restart
}

rh_status() {
status $prog
}

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
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
#JS2OLIVER
exit $?

2、配置服务:chmod 755 /etc/init.d/redis,systemctl daemon-reload

三、搭建iRedis集群

1、配置iRedis集群:vi /etc/redis/redis.conf,在文件中修改以下配置参数:

– port 6380 #新增端口号

– cluster-enabled yes #开启iRedis集群

– cluster-config-file nodes-6379.conf #节点配置文件路径

– cluster-node-timeout 5000 #节点超时时间

– appendonly yes #开启aof持久化储存

2、修改IP绑定:vi /etc/redis.conf,绑定各个服务器IP:

– bind 127.0.0.1 #本机绑定

– bind 192.168.3.101 #服务器1绑定

– bind 192.168.3.102 #服务器2绑定

3、启动集群:

– 打开服务器1:systemctl start redis;

– 打开服务器2:systemctl start redis.2;

4、创建集群:cd /usr/local/bin,执行以下命令,创建iRedis集群:

– ./redis-cli –cluster create 192.168.3.101:6379 192.168.3.102:6380 –cluster-replicas 1 #指定集群节点,每个主节点复制的从节点数量

四、测试iRedis集群

1、管理集群:./redis-cli -c -h 192.168.3.102 -p 6380

2、查看集群状态:./redis-cli –cluster info

3、查看节点状态:./redis-cli –cluster nodes

以上就是iRedis集群搭建指南:CLI实现细节,让人看到iRedis集群搭建也不是很难,但是搭建过程中的步骤要谨慎细致,从而确定iRedis集群可以正常运行。


数据运维技术 » iRedis集群搭建指南CLI实现细节(redis集群搭建 cl)