Redis Standalone
info
# Redis singleton info
version: 6.2.5
address: 192.101.11.72:7700
password: hlrdscls
data: /opt/tools/redis625/redis-singleton/7700
install path: opt/tools/redis625/redis-singleton
info-test
# Redis singleton-test info
version: 6.2.5
address: 192.101.11.72:7701
password: hlrdscls
data: /opt/tools/redis625/redis-singleton-test/7701
install path: opt/tools/redis625/redis-singleton-test
download
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
install
first install tcl for redis runtest
cp tcl8.6.1-src.tar.gz /usr/local/
tar -xzvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix
./configure
make
make install
install redis
tar -xzvf redis-6.2.5.tar.gz
cd redis-6.2.5
make
./runtest
add redis path
vi /etc/profile
export PATH=$PATH:the/redis/install/path/src
configure
mkdir -p redis-singleton/7700
mkdir -p redis-singleton-test/7701
redis.conf 示例
daemonize yes
port 7701 #(分别对每个机器的端口号进行设置)
dir /opt/tools/redis625/redis-singleton-test/7701/ #(指定数据文件存放位置,必须要指定不同的目录位置,不然会丢失数据)
cluster-enabled no #(启动集群模式)
cluster-config-file nodes-7701.conf #(集群节点信息文件,这里800x最好和port对应上)
cluster-node-timeout 5000
bind * -::1 #(default 全监听)
protected-mode no #(关闭保护模式)
appendonly yes
#如果要设置密码需要增加如下配置:
requirepass hlrdscls # (设置redis访问密码)
#masterauth hlrdscls # (设置集群节点间访问密码,跟上面一致)
每个实例修改对应的端口和数据目录
start redis instances
redis-server ./redis-singleton/7700/redis.conf
redis-server ./redis-singleton-test/7701/redis.conf
shutdown cluster
redis-cli -a hlrdscls -c -h 192.101.11.72 -p 7700 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.72 -p 7701 shutdown;
restart
redis-server ./redis-singleton/7700/redis.conf
redis-server ./redis-singleton-test/7701/redis.conf
Redis Cluster
info
# Redis Cluster info
version: 6.2.5
address:192.101.11.67:7701,192.101.11.67:7702,192.101.11.67:7703,192.101.11.68:7704,192.101.11.68:7705,192.101.11.68:7706
password: hlrdscls
data: opt/tools/redis625/redis-cluster/7701
opt/tools/redis625/redis-cluster/7702
opt/tools/redis625/redis-cluster/7703
opt/tools/redis625/redis-cluster/7704
opt/tools/redis625/redis-cluster/7705
opt/tools/redis625/redis-cluster/7706
info: redis-cli -a hlrdscls --cluster info 192.101.11.67:7701
install path: opt/tools/redis625
info-test
# Redis Cluster info
version: 6.2.5
address:192.101.11.71:7701,192.101.11.71:7702,192.101.11.71:7703,192.101.11.72:7704,192.101.11.72:7705,192.101.11.72:7706
password: hlrdscls
data: opt/tools/redis625/redis-cluster/7701
opt/tools/redis625/redis-cluster/7702
opt/tools/redis625/redis-cluster/7703
opt/tools/redis625/redis-cluster/7704
opt/tools/redis625/redis-cluster/7705
opt/tools/redis625/redis-cluster/7706
info: redis-cli -a hlrdscls --cluster info 192.101.11.71:7701
install path: opt/tools/redis625
select Redis Cluster mode rather than Redis Sentinel mode as the Redis cluster for best horizonal expansions.
two port int the firewall, such as 6379 and 16379, must be opened for command and clustering, respectively.
the minimal cluster that works as expected requires to contain at least three master nodes. For your first tests it is strongly suggested to start a six nodes cluster with three masters and three slaves.
download
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
install
first install tcl for redis runtest
cp tcl8.6.1-src.tar.gz /usr/local/
tar -xzvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix
./configure
make
make install
install redis
tar -xzvf redis-6.2.5.tar.gz
cd redis-6.2.5
make
./runtest
add redis path
vi /etc/profile
export PATH=$PATH:the/redis/install/path/src
create cluster
示例:在两台机器上搭建3主3从 redis 节点
configure
每台机器启动三个 redis 实例
分别新建三个目录,新建三个 redis.conf
如:
192.101.11.67
mkdir 7701 7702 7703
192.101.11.68
mkdir 7704 7705 7706
redis.conf 示例
daemonize yes
port 7701 #(分别对每个机器的端口号进行设置)
dir /opt/tools/redis625/redis-cluster/7701/ #(指定数据文件存放位置,必须要指定不同的目录位置,不然会丢失数据)
cluster-enabled yes #(启动集群模式)
cluster-config-file nodes-7701.conf #(集群节点信息文件,这里800x最好和port对应上)
cluster-node-timeout 5000
bind * -::1 #(default 全监听)
protected-mode no #(关闭保护模式)
appendonly yes
#如果要设置密码需要增加如下配置:
requirepass hlrdscls # (设置redis访问密码)
masterauth hlrdscls # (设置集群节点间访问密码,跟上面一致)
每个实例修改对应的端口
start redis instances
redis-server ./7701/redis.conf
redis-server ./7702/redis.conf
redis-server ./7703/redis.conf
redis-server ./7704/redis.conf
redis-server ./7705/redis.conf
redis-server ./7706/redis.conf
create cluster
open the port for firewall if the firewall has been enabled.
firewall-cmd --zone=public --add-port=7701/tcp --permanent
firewall-cmd --zone=public --add-port=7702/tcp --permanent
firewall-cmd --zone=public --add-port=7703/tcp --permanent
firewall-cmd --zone=public --add-port=17701/tcp --permanent
firewall-cmd --zone=public --add-port=17702/tcp --permanent
firewall-cmd --zone=public --add-port=17703/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --add-port=7704/tcp --permanent
firewall-cmd --zone=public --add-port=7705/tcp --permanent
firewall-cmd --zone=public --add-port=7706/tcp --permanent
firewall-cmd --zone=public --add-port=17704/tcp --permanent
firewall-cmd --zone=public --add-port=17705/tcp --permanent
firewall-cmd --zone=public --add-port=17706/tcp --permanent
firewall-cmd --reload
redis-cli -a hlrdscls --cluster create --cluster-replicas 1 192.101.11.67:7701 192.101.11.67:7702 192.101.11.67:7703 192.101.11.68:7704 192.101.11.682:7705 192.101.11.68:7706
shutdown cluster
redis-cli -a hlrdscls -c -h 192.101.11.67 -p 7701 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.67 -p 7702 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.67 -p 7703 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.68 -p 7704 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.68 -p 7705 shutdown;
redis-cli -a hlrdscls -c -h 192.101.11.68 -p 7706 shutdown;
check cluster
redis-cli -a hlrdscls --cluster info 192.101.11.67:7701
restart cluster
redis-server ./7701/redis.conf
redis-server ./7702/redis.conf
redis-server ./7703/redis.conf
redis-server ./7704/redis.conf
redis-server ./7705/redis.conf
redis-server ./7706/redis.conf