redis初体验--安装篇
一.安装
###参考 https://redis.io/download
$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz
$ tar xzf redis-4.0.9.tar.gz
$ cd redis-4.0.9
$ make
小贴士:
wget
-P : 指定下载的目录
用法:wget -P 目录 下载地址
二.启动
$ cd redis-4.0.9/src
##默认不是以守护进程方式运行,后台运行退出当前页面即程序自动退出
$ ./redis-server
关闭
$ kill -9 进程号
#进入客户端
$ ./redis-cli
127.0.0.1:6379>
三.参数
1.daemonize
值:no/yes
默认值:no
config set是否支持修改:N
说明:是否以守护进程方式运行redis,当为no时,启动系统如果不加&则只能后台方式启动,如果退出该页面程序退出
$ ./redis-server
31035:C 17 May 16:40:28.877 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
31035:C 17 May 16:40:28.877 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=31035, just started
31035:C 17 May 16:40:28.877 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 31035
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
31035:M 17 May 16:40:28.878 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31035:M 17 May 16:40:28.878 # Server initialized
31035:M 17 May 16:40:28.878 # 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.
31035:M 17 May 16:40:28.878 # 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.
31035:M 17 May 16:40:28.878 * DB loaded from disk: 0.000 seconds
31035:M 17 May 16:40:28.878 * Ready to accept connections
ctrl+c退出当前页面
^C31035:signal-handler (1526546535) Received SIGINT scheduling shutdown...
31035:M 17 May 16:42:15.409 # User requested shutdown...
31035:M 17 May 16:42:15.409 * Saving the final RDB snapshot before exiting.
31035:M 17 May 16:42:15.411 * DB saved on disk
31035:M 17 May 16:42:15.412 # Redis is now ready to exit, bye bye...
当加入&运行 ctrl+c退出当前页面不会关闭这个进程。如果想省略可以直接设置这个参数为yes
2.port
默认值:6379
config set是否支持修改:N
说明:修改端口号,当端口号被修改后,运行客户端需要用-p加上端口号执行
$ ./redis-cli -p 端口号
3.bind
默认值:127.0.0.1
config set是否支持修改:N
说明:绑定的主机地址,默认127.0.0.1也就是本地回环,只有本机才能访问redis。如果要设置多个
bind 192.168.64.129 127.0.0.1
当不想做限制时参数设置为空。
4.protected-mode
值:yes/no
默认值:yes
config set是否支持修改:Y
说明:保护模式,避免redis被远程计算机连接。
5.requirepass
默认值:空
config set是否支持修改:Y
说明:修改密码,当修改后,登录客户端需要认证密码
$ ./redis-cli
127.0.0.1:6379> auth 12
OK
ps:修改配置文件的方式:
1.config命令
#只能修改部分参数
config set 参数名
#查看
config get 参数名|参数名片段*|*
这种方式修改可以即时生效,不用重启服务
2.修改配置文件
redis-4.0.9/redis.conf
这种方式修改启动时要带上配置文件
$ ./redis-server ../redis.conf