Unzip
Tar zxvf redis-3.0.4.tar.gz
Enter the extracted directory
CD redis-3.0.4
compiling source files with make
Make
Installation
Enter the directory of the source file
CD src
Replicating Redis servers and clients to/usr/local/bin
CP Redis-server Redis-cli/usr/local/bin
It's better to copy the Sentinel,benchmark and check.
CP Redis-sentinel Redis-benchmark redis-check-aof Redis-check-dump/usr/local/bin
Create a Redis configuration folder
Mkdir/etc/redis
Create a valid directory for saving data under/var/lib/redis
Mkdir-p/var/lib/redis/6379
System parameters
To configure some kernel parameters for Redis to work properly
The configuration vm.overcommit_memory is 1, which prevents data from being truncated, as detailed in this
Sysctl-w Vm.overcommit_memory=1
The maximum number of modified backlog connections exceeds the Tcp-backlog value in Redis.conf, which is the default value of 511. You can find more information about the SYSCTL-based IP network tunnel in kernel.org
Sysctl-w net.core.somaxconn=512
Cancels support for transparent giant page memory (transparent huge pages) because it causes a delay in Redis usage and memory access issues
echo Never >/sys/kernel/mm/transparent_hugepage/enabled
Redis.conf
Redis.conf is a Redis profile, however you will see that the file name is 6379.conf, and this number is the network port that Redis listens to. If you want to run more than one Redis instance, it is recommended to use such a name.
Copy the redis.conf of the sample to /etc/redis/6379.conf
CP redis.conf/etc/redis/6379.conf
Now edit this file and configure the parameters
Daemonize
Setting Daemonize to NO,SYSTEMD requires it to run in the foreground, or Redis will suddenly hang up.
Daemonize No
Pidfile
Set Pidfile to/var/run/redis_6379.pid
Pidfile/var/run/redis_6379.pid
Port
If you are not ready to use the default port, you can modify
Port 6379
LogLevel
Setting the log level
LogLevel Notice
LogFile
To modify the log file path
Logfile/var/log/redis_6379.log
Dir
Set Directory to/var/lib/redis/6379
dir/var/lib/redis/6379
Safety
Here are a few things that can improve security
Unix sockets
In many cases, client programs and server-side programs run on the same machine, so there is no need to listen for sockets on the network. If this is similar to your usage, you can use a UNIX socket instead of a network socket, you need to configure Port 0, and then configure the options below to enable the UNIX socket.
Set up a socket file for a UNIX socket
Unixsocket/tmp/redis.sock
Restricting permissions on socket files
Unixsocketperm 700
Now in order for REDIS-CLI to be accessible, you should use the-s parameter to point to the socket file
Redis-cli-s/tmp/redis.sock
Requirepass
You may need remote access, if yes, then you should set the password, which will require a password before each operation
Requirepass "BTFBX1NYYWRMTUEYNHHSCG"
Rename-command
Imagine the output of the following command. Yes, this will output the configuration of the server, so you should deny this access in any possible circumstances.
CONFIG GET *
In order to restrict or even prohibit this or other instructions you can use the Rename-command command. You must provide a command name and alternate name. To disallow it, you need to set an alternate name to an empty string, which prevents anyone from guessing that the name of the command is safe.
Rename-command flushdb "flushdb_my_salt_g0es_here09u09u" Rename-command flushall "" Rename-command CONFIG "CONFIG_MY_ S4lt_go3s_here09u09u "
Snapshot
By default, Redis periodically dumps datasets to the dump.rdb file in the directory we set up. You can use the Save command to configure the frequency of the dump, its first parameter is the time frame in seconds, and the second parameter is the number of modifications made on the data file.
Every 15 minutes and a minimum of one key change
Save 900 1
Every 5 minutes and at least 10 keys have been modified
Save 300 10
Every 1 minutes and at least 10,000 keys have been modified
Save 60 10000
Start up at boot time
You can use SYSTEMD to add Redis to the system boot list
Copy the sample Init_script file to/ETC/INIT.D, and note the port number that the script name represents
CP utils/redis_init_script/etc/init.d/redis_6379
Now we're going to use SYSTEMD, so create a unit file under/etc/systems/system named Redis_6379.service
Vi/etc/systemd/system/redis_6379.service
[Unit] Description=redis on port 6379[service]type=forkingexecstart=/etc/init.d/redis_6379 startexecstop=/etc/init.d/ redis_6379 Stop[install]wantedby=multi-user.target
So you can start, and by setting these options you can deploy the Redis service to a lot of simple scenarios
How to install Redis on CENTOS7