Configure the Redis extranet to access

Source: Internet
Author: User

Environment Description

Redis service installed in Linux

The XAMPP environment is installed in Windows . For PHP to run

The PHP code is as follows:

<?php    $redisnew Redis();    $redis->connect(‘192.168.1.4‘6379);    $redis->set(‘tag‘‘hello‘);    echo‘name:‘$redis->get(‘tag‘);

When executing the above code, the error is as follows:

Fatal error:uncaught exception ' redisexception ' with message ' Redis server went away ' in xxxx

Redisexception:redis server went away in xxxxxx

Analysis and solution of error of solution

The reason for the error is simply that the Redis service is not connected, and because of the security policy adopted by Redis, only local access is allowed by default. You need to allow extranet access through a simple configuration.

    • Modify the Redis configuration file to block all bind information.

      # bind 192.168.1.100 10.0.0.1
      # bind 192.168.1.8
      # bind 127.0.0.1

      After the modification is complete, you will need to restart the Redis service.

    • Modified Linux Firewall (iptables), turn on your Redis service port, default is 6379

      -A input-m state–state new-m tcp-p tcp–dport 6379-j ACCEPT
      ......
      -A input-j Reject–reject-with icmp-host-prohibited

      Note that you must put the Redis firewall configuration in REJECT front of it. And then executeservice iptables restart

Now, by accessing the code just above, you can link to the Redis service and display it correctly.

about Bind

Turn to the article on the Internet, where the translation is "specify that Redis receives only requests from that IP address, and if not set, all requests will be processed, preferably in a production environment." This explanation will totally confused beginners, even wrong. The English language of the office is

# If you want your can bind a single interface if the BIND option isn't
# specified all the interfaces would listen for incoming connections.
# bind 127.0.0.1

This indicates that Bind is interface, which means the network interface. The server can have a network interface (commonly said NIC), or more. For example, there are two network cards on the machine, 192.168.205.5 and 192.168.205.6, if bind 192.168.205.5, then only the network card address accepts external requests, if not bound, then two network card ports accept the request.

OK, don't know to speak clearly no, in cite an example. In my experiment, I commented out the bind item, and I actually had a solution. Because the address of my Redis server is 192.168.1.4 . If I don't comment on the bind item, what's the alternative? I can do the following configuration:

# bind 192.168.1.4

Many people here would mistakenly assume that the bound IP should be the IP of the requested source. In fact, this should be bound to the IP that your Redis server itself accepts requests for.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Configure the Redis extranet to access

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.