ubuntu install redis, master-slave synchronization, uninstall

Redis installation
Direct input command

 sudo apt-get install redis-server


After the installation is complete, the Redis server will start automatically.
Use the ps -aux|grep redis command to see the default port 6379 of the server system process

redis      2890  0.2  0.1  41872  6064 ?        Ssl  14:17   0:07 /usr/bin/redis-server 127.0.0.1:6379     hzlarm     3222  0.0  0.0  11324   780 pts/2    S+   15:02   0:00 grep --color=auto redis 

Use the netstat -nlt|grep 6379 command to see the redis server status
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
Use the sudo /etc/init.d/redis-server status command to see the Redis server status

Insert picture description here

The basic configuration of the Redis server The
configuration file is /etc/redis/redis.conf

First, sudo vi /etc/redis/redis.conf
adds the Redis access account.
Redis server does not require a password by default, assuming that the password is set to abc.
Remove the comment # in front of
requirepass and add the password requirepass abc at the back

Open Redis remote connection
Comment out the binding address #bind 127.0.0.1

Modify Redis's default port
port 6379

Redis runs as a daemon process.
If it runs as a daemon process, it will not block on the command line, similar to a service.
If it runs as a non-daemon process, the current terminal is blocked and cannot be used. It is
recommended to change to yes and run
daemonize no|yes as a daemon process
Redis data file
dbfilename dump.rdb

Data file storage path
dir /var/lib/redis

Restart the server after the configuration is complete
sudo /etc/init.d/redis-server restart or
sudo service redis-server restart or
sudo redis-server /etc/redis/redis.conf

Master-slave configuration
A master can have multiple slaves, and a slave can have multiple slaves. In this way, a powerful multi-level server cluster architecture is formed. For
example, the machine with ip 192.168.220.135 is used as the master server, and the ip is 192.168 .220.123 machine as the slave server to
set the configuration of the master server
sudo vi /etc/redis/redis.conf modify the binding ip
bind 192.168.220.135 restart the redis server

Set the configuration of the slave server
sudo vi /etc/redis/redis.conf Note: write the host ip after slaveof, and then write the port, and the port must be written
bind 192.168.220.123
slaveof 192.168.220.135 6379
restart the redis server

Start the client redis-cli -h after the modified ip
, execute the info command on the master and slave respectively, and view the output information
. Write data on the master
set ab
and read data on the slave
get a

Redis installation configuration server starts client data operation publish subscription master-slave configuration uninstall Redis

Uninstall redis
sudo apt-get remove redis-server
sudo apt-get autoremove --purge redis-server

Possible problems

Solution
Modify the configuration file
vim /etc/redis/redis.conf of the   redis server to
 
comment the following bound host address
# bind 127.0.0.1


Modify the parameter configuration of redis server
 daemonize "no"
 
Modify the protection mode of redis to no, do not enable

protected-mode "no"

After restarting the server:

problem solved