Configuration record of Redis startup in CentOS 6.5

Source: Internet
Author: User

Configuration record of Redis startup in CentOS 6.5

In CentOS 6.5, let's talk about the Redis STARTUP configuration record.

Download and install

Reference: "Redis installation record under CentOS 6.5"

If you only execute Make, you also need to execute the following command to configure startup:

[Plain] view plaincopy
  1. Sudomakeinstall
During the install, The redis command will be copied to/usr/local/bin.

Copy the configuration file to the/etc directory.

[Plain] view plaincopy
  1. Cpredis. conf/etc

To create a user and log directory, we recommend that you create a separate user for Redis and create a new data and log folder.

[Plain] view plaincopy
  1. Sudouseraddredis
  2. Sudomkdir-p/var/lib/redis
  3. Sudomkdir-p/var/log/redis
  4. Sudochownredis. redis/var/lib/redis
  5. Sudochownredis. redis/var/log/redis
Modify configuration file

[Plain] view plaincopy
  1. Vi/etc/redis. conf
Modify the bound IP address to solve the problem that other IP addresses outside the local machine cannot be accessed (if you need to access it on another computer );

[Plain] view plaincopy
  1. ################################## NETWORK ##### ################################
  2. # Bydefault, ifno "bind" configurationdirectiveisspecified, Redislistens
  3. # Forconnectionsfromallthenetworkinterfacesavailableontheserver.
  4. # Itispossibletolistentojustoneormultipleselectedinterfacesusing
  5. # The "bind" configurationdirective, followedbyoneormoreIPaddresses.
  6. #
  7. # Examples:
  8. #
  9. # Bind192.168.1.10010.0.0.1
  10. # Bind127.0.0.1: 1
  11. #
  12. #~~~ WARNING ~~~ IfthecomputerrunningRedisisdirectlyexposedtothe
  13. # Internet, bindingtoalltheinterfacesisdangerousandwillexposethe
  14. # Instancetoeverybodyontheinternet. Sobydefaultweuncommentthe
  15. # Followingbinddirective, thatwillforceRedistolistenonlyinto
  16. # The4244lookbackinterfaceaddress (thismeansRediswillbeableto
  17. # Acceptconnectionsonlyfromclientsrunning1_thesamecomputerit
  18. # Isrunning ).
  19. #
  20. # IFYOUARESUREYOUWANTYOURINSTANCETOLISTENTOALLTHEINTERFACES
  21. # JUSTCOMMENTTHEFOLLOWINGLINE.
  22. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Bind0.0.0.0
The default value is "bind 127.0.0.1: 1" and is changed to "bind 0.0.0.0 ";
Change the startup mode to background startup

[Plain] view plaincopy
  1. ################################# GENERAL ###### ###############################
  2. # BydefaultRedisdoesnotrunasadaemon. Use 'yes' ifyouneedit.
  3. # NotethatRediswillwriteapidfilein/var/run/redis. pidwhendaemonized.
  4. Daemonizeyes
Daemonize yes

Modify the data file storage location

[Plain] view plaincopy
  1. # Theworkingdirectory.
  2. #
  3. # TheDBwillbewritteninsidethisdirectory, withthefilenamespecified
  4. # Aboveusingthe 'dbfilename' configurationctive.
  5. #
  6. # TheAppendOnlyFilewillalsobecreatedinsidethisdirectory.
  7. #
  8. # Notethatyoumustspecifyadirectoryhere, notafilename.
  9. Dir/var/lib/redis
Note: specify a directory without a file name;

Configure the init script

[Plain] view plaincopy
  1. Vi/etc/init. d/redis
[Plain] view plaincopy
  1. # Chkconfig: 23459010
  2. # Description: Redisisapersistentkey-valuedatabase
  3. ###########################
  4. PATH =/usr/local/bin:/sbin:/usr/bin:/bin
  5. REDISPORT = 6379
  6. EXEC =/usr/local/bin/redis-server
  7. REDIS_CLI =/usr/local/bin/redis-cli
  8. PIDFILE =/var/run/redis. pid
  9. CONF = "/etc/redis. conf"
  10. Case "$1" in
  11. Start)
  12. If [-f $ PIDFILE]
  13. Then
  14. Echo "$ PIDFILEexists, processisalreadyrunningorcrashed"
  15. Else
  16. Echo "StartingRedisserver ..."
  17. $ EXEC $ CONF
  18. Fi
  19. If ["$? "=" 0 "]
  20. Then
  21. Echo "Redisisrunning ..."
  22. Fi
  23. ;;
  24. Stop)
  25. If [! -F $ PIDFILE]
  26. Then
  27. Echo "$ PIDFILEdoesnotexist, processisnotrunning"
  28. Else
  29. PID = $ (cat $ PIDFILE)
  30. Echo "Stopping ..."
  31. $ REDIS_CLI-p $ REDISPORTSHUTDOWN
  32. While [-x $ {PIDFILE}]
  33. Do
  34. Echo "WaitingforRedistoshutdown ..."
  35. Sleep1
  36. Done
  37. Echo "Redisstopped"
  38. Fi
  39. ;;
  40. Restart | force-reload)
  41. $ {0} stop
  42. $ {0} start
  43. ;;
  44. *)
  45. Echo "Usage:/etc/init. d/redis {start | stop | restart | force-reload}"> & 2
  46. Exit1
  47. Esac
  48. ##############################
Note the first two sentences:

[Plain] view plaincopy
  1. # Chkconfig: 23459010
  2. # Description: Redisisapersistentkey-valuedatabase
This is a comment, but if it is not, an error will be reported: service redis does not support chkconfig
Add execution permission

[Plain] view plaincopy
  1. Chmod + x/etc/init. d/redis
Set the startup service [plain] view plaincopy
  1. Sudochkconfigredison
Start and Stop redis

[Plain] view plaincopy
  1. Serviceredisstart
  2. Serviceredisstop
Or:

[Plain] view plaincopy
  1. /Etc/init. d/redisstart
  2. /Etc/init. d/redisstop
Test redis

[Plain] view plaincopy
  1. # Redis-cli
  2. 127.0.0.1: 6379> setkey123
  3. OK
  4. 127.0.0.1: 6379> getkey
  5. "123"
  6. 127.0.0.1: 6379> exit
You can also use Telnet to test:

[Plain] view plaincopy
  1. Telnet192.168.1.1006379
After the connection, execute the same command.

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.