- Android
- Ios
- Javascript
- HTML5
- Css
- Jquery
- Python
- Php
- NodeJS
- Java
- Spring
- Mysql
- Mongodb
- Redis
- Nosql
- Vim
- C++
- C#
- Json
- Ruby
- Linux
- Nginx
- Docker
All categories > Database related > NoSQL database nosql redis Advanced Utility Commands-Security and master-slave replicationNoSQL Redis 2014-01-09 22:52:47 released
Collection1 Collection
First, security
Set a password for Redis: a password that needs to be applied before any other designations are set after the client connects.
Warning: Because Redis is very fast, under a better server, an external user can make a 150k password attempt in a second, which means you need to specify a very strong password to prevent brute force.
Ways to change your password:
Just open Requirepass in Redis profile redis.conf, like I set my access password to MyPassword
Requirepass MyPassword
After adding this line of code in redis.conf, we killed the original Redis process: Pkill Redis and then restarted redis:/usr/local/redis-2.8.1/src/redis-server/user/local/ Redis-2.8.1/redis.conf
We can then use/USR/LOCAL/REDIS-2.8.1/SRC/REDIS-CLI to find the login, but when we do the operation, such as the keys * will be the following error:
127.0.0.1:6379> keys *
(Error) Noauth Authentication required.
There is no need for authorization validation.
Here Redis supports two modes of authorization, one that is authorized directly with the AUTH command:
The first time I entered a wrong password test, authorization failed, the second time to enter the correct password, return OK, authorization is successful, then you can do all the operation.
If we don't want to use AUTH for authorization every time we log in, we can use another authorization method, that is, when we log in to the client, we use-A to specify the password.
sh-3.2#/usr/local/redis-2.8.1/src/redis-cli-a MyPassword
If the above password is wrong, it can be entered, but cannot be manipulated afterwards. Need to re-authorize with Auth.
Second, master-slave replication
Redis Master-slave replication configuration and usage are simple. Master-slave replication allows multiple slave servers to have the same database copy as master server.
Features of Redis master-slave replication:
1. One master can have multiple slave (1-to-many relationships)
2. Multiple slave can connect to the same master, and can also connect to other slave (this is done because if one of the slave is masterdown off, it can immediately act as master, so the entire service flow is unaffected)
3. From replication does not block master, while synchronizing the data, Master can continue to process client requests.
4. Improve the scalability of the system
Redis master-slave replication process:
1.slave Connect with master and send Sync Sync command.
2.Master initiates a background process, saves the database snapshot to a file, and the master master process starts collecting the new write commands and caches them.
3. After the background is finished saving, send the file to slave
4.slave saving files to your hard disk
Configure the master-slave server:
Configuring the slave server is simple, just add the following configuration to the slave configuration file:
Slaveof Masterip Masterport
If the host is enabled for login verification, you will need to add the following sentence:
Masterauth Authpassword
Then start the slave, first the main opportunity to send a snapshot to the slave, the slave database will be updated to the same state as the host, and then write to the host, the slave will also be updated with it.
If we write the data from the machine, then we get an error:
(Error) READONLY you can ' t write against a read only slave.
We can use the Info command to view the information of the master-slave server, which can be seen with the info command on the slave machine.
Role:slave
Master_host:masterip
Master_port:masterport
Master_link_status:up proof and host in connected state
Use the Info command on the host
Role:master
Connected to several slave machines at the same time
Connected_slaves:1
You can also view the IP and online status of the slave connected to the host
Slave0:ip=192.168.1.107,port=6379,state=online,offset=1709,lag=1
Original address: http://blog.csdn.net/liutingxu1/article/details/17116107
A detailed description of the NoSQL Redis Advanced Utility Command-security and master-slave replication