Overview
First report the version of my system:
[Email protected] init.d]# cat/etc/issue
The system version information is as follows:
Reference
CentOS Release 6.4 (Final)
Kernel \ r on an \m
Installing Redis
You want to install Redis under this directory:
Reference
/usr/local/redis
Refer to the Http://redis.io/download installation instructions to make adjustments:
Reference
$ mkdir/usr/local/redis
$ cd/usr/local/src
$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xzf redis-2.6.14.tar.gz
$ ln-s redis-2.6.14 Redis #建立一个链接
$ CD Redis
$ make Prefix=/usr/local/redis Install #安装到指定目录中
Note the last line above, we specified the installed directory through prefix. If make fails, it is common that GCC is not installed in your system and can be installed by Yum:
Yum Install GCC
After the installation is complete, make is executed.
After you have successfully installed Redis, you will be able to see a bin directory in/usr/local/redis that includes the following files:
Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
Modify the system configuration file, execute the command
echo Vm.overcommit_memory=1 >>/etc/sysctl.conf
Sysctl Vm.overcommit_memory=1 or perform echo Vm.overcommit_memory=1 >>/proc/sys/vm/overcommit_memory
Use numeric meanings:
0, indicates that the kernel will check for sufficient available memory to be used by the process, and if sufficient memory is available, the memory request is allowed; otherwise, the memory request fails and the error is returned to the application process.
1, which means that the kernel allows all physical memory to be allocated regardless of the current memory state.
2, which indicates that the kernel allows allocating more memory than the sum of all physical memory and swap space
Redis configuration file Resolution
Redis.conf
Daemonize Yes---for the process to run in the background
Parameter description:
Daemonize: Whether to run daemon mode later
Pidfile:pid File Location
Port: Port number for listening
Timeout: Request time-out
Loglevel:log Information level
Logfile:log File Location
Databases: number of open databases
Save *: How often the snapshot is saved, the first * indicates how long, and the third * indicates how many times the write operation is performed. Snapshots are automatically saved when a certain number of writes are performed within a certain amount of time. You can set multiple conditions.
Rdbcompression: Whether to use compression
Dbfilename: Data Snapshot file name (only file name, excluding directory)
Dir: Save directory for Data snapshot (this is the directory)
AppendOnly: If the appendonlylog is turned on, each write will record a log, which will improve the data anti-risk ability, but affect the efficiency.
Appendfsync:appendonlylog How to sync to disk (three options, each write is forced to call Fsync, Fsync per second, do not call Fsync wait for the system to synchronize itself)
6. Start Redis
$ cd/usr/local/bin
./redis-server/etc/redis.conf
Check whether the start is successful
$ PS-EF | grep Redis
make Redis a service
1. Copy the script to the/ETC/RC.D/INIT.D directory
When you install Redis as per the above steps, its service script is located at:
/usr/local/src/redis/utils/redis_init_script
It must be copied to the/ETC/RC.D/INIT.D directory:
Cp/usr/local/src/redis/utils/redis_init_script/etc/rc.d/init.d/redis
The following copies the Redis_init_script to/etc/rc.d/init.d/and is easily named Redis.
If this is the case, we directly register the service:
Chkconfig--add Redis
The following error will be reported:
Reference
Redis service does not support Chkconfig
For some, we need to change the Redis script, see the next section for instructions.
2. Change the service script for Redis
Vim/etc/rc.d/init.d/redis
See the following file contents:
#!/bin/bash#chkconfig: 2345 80 90# simple redis init.d script conceived to work on linux systems# as it does use of The /proc filesystem. redisport=6379exec=/usr/local/redis/bin/redis-servercliexec=/usr/local/redis/bin/redis-clipidfile=/var/run/ redis_${redisport}.pidconf= "/etc/redis/${redisport}.conf" case "$" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed " else echo "Starting redis server ..." $EXEC $CONF & fi ;; stop) if [ ! -f $ pidfile ] then echo "$PIDFILE does not exist, Process is not running " else pid=$ (cat $PIDFILE) echo "Stopping &NBSP: " $ cliexec -p $REDISPORT shutdown while [ -x /proc/${pid} ] do echo "Waiting for redis to shutdown &NBSP: " sleep 1 done echo "redis stopped" fi ;; *) echo "Please use start or stop as first argument " ;; Esac
1) Troubleshoot issues that cannot be registered:
The original file does not have the contents of line 2nd below,
Reference
#chkconfig: 2345 80 90
If the registration will be an error, to add re-registration is OK.
2) Change the exec, cliexec parameter, set the corresponding value, as shown above is consistent with our previous installation.
3) Change the Redis Open command to run in the background:
$EXEC $CONF &
Notice that the "&" in the back is the meaning of moving the service to the back, or when the service is started, the Redis service will
Occupy the front desk, occupying the main user interface, resulting in other commands not being executed.
4) Copy the Redis configuration file to/etc/redis/${redisport}.conf
Mkdir/etc/redis cp/usr/local/src/redis/redis.conf/etc/redis/6379.conf
In this way, the conf specified by the Redis service script exists. By default, Redis does not have authentication enabled, and you can specify a verification password by turning on the requirepass of 6379.conf.
Once the above operation is complete, you can register the service:
Chkconfig--add Redis
3. Start the Redis service
$ service Redis Start
Add the directory of the Redis command to the system parameter path
To modify a profile:
#vi/etc/profile
In the last line add:
Export path= "$PATH:/usr/local/redis/bin"
Then apply this file immediately:
. /etc/profile
This makes it possible to invoke the REDIS-CLI command directly, as follows:
$ Redis-cliredis 127.0.0.1:6379> auth Supermanokredis 127.0.0.1:6379> Pingpongredis 127.0.0.1:6379>
Because I turned on the security authentication feature above, the password is Superman, so I need to auth to interact with the server.
< finish >
Installing the Redis complete process