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
- 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
- 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
- Sudouseraddredis
- Sudomkdir-p/var/lib/redis
- Sudomkdir-p/var/log/redis
- Sudochownredis. redis/var/lib/redis
- Sudochownredis. redis/var/log/redis
Modify configuration file
[Plain] view plaincopy
- 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
- ################################## NETWORK ##### ################################
- # Bydefault, ifno "bind" configurationdirectiveisspecified, Redislistens
- # Forconnectionsfromallthenetworkinterfacesavailableontheserver.
- # Itispossibletolistentojustoneormultipleselectedinterfacesusing
- # The "bind" configurationdirective, followedbyoneormoreIPaddresses.
- #
- # Examples:
- #
- # Bind192.168.1.10010.0.0.1
- # Bind127.0.0.1: 1
- #
- #~~~ WARNING ~~~ IfthecomputerrunningRedisisdirectlyexposedtothe
- # Internet, bindingtoalltheinterfacesisdangerousandwillexposethe
- # Instancetoeverybodyontheinternet. Sobydefaultweuncommentthe
- # Followingbinddirective, thatwillforceRedistolistenonlyinto
- # The4244lookbackinterfaceaddress (thismeansRediswillbeableto
- # Acceptconnectionsonlyfromclientsrunning1_thesamecomputerit
- # Isrunning ).
- #
- # IFYOUARESUREYOUWANTYOURINSTANCETOLISTENTOALLTHEINTERFACES
- # JUSTCOMMENTTHEFOLLOWINGLINE.
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 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
- ################################# GENERAL ###### ###############################
- # BydefaultRedisdoesnotrunasadaemon. Use 'yes' ifyouneedit.
- # NotethatRediswillwriteapidfilein/var/run/redis. pidwhendaemonized.
- Daemonizeyes
Daemonize yesModify the data file storage location
[Plain] view plaincopy
- # Theworkingdirectory.
- #
- # TheDBwillbewritteninsidethisdirectory, withthefilenamespecified
- # Aboveusingthe 'dbfilename' configurationctive.
- #
- # TheAppendOnlyFilewillalsobecreatedinsidethisdirectory.
- #
- # Notethatyoumustspecifyadirectoryhere, notafilename.
- Dir/var/lib/redis
Note: specify a directory without a file name;Configure the init script[Plain] view plaincopy
- Vi/etc/init. d/redis
[Plain] view plaincopy
- # Chkconfig: 23459010
- # Description: Redisisapersistentkey-valuedatabase
- ###########################
- PATH =/usr/local/bin:/sbin:/usr/bin:/bin
- REDISPORT = 6379
- EXEC =/usr/local/bin/redis-server
- REDIS_CLI =/usr/local/bin/redis-cli
- PIDFILE =/var/run/redis. pid
- CONF = "/etc/redis. conf"
- Case "$1" in
- Start)
- If [-f $ PIDFILE]
- Then
- Echo "$ PIDFILEexists, processisalreadyrunningorcrashed"
- Else
- Echo "StartingRedisserver ..."
- $ EXEC $ CONF
- Fi
- If ["$? "=" 0 "]
- Then
- Echo "Redisisrunning ..."
- Fi
- ;;
- Stop)
- If [! -F $ PIDFILE]
- Then
- Echo "$ PIDFILEdoesnotexist, processisnotrunning"
- Else
- PID = $ (cat $ PIDFILE)
- Echo "Stopping ..."
- $ REDIS_CLI-p $ REDISPORTSHUTDOWN
- While [-x $ {PIDFILE}]
- Do
- Echo "WaitingforRedistoshutdown ..."
- Sleep1
- Done
- Echo "Redisstopped"
- Fi
- ;;
- Restart | force-reload)
- $ {0} stop
- $ {0} start
- ;;
- *)
- Echo "Usage:/etc/init. d/redis {start | stop | restart | force-reload}"> & 2
- Exit1
- Esac
- ##############################
Note the first two sentences:[Plain] view plaincopy
- # Chkconfig: 23459010
- # 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
- Chmod + x/etc/init. d/redis
Set the startup service [plain] view plaincopy
- Sudochkconfigredison
Start and Stop redis[Plain] view plaincopy
- Serviceredisstart
- Serviceredisstop
Or:[Plain] view plaincopy
- /Etc/init. d/redisstart
- /Etc/init. d/redisstop
Test redis[Plain] view plaincopy
- # Redis-cli
- 127.0.0.1: 6379> setkey123
- OK
- 127.0.0.1: 6379> getkey
- "123"
- 127.0.0.1: 6379> exit
You can also use Telnet to test:[Plain] view plaincopy
- Telnet192.168.1.1006379
After the connection, execute the same command.