当前位置:网站首页>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
边栏推荐
- À propos de l'utilisation intelligente du flux et de la carte
- 数据传送指令
- JVM垃圾回收概述
- DS18B20數字溫度計系統設計
- Fdog series (III): use Tencent cloud SMS interface to send SMS, write database, deploy to server, web finale.
- 算数运算指令
- JVM之垃圾回收器上篇
- Which is more important for programming, practice or theory [there are some things recently, I don't have time to write an article, so I'll post an article on hydrology, and I'll fill in later]
- MySQL字符串函数
- 汇编语言段定义
猜你喜欢

Description of project structure configuration of idea

JVM之垃圾回收器下篇

"One year after graduation, I won ACL best paper"

Instructions for Redux

Shell_ 02_ Text three swordsman

Fdog series (III): use Tencent cloud SMS interface to send SMS, write database, deploy to server, web finale.

学习投资大师的智慧

Fdog series (4): use the QT framework to imitate QQ to realize the login interface, interface chapter.

Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"

吴军三部曲见识(四) 大家智慧
随机推荐
TCP的三次握手和四次挥手
Log4j2 major vulnerabilities and Solutions
On the clever use of stream and map
vscode
JVM运行时数据区之程序计数器
Compile homework after class
Only learning C can live up to expectations top3 demo exercise
程序员定位解决问题方法论
8086 分段技术
Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
README. txt
汇编课后作业
MySQL optimization notes
学习投资大师的智慧
TypeScript基本操作
Idea resolving jar package conflicts
Fdog series (I): think about it. It's better to write a chat software. Then start with the imitation QQ registration page.
冯诺依曼体系结构
唯有學C不負眾望 TOP5 S1E8|S1E9:字符和字符串&&算術運算符
arithmetic operation