赞
踩
1)下载安装包 wget http://download.redis.io/releases/redis-?.?.?.tar.gz 如:wget http://download.redis.io/releases/redis-4.0.0.tar.gz 2)解压: tar -xvf 文件名.tar.gz 如:tar -xvf redis-4.0.0.tar.gz 3)编译:make 4)安装 make install [destdir=/目录] 如:make install 5)启动 redis redis-server 6)重新打开另一终端,启动 redis 客户端 cd ../redis-4.0.0/src/ redis-cli
# 1)下载安装包 redis-4.0.0.tar.gz # 切换目录 root@WIN-20240529BJA:/home/djh# cd /usr/local # 创建新目录 root@WIN-20240529BJA:/usr/local# mkdir redis root@WIN-20240529BJA:/usr/local# cd redis/ # 下载安装包 redis-4.0.0.tar.gz root@WIN-20240529BJA:/usr/local/redis# wget http://download.redis.io/releases/redis-4.0.0.tar.gz root@WIN-20240529BJA:/usr/local/redis# ll total 1680 drwxr-xr-x 2 root root 4096 Jul 15 16:26 ./ drwxr-xr-x 15 root root 4096 Jul 15 16:25 ../ -rw-r--r-- 1 root root 1710169 Jun 27 2020 redis-4.0.0.tar.gz # 2)解压 redis-4.0.0.tar.gz # 切换目录 cd /usr/local/redis/ # 解压 redis-4.0.0.tar.gz tar -xvf redis-4.0.0.tar.gz # 3)编译并安装 redis-4.0.0 # 切换到 redis 安装目录下的 src 目录: root@WIN-20240529BJA:/usr/local/redis# cd /usr/local/redis/redis-4.0.0/src/ # 安装 make 命令(如果出现错误:make: not found ) apt install make # 安装 C 编译器(如果出现错误:/bin/sh: 1: cc: not found ) root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0/src# sudo apt-get install build-essential tcl # 编译并安装 make install # (如果出现错误:zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory)可使用以下命令编译并安装: root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0/src# make CFLAGS="-DUSE_JEMALLOC=0" install # 4)启动 redis 服务 # 切换到 redis 安装目录下的 src 目录: root@WIN-20240529BJA:/usr/local/redis# cd /usr/local/redis/redis-4.0.0/src/ # 启动 redis 服务 redis-server # 5)重新打开另一终端,启动 redis 客户端 # 切换到 redis 安装目录下的 src 目录: root@WIN-20240529BJA:/usr/local/redis# cd /usr/local/redis/redis-4.0.0/src/ # 启动 redis 客户端 redis-cli
# 默认配置启动(默认端口号:6379)
redis-server
# 指定端口号启动
redis-server --port 6379
redis-server --port 6380
# 默认连接
redis-cli
# 指定端口号连接 redis 服务
redis-cli -p 6379
redis-cli -p 6380
# 默认配置启动(默认端口号:6379)
redis-server
# 指定端口号启动
redis-server --port 6379
redis-server --port 6380
# 指定配置文件启动
redis-server redis.conf
redis-server redis-6379.conf
redis-server redis-6380.conf
redis-server conf/redis-6379.conf
redis-server config/redis-6380.conf .....
# 默认连接
redis-cli
# 指定端口号连接 redis 服务
redis-cli -p 6379
redis-cli -p 6380
# 连接指定服务器
redis-cli -h 127.0.0.1
redis-cli -port 6379
redis-cli -h 127.0.0.1 -port 6379
# 切换到 redis 安装目录: cd /usr/local/redis/redis-4.0.0/ # 复制配置文件内容,取掉注释并取掉空白,把其他内容复制到 redis-6379.conf 文件里 cat redis.conf | grep -v "#" | grep -v "^$" > redis-6379.conf # 修改 redis-6379.conf 配置文件 vim redis-6379.conf # 保底以下内容即可: port 6379 daemonize yes logfile "6379.log" # data 目录为新建目录 dir /usr/local/redis/redis-4.0.0/data
# 切换到 redis 安装目录: cd /usr/local/redis/redis-4.0.0/ # 指定配置文件,后台启动 redis 服务: root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-server redis-6379.conf # 查看 redis 服务,后台启动是否启动成功 root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# ps -ef | grep redis- root 23991 1 0 21:42 ? 00:00:00 redis-server *:6379 root 23996 1538 3 21:43 pts/3 00:00:00 grep --color=auto redis- root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# # 打开另一终端,启动客户端,连接后台服务 root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0/data# cd .. root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-cli 127.0.0.1:6379> set name redis OK 127.0.0.1:6379> get name "redis" 127.0.0.1:6379>
# 查看 redis 后台服务是否启动
root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# ps -ef | grep redis-
root 23991 1 0 21:42 ? 00:00:00 redis-server *:6379
root 24063 1538 0 21:55 pts/3 00:00:00 grep --color=auto redis-
# 通过 PID 杀死 redis 服务进程
root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# kill -s 9 23991
# 再次 查看 redis 后台服务是否启动
root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# ps -ef | grep redis-
root 24066 1538 0 21:56 pts/3 00:00:00 grep --color=auto redis-
root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0#
# 切换到 redis 安装目录: cd /usr/local/redis/redis-4.0.0/ # 创建新目录 conf mkdir conf # 把 redis-6379.conf 配置文件,移动到 conf (新建目录) 统一管理。 mv redis-6379.conf conf # 复制一份 redis-6379.conf 更名为 redis-6380.conf cp conf/redis-6379.conf conf/redis-6380.conf # 编辑 redis-6380.conf 端口号 vim conf/redis-6380.conf # 保底以下内容即可: port 6380 daemonize yes logfile "6380.log" # data 目录为新建目录 dir /usr/local/redis/redis-4.0.0/data
# 切换到 redis 安装目录: cd /usr/local/redis/redis-4.0.0/ # 指定配置文件,后台启动 redis 服务: root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-server conf/redis-6379.conf root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-server conf/redis-6380.conf # 查看 redis 服务,后台启动是否启动成功 root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# ps -ef | grep redis- root 24075 1 0 22:19 ? 00:00:00 redis-server *:6379 root 24086 1 0 22:28 ? 00:00:00 redis-server *:6380 root 24091 1538 0 22:28 pts/3 00:00:00 grep --color=auto redis- root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# # 打开另一终端,启动客户端,连接后台服务 # 切换到 redis 安装目录: cd /usr/local/redis/redis-4.0.0/ root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-cli -p 6379 127.0.0.1:6379> set name redis-6379 OK 127.0.0.1:6379> get name "redis-6379" 127.0.0.1:6379> # Ctrl + c 退出连接 redis-6379 , 并重新连接 redis-6380 服务 root@WIN-20240529BJA:/usr/local/redis/redis-4.0.0# redis-cli -p 6380 127.0.0.1:6380> set name redis-6380 OK 127.0.0.1:6380> get name "redis-6380" 127.0.0.1:6380>
上一节关联链接请点击:
# Redis 入门到精通(三)jedis
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。