Redis-02Redis在linux下的安裝及常見問題
阿新 • • 發佈:2018-12-10
新建redis使用者
使用root使用者登入虛機,新增使用者並設定密碼
#新增使用者 [也可以通過-u -g -d引數指定特定的值來建立使用者
[[email protected] ~]# useradd redis
#修改密碼
[[email protected] ~]# passwd redis
Changing password for user redis.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfull
#檢視
[ [email protected] ~]$ id redis
uid=501(redis) gid=501(redis) groups=501(redis)
安裝Redis
切換到redis使用者,建立目錄,下載解壓。我這臺主機可以連外網,所以直接通過wget的方式下載,如果不能訪問外網的話,可以下載後ftp到主機上。
[[email protected] ~]# su - redis
[[email protected] ~]$ mkdir -p /home/redis/redis
[[email protected] ~]$wget http://download.redis.io/releases/redis-4.0.11.tar.gz
[ [email protected] ~]$tar -xvzf redis-4.0.11.tar.gz
[[email protected] ~]$cd redis-4.0.11
[[email protected] ~]$make
make 錯誤一 未安裝gcc
[[email protected] redis-4.0.11]$ make
cd src && make all
make[1]: Entering directory `/home/redis/redis/redis-4.0.11/src'
CC Makefile.dep
make[1]: Leaving directory `/home/redis/redis/redis-4.0.11/src'
make[1]: Entering directory `/home/redis/redis/redis-4.0.11/src'
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/redis/redis/redis-4.0.11/src'
make: *** [all] Error 2
[ [email protected] redis-4.0.11]$
然後重新make
make 錯誤二 jemalloc
[[email protected] redis-4.0.11]$ make
cd src && make all
make[1]: Entering directory `/home/redis/redis/redis-4.0.11/src'
CC adlist.o
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"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/home/redis/redis/redis-4.0.11/src'
make: *** [all] Error 2
執行上述命令後
[[email protected] redis-4.0.11]$ make distclean
......
......
......
[[email protected] redis-4.0.11]$ make
......
......
......
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/home/redis/redis/redis-4.0.11/src'
[[email protected] redis-4.0.11]$
整理檔案
為了方便對Redis的配置和服進行管理,建立etc和bin目錄
[[email protected] redis-4.0.11]$ pwd
/home/redis/redis/redis-4.0.11
[[email protected] redis-4.0.11]$ mkdir etc
[[email protected] redis-4.0.11]$ mkdir bin
[[email protected] redis-4.0.11]$ mv redis.conf etc/
[[email protected] redis-4.0.11]$ cd src
[[email protected] src]$ mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb ../bin
[[email protected] src]$
啟動redis
以預設的方式啟動redis
可以直接使用./redis-server的方式 以預設形式啟動redis.
[[email protected] bin]$ ./redis-server
31494:C 19 Sep 20:01:36.670 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
31494:C 19 Sep 20:01:36.670 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=31494, just started
31494:C 19 Sep 20:01:36.670 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
31494:M 19 Sep 20:01:36.671 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
31494:M 19 Sep 20:01:36.671 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
31494:M 19 Sep 20:01:36.671 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.11 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 31494
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
31494:M 19 Sep 20:01:36.693 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31494:M 19 Sep 20:01:36.693 # Server initialized
31494:M 19 Sep 20:01:36.693 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
31494:M 19 Sep 20:01:36.694 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
31494:M 19 Sep 20:01:36.694 * Ready to accept connections
ctrl+c終止該程序
^C31494:signal-handler (1537361978) Received SIGINT scheduling shutdown...
31494:M 19 Sep 20:59:38.814 # User requested shutdown...
31494:M 19 Sep 20:59:38.816 * Saving the final RDB snapshot before exiting.
31494:M 19 Sep 20:59:38.828 * DB saved on disk
31494:M 19 Sep 20:59:38.828 # Redis is now ready to exit, bye bye...
檢視程序,可以看到沒有該程序了。
[[email protected] bin]$ ps -ef|grep redis-server |grep -v redis-server
[[email protected] bin]$
指定redis.conf啟動redis
[[email protected] bin]$ ./redis-server ../etc/redis.conf
31765:C 19 Sep 21:04:08.458 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
31765:C 19 Sep 21:04:08.458 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=31765, just started
31765:C 19 Sep 21:04:08.458 # Configuration loaded
31765:M 19 Sep 21:04:08.460 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
31765:M 19 Sep 21:04:08.460 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
31765:M 19 Sep 21:04:08.460 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.11 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 31765
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
31765:M 19 Sep 21:04:08.464 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31765:M 19 Sep 21:04:08.464 # Server initialized
31765:M 19 Sep 21:04:08.464 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
31765:M 19 Sep 21:04:08.464 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
31765:M 19 Sep 21:04:08.464 * DB loaded from disk: 0.000 seconds
31765:M 19 Sep 21:04:08.464 * Ready to accept connections
後臺方式啟動redis
修改redis.conf 將 daemonize no
修改為 daemonize yes
,儲存重啟redis.
[[email protected] redis-4.0.11]$ cd bin/
[[email protected] bin]$ ./redis-server ../etc/redis.conf
31864:C 19 Sep 21:11:01.500 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
31864:C 19 Sep 21:11:01.500 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=31864, just started
31864:C 19 Sep 21:11:01.500 # Configuration loaded
[[email protected] bin]$
[[email protected] bin]$ ps -ef|grep redis-server
redis 31865 1 0 21:11 ? 00:00:00 ./redis-server 127.0.0.1:6379
redis 31870 31812 0 21:11 pts/0 00:00:00 grep redis-server
[[email protected] bin]$ date
Wed Sep 19 21:11:14 CST 2018
[[email protected] bin]$
後臺啟動方式下,啟動之後列印了很少的的內容,檢視是否啟動成功,ps -ef|grep redis-server
命令即可。