Linux install redis

Linux installation redis ===================

1. Install Redis

Create the installation path first: /data1/apps/redis2.6.14


1.1, download and install

wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
tar -zxvf redis-2.6.14.tar.gz
cd redis-2.6.14
make PREFIX=/data1/apps/redis2.6.14 install
mkdir /data1/apps/redis2.6.14/etc

1.5, possible error prompts
>> Prompt 1:
make[3]: gcc: command not found
>> Solve
yum -y install gcc-c++

>>hint 2:
in file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: no such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
>>
Add MALLOC=libc parameter
make PREFIX=/data/apps/redis2.6.14 MALLOC=libc install when solving make


cp redis.conf /etc/
This file is the configuration file for redis startup

 

Since redis is installed under /data1/apps/redis2.6.14/,
cd /data1/apps/redis2.6.14/ to enter this directory and execute cp
redis-benchmark redis-cli redis-server /usr/bin/
./ is added when executing, and it can be executed anywhere


echo 1 > /proc/sys/vm/overcommit_memory

Set the memory allocation policy (optional, set according to the actual situation of the server) /proc/sys/vm/overcommit_memory
Optional values: 0, 1, 2.
0, which means that the kernel will check whether there is enough available memory for the application process to use; if there is enough available memory, the memory application is allowed; otherwise, the memory application fails and an 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. Indicates that the kernel allows the allocation of memory that exceeds the sum of all physical memory and swap space. It is
worth noting that when redis dumps data, it will fork a child process. In theory, the memory occupied by the child process is the same as that of the parent. For example, the memory occupied by the parent is 8G. At this time, 8G of memory should also be allocated to the child. If the memory cannot be burdened, the redis server will be down or the IO load will be too high, which will reduce the efficiency. So the more optimized memory allocation strategy here should be set to 1 (meaning that the kernel allows all physical memory to be allocated, regardless of the current memory state)

Open the redis port and modify the firewall configuration file
vi /etc/sysconfig/iptables
to add the port configuration

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

Reload rules
service iptables restart

Start redis service
redis-server /etc/redis.conf

[3862] 19 Feb 23:10:56.339 * Max number of open files set to 10032
[3862] 19 Feb 23:10:56.347 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.6.14 (00000000/0) 32 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 3862
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[3862] 19 Feb 23:10:56.347 # Server started, Redis version 2.6.14
[3862] 19 Feb 23:10:56.347 * The server is now ready to accept connections on port 6379

Check the process to confirm that redis started successfully:
ps -ef | grep redis
[root@mtycentos ~]# ps -ef | grep redis
root 3862 3666 0 23:10 pts/1 00:00:00 redis-server /etc/redis. conf
root 3886 3866 0 23:11 pts/0 00:00:00 grep redis

If the startup fails, in most cases it is because of a problem with the configuration of redis.conf.
Set redis as a background daemon:
vi /etc/redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis .pid when daemonized.
#daemonize no
daemonize yes Change
no to yes

Close redis after modification: redis-cli shutdown
to see if it is closed: ps -ef | grep redis

Start again as a daemon: redis-server /etc/redis.conf
[root@mtycentos ~]# ps -ef | grep redis
root 3913 1 0 23:16 ? 00:00:00 redis-server /etc/redis.conf
root 3917 3866 0 23:16 pts/0 00:00:00 grep redis

OK, the startup is successful

Test it:
Enter the redis client command line:
redis-cli Enter
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> set name hanlu
OK
redis 127.0.0.1:6379> get name
"hanlu"

The description was successful.

Exit the current command line: quit


Shut down redis:
redis-cli shutdown
After redis is shut down, the cached data will be automatically saved to the hard disk, and the hard disk address is the configuration item dgfilename dump.rdb in redis.conf


Force backup data to disk:
redis-cli save or redis-cli -p 6380 save (to specify a port for backup)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324649246&siteId=291194637