[The NoSQL Database] from the Redis master deployment

A, Redis master from

What is the use Redis master-slave:

1. Back up data: using slave node to back up the data master node, thus avoiding the master node goes down all result in data loss.

2. separate read and write: Master node only responsible for writing, while the slave node is responsible only for reading. Ratio, for example, the reader 10: 1, so that the efficiency can be improved.

As shown below:

A Master can have multiple Slave, and each can have multiple Slave Slave, so that you can form a powerful server cluster structure.

 

Two, Redis master node configuration

1.Redis source compiler installation

In CentOS7:

Copy the code
# Installed gcc compiler 
yum the install gcc -Y 
# download Redis 
wget http://download.redis.io/releases/redis-5.0.7.tar.gz 
# decompress 
the tar-5.0.7.tar.gz the xzf Redis 
# move the folder to / usr / local in 
mv redis-5.0.7 / usr / local / 
# redis into the directory 
cd /usr/local/redis-5.0.7 
# compiler 
make all
Copy the code
# Install TCL 
yum -y install TCL 
# redis test run 
make test
# Mounted to the / usr / local / bin 
the make the install

Enter / under usr / local / bin View installed redis command:

Copy the code
[root@centos-base bin]# ll
total 32772
-rwxr-xr-x. 1 root root 4366808 Jan  5 14:20 redis-benchmark
-rwxr-xr-x. 1 root root 8125200 Jan  5 14:20 redis-check-aof
-rwxr-xr-x. 1 root root 8125200 Jan  5 14:20 redis-check-rdb
-rwxr-xr-x. 1 root root 4807880 Jan  5 14:20 redis-cli
lrwxrwxrwx. 1 root root      12 Jan  5 14:20 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8125200 Jan  5 14:20 redis-server
Copy the code

 

2.Redis Configuration

Copy redis.conf:

cd /etc
mkdir redis
cd /usr/local/redis-5.0.7
cp redis.conf /etc/redis/redis.conf

Change setting:

we /etc/redis/redis.conf
Copy the code
bind 192.168.1.181 127.0.0.1 # service IP address 
port 6379 # service port 
daemonize yes # is running as a daemon form 
dbfilename dump.rdb # persistent data file name 
dir / var / lib / redis # persistent data files and 
logfile /var/log/redis/redis-server.log # log file location 
database 16 # total database 16, No. 15 ~. 1 
slaveof # of the primary and replication (for distributed)
Copy the code

Note: The persistent storage of address data files and log files previously created to store the file directory.

cd / var / lib 
mkdir redis 
cd / var / log 
mkdir redis

 

Configuration File Reference:

(Transfer from https://blog.csdn.net/ljphilp/article/details/52934933 )

  View Code

 

3. Set Redis service

Configuration Management systemctl Redis service:

Copy the code
Edit the file # 
vim /usr/lib/systemd/system/redis.service 

# in redis.service file and add the following to save 

###################### #### 

[Unit] 
the Description = the Redis-5.0.7-6379 
the After network.target = 

[-Service] 
the Type = the forking 
PIDFILE = / var / RUN / redis-6379.pid 
ExecStart = / usr / local / bin / redis- /etc/redis/redis.conf Server 
ExecReload = / bin / -s the kill the HUP $ MAINPID 
ExecStop = / bin / -s the kill the QUIT $ MAINPID 
PrivateTmp to true = 

[the Install] 
WantedBy = multi-user.target 

###### ##################### 

# load service 
systemctl daemon-reload
Copy the code

 

reids service operation:

systemctl start redis # start 
systemctl stop redis # stop 
systemctl restart redis # restart 
systemctl status redis # view the status 
systemctl enable redis # boot 
systemctl disable redis # cancel boot

 

4. Run Redis

Copy the code
[root@centos-base system]# systemctl start redis
[root@centos-base system]# systemctl status redis
鈼[0m redis.service - Redis-5.0.7-6379
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-01-05 15:19:46 CST; 4s ago
  Process: 27232 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 27243 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 27244 (redis-server)
   CGroup: /system.slice/redis.service
           鈹斺攢27244 /usr/local/bin/redis-server 127.0.0.1:6379

Jan 05 15:19:46 centos-base systemd[1]: Starting Redis-5.0.7-6379...
Jan 05 15:19:46 centos-base systemd[1]: Started Redis-5.0.7-6379.
Copy the code

View process:

[root@centos-base system]# ps -ef | grep redis
root      27244      1  0 15:19 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root      27251  17132  0 15:22 pts/0    00:00:00 grep --color=auto redis

 

 

Three, Redis from node configuration

1. Installation from node Redis

Referring to the master node during installation, deployment from a node.

2. From node configuration

Redis.conf modify the configuration file:

# Replicaof modify configuration items, fill in the master node IP and port 
replicaof 192.168 . 1.181  6379

3. Restart from the master node Redis service

 

Fourth, the master-slave operation

1. See the master node status

Excuting an order:

[root@centos-base system]# redis-cli -h 192.168.1.181 info Replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.1.180,port=6379,state=online,offset=42,lag=1
master_replid:14e0a788c85de285ae34ab98f41893aaf097335a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:42
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:42

It can be seen that the node is the master node, connected from a node has, from the IP node is 192.168.1.180, port 6379.

 

2. Check the node status

Excuting an order:

[root@centos-base system]# redis-cli -h 192.168.1.180 info Replication 
# Replication
role:slave
master_host:192.168.1.181
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:546
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:14e0a788c85de285ae34ab98f41893aaf097335a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:546
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:546

It can be seen that the node is a slave node, the master node belonging to 192.168.1.181, the master node port 6379.

 

3. Data from the master operation

Setting a value in the master node:

[root@centos-base system]# redis-cli -h 192.168.1.181 -p 6379
192.168.1.181:6379> select 10
OK
192.168.1.181:6379[10]> set name helloworld
OK

We set up a master node name value helloworld.

 

In the name of obtaining value from the node:

[root@centos-base system]# redis-cli -h 192.168.1.180 -p 6379
192.168.1.180:6379> select 10
OK
192.168.1.180:6379[10]> get name
"helloworld"

It can be seen from the obtained value of the name of the node, as helloworld.

 

This shows that, after the master node intervening value, will automatically synchronize to the node .

 

When the master node survival, using interpolated values ​​from the node:

192.168.1.180:6379[10]> set age 32
(error) READONLY You can't write against a read only replica.

We can see that in the survival of the master node, the node from the read-only (read only) a.

Guess you like

Origin www.cnblogs.com/leokale-zz/p/12153822.html