Redis series-Remotely connect to redis and lock redis

Source: Internet
Author: User
Tags redis server

Assume that the two redis servers have ip addresses 192.168.1.101 and 192.168.1.103 respectively. How can I access redis on redis 101 through redis-cli on redis 103? Before remotely connecting to redis 103, let's talk about several key parameters of redis-cli:

Usage: redis-cli [OPTIONS] [cmd [arg [arg...]

-H <Host ip address>. The default value is 127.0.0.1.

-P <port>. The default value is 6379.

-A <password>: If redis is locked, the password must be passed.

-- Help: displays help information.

Through the introduction of rendis-cli usage, connecting to 101 on 103 should be simple:

[Root @ bkjia001 ~] # Redis-cli-h 192.168.1.103-p 6379

Redis 192.168.1.103: 6379>

Set each string value user.1.name = zhangsan for 101 on 103.

Redis 192.168.1.103: 6379> set user.1.name zhangsan

OK

If OK is displayed, the setting is successful. Then, log on to MySQL 103 directly to see if this value can be obtained.

[Root @ bkjia003 utils] # redis-cli

Redis 127.0.0.1: 6379> get user.1.name

"Zhangsan"

It is indeed zhangsan, which means that the redis server on 101 is connected to the redis server on 103. Of course, there are basic conditions for successful connection to port 103, and port 101 on port 103 can be used for communication.

It is very dangerous for everyone to connect to the redis server. We need to set a password for redis on 103. How should we set it? We need to edit the redis configuration file/etc/redis/6379. conf.

[Root @ bkjia003 utils] # vim/etc/redis/6379. conf

Find # requirepass foobared and remove the comment #, and replace foobared with your own password: hi, coder

Requirepass "hi, coder"

After saving the configuration file, restart the redis service.

[Root @ bkjia003 utils] #/etc/init. d/redis_6379 stop
Stopping...
Waiting for Redis to shutdown...
Redis stopped
[Root @ bkjia003 utils] #/etc/init. d/redis_6379 start
Starting Redis server...

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.