一、单机安装redis
1.1 安装redis依赖
redis是基于C语言编写的,因此首先需要安装redis的所需的gcc依赖:
yum install -y gcc tcl
1.2 下载安装包并解压
下载地址: download.redis.io/releases/re…
#下载安装包
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
mv redis-6.2.6.tar.gz /usr/local/src/
cd /usr/local/src/
#解压
tar zxf redis-6.2.6.tar.gz
cd redis-6.2.6
ls
#编译
make&&make install
如果能上述步骤没有出错,就表示安装成功了。默认的安装路径在/usr/local/bin下面
[root@192 redis-6.2.6]# cd /usr/local/bin
[root@192 bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
1.3 启动
1.3.1 默认启动
安装完成后,在任意目录执行redis-server命令即可启动redis,此种方式为前台启动
[root@192 ~]# redis-server
15168:C 15 Nov 2022 10:33:44.254 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15168:C 15 Nov 2022 10:33:44.254 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=15168, just started
15168:C 15 Nov 2022 10:33:44.254 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
15168:M 15 Nov 2022 10:33:44.254 * Increased maximum number of open files to 10032 (it was originally set to 1024).
15168:M 15 Nov 2022 10:33:44.254 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 15168
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
15168:M 15 Nov 2022 10:33:44.256 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
15168:M 15 Nov 2022 10:33:44.256 # Server initialized
15168:M 15 Nov 2022 10:33:44.256 # 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.
15168:M 15 Nov 2022 10:33:44.257 * Ready to accept connections
1.3.2 指定配置启动
如果想让redis以后台方式启动,那就必须要修改redis配置文件,配置文件的位置在压缩包解压后的文件夹目录下/usr/local/src/redis-6.2.6,文件名叫做redis.conf:
cd /usr/local/src/redis-6.2.6
[root@192 redis-6.2.6]# ls
00-RELEASENOTES BUGS CONDUCT CONTRIBUTING COPYING deps INSTALL Makefile MANIFESTO README.md redis.conf runtest runtest-cluster runtest-moduleapi runtest-sentinel sentinel.conf src tests TLS.md utils
需要将该配置文件备份。
cp redis.conf redis.conf.bak
修改一些配置
vi redis.conf
#允许访问的地址 默认是127.0.0.1,会导致只能在本地访问,0.0.0.0 为任意IP访问,生产环境需要指定具体IP
#bind 127.0.0.1 -::1
bind 0.0.0.0
#守护进程,改为yes 为后台运行
daemonize yes
#密码 设置后必须输入密码
requirepass 12345
logfile "redis.log"
#端口
port 6379
dir .
#databases 1
启动redis
[root@192 redis-6.2.6]# redis-server redis.conf
[root@192 redis-6.2.6]# ps -ef|grep redis
root 15225 1 0 10:54 ? 00:00:00 redis-server 0.0.0.0:6379
root 15231 1962 0 10:54 pts/1 00:00:00 grep --color=auto redis
[root@192 redis-6.2.6]#
停止服务
#判断redis-cli 来执行shutdown,即可停止redis服务
redis-cli -a 12345 shutdown
1.3.3 开机启动
vi /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
PrivateTmp=true
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
二、redis客户端
2.1 了解命令行客户端
命令行客户端在安装redis的时候会自动安装,在任意位置执行redis-cli即可.
# redis-cli 其实后面跟了 -h -p 等参数只是默认的省略了
# 下面的命令完整的是 redis-cli -h 127.0.0.1 -p 6379
# auth 是输入密码验证
# ping 是检测redis-server的心跳
[root@192 ~]# redis-cli
127.0.0.1:6379> auth 12345
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
2.2 了解图形界面客户端
此处就介绍几个。
2.3 按语言浏览:
- ActionScript
- ActiveX/COM+
- Bash
- Boomi
- C
- C#
- C++
- Clojure
- Common Lisp
- Crystal
- D
- Dart
- Delphi
- Elixir
- emacs lisp
- Erlang
- Fancy
- gawk
- GNU Prolog
- Go
- Haskell
- Haxe
- Java
- Julia
- Lasso
- Lua
- Matlab
- mruby
- Nim
- Node.js
- Objective-C
- OCaml
- Pascal
- Perl
- PHP
- PL/SQL
- Prolog
- Pure Data
- Python
- R
- Racket
- Rebol
- Ruby
- Rust
- Scala
- Scheme
- Smalltalk
- Swift
- Tcl
- VB
- VCL
- Xojo
- Zig