当前位置:网站首页>CentOS7上Redis安装
CentOS7上Redis安装
2022-07-06 09:33:00 【小白说(๑• . •๑)】
CentOS7上Redis安装
1、redis上传+编译+安装
提前下载好redis-xxx.tar.gz的压缩文件,然后从本地上传redis压缩文件到服务器。拖拽的方式(我使用的是Xhell,注意拖拽的目录,往哪拖就上传到哪个目录)如果出现:
-bash: rz: 未找到命令,执行:
yum -y install lrzsz
上传完成后,解压上传的文件
tar xzf redis-3.2.8.tar.gz # -zxvf
解压得到 redis-3.2.8文件夹,进入 redis-3.2.8文件夹,首先执行gcc -v
,查看是否有gcc编译器,如果没有一定要执行这一步,否则跳过:
yum -y install gcc automake autoconf libtool make #安装gcc编译器
编译redis的源文件,生成可执行文件:
make MALLOC=libc #直接在当前目录下编译,并将可执行文件生成到src的目录下面。
如果想要将可执行文件生成到一个纯净的目录下面,可以执行:
make install PREFIX=/usr/local/redis/redis #会在redis目录总生成一个bin文件夹,里面放着可执行文件
两个编译的方式任选其一即可。
至此编译安装工作全部完成,已经能够将redis运行起来了。此时使用的是默认的配置文件进行启动。
注!可以在/usr/local/redis/redis
目录下面创建三个文件夹:
mkdir data #放redis缓存的数据
mkdir conf #放redis的配置文件
mkdir logs #放redis执行的日志文件
2、systemctl启动redis+开机自启动redis
在使用解压缩的方式安装完成redis之后,如果想要使用systemctl启动的话需要编写一个脚本文件来完成启动的过程(自动安装的可能没有这个烦恼哦!)。
使用service来管理服务的话,需要在/etc/init.d/
目录下创建脚本文件。
使用systemctl类似:
- 进入
/lib/systemd/system
目录编写脚本文件rediss.service
cd /lib/systemd/system #进入目录下
vi redis.service #创建并编辑
redis.service文件内容如下:
[Unit] #[Unit]:表示这是基础西悉尼
Description=Redis #Description:描述
After=network.target #After:表示在哪一个应用后面启动,一般是网络服务后启动启动
[Service] #[Service]:表示这里是服务信息
ExecStart=/usr/local/redis/redis/bin/redis-server /usr/local/redis/redis/conf/redis.conf --daemonize no #ExecStart:启动服务的命令(路径配置自己实际安装路径)
# 如果需要密码连接客户端的话配置:
# ExecStop=/usr/local/redis/redis/bin/redis-cli -h 127.0.0.1 -p 6379 -a 密码 shutdown
ExecStop=/usr/local/redis/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown #ExecStop:停止服务的命令
[Install] #[Install]:表示安装的相关西悉尼
WantedBy=multi-user.target #WantedBy:是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行
- 创建软连接
创建软连接的目的是,在系统初始化的时候自动启动服务准备的。
为刚刚创建的脚本文件创建一个软连接(类似于windows系统中的桌面快捷方式)。
#ls -s 建立软连接
#ls -s 源地址 目标地址
ls -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
- 刷新配置+启动+停止+重启
刚刚配置完systemctl之后需要刷新配置生效。
systemctl daemon-reload #刷新配置
systemctl start redis #或者 systemctl start redis.service-->开启redis
ps -ef|grep redis #启动之后可以查看是否具有redis的进程
systemctl stop redis #或者 systemctl stop redis.service-->停止redis
systemctl restart redis #或者 systemctl restart redis.service-->重启redis
- redis开机自启动与禁用
systemctl enable redis #开机自启
systemctl disable redis #禁用开机自启
systemctl status redis #查看当前redis的启动状态
参考链接
https://blog.csdn.net/penyoudi1/article/details/53692218
https://www.cnblogs.com/mr-wuxiansheng/p/12494124.html
边栏推荐
- 字节跳动技术面试官现身说法:我最想pick什么样的候选人
- Fdog series (III): use Tencent cloud SMS interface to send SMS, write database, deploy to server, web finale.
- 搭建flutter环境入坑集合
- DOS 功能调用
- SQL tuning notes
- TypeScript基本操作
- 唯有学C不负众望 TOP4 S1E6:数据类型
- À propos de l'utilisation intelligente du flux et de la carte
- 唯有學C不負眾望 TOP5 S1E8|S1E9:字符和字符串&&算術運算符
- 面试集锦库
猜你喜欢
Logical operation instruction
字节跳动技术面试官现身说法:我最想pick什么样的候选人
JVM运行时数据区之程序计数器
Mongodb learning notes
学习投资大师的智慧
1. JVM入门介绍
Eight part essay that everyone likes
Alibaba cloud server docker installation mysql5.5
High performance mysql (Third Edition) notes
Yao BanZhi and his team came together, and the competition experts gathered together. What fairy programming competition is this?
随机推荐
姚班智班齐上阵,竞赛高手聚一堂,这是什么神仙编程大赛?
Koa Middleware
Activit fragmented deadly pit
TCP's three handshakes and four waves
算数运算指令
Shell_ 06_ Judgment and circulation
手把手带你做强化学习实验--敲级详细
8086 内存
Resume of a microservice architecture teacher with 10 years of work experience
DS18B20數字溫度計系統設計
Control transfer instruction
mysql的合计/统计函数
DOS function call
Flink 解析(六):Savepoints
vscode
Many papers on ByteDance have been selected into CVPR 2021, and the selected dry goods are here
搭建flutter环境入坑集合
8086 CPU internal structure
Programmer orientation problem solving methodology
Fdog series (V): use QT to imitate QQ to realize login interface to main interface, function chapter.