简单实现linux下redis后台启动,开机自动启动(2024)

1.要实现redis后台启动,必须修改redis的配置文件,先cd /usr/local/src/redis-6.2.6到此目录后,先备份一份配置文件(避免配置操作失误)输入cp redis.conf redis.conf.bck再输入vi redis.conf修改配置文件

2.按/进入搜索模式,输入bind 找到后按i进去insert 模式 把原来的bind注释掉,下面输入bind 0.0.0.0 完成后按Esc退出insert模式

3.按/进入搜索模式,输入daemonize 找到后按i进去insert 模式 把后面的no改为yes,完成后按Esc退出insert模式

4.按/进入搜索模式,输入requirepass到后按i进去insert 模式 把后面的foobared改为要设的登录密码, 完成后按Esc退出insert模式

5.按/进入搜索模式,输入logfile 找到后按i进去insert 模式 在后面的双引号中加入redis.log,完成后按Esc退出insert模式,然后输入:wq保持并退出

6.输入cd /usr/locl/src/redis-6.2.6进入redis安装目录输入 redis-server redis.conf启动

7.输入ps -ef | grep redis查看有没有redis的运行进程,等等要设置开机自启要先杀死进程输入kill -9 加进程id


1.要设置开机自启,先新建一个系统服务文件,输入 vi /etc/system/redis.service,并在里面输入内容

Unit

Description=redis-server

After=network.target

Service

Type=forking

ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf

PrivateTmp=true

Install

WantedBy=multi-user.target

复制粘贴就行啦

2.然后输入systemctl daemon-reload重载服务

3.输入systemctl start redis 再输入systemctl status redis查看

4.systemctl stop redis关闭

5.systemctl enable redis配置成功再输入systemctl start redi再输入ps -ef | grep redis查看

6.输入cd /usr/local/bin/ 再输入redis-cli -h加自己ip地址 -p6379 -a加自己密码,出现页面后输入ping看返回pong及成功配置完成

相关推荐
Hero | 柒20 分钟前
JAVA反射机制
java·spring·反射
hanyi_qwe27 分钟前
文本三剑客--awk
linux·运维·服务器
j***630830 分钟前
Springboot项目中线程池使用整理
java·spring boot·后端
likuolei32 分钟前
Eclipse 创建 Java 接口
java·数据库·eclipse
q***547534 分钟前
Spring Boot 经典九设计模式全览
java·spring boot·设计模式
a***560636 分钟前
Spring Boot接收参数的19种方式
java·spring boot·后端
Caven7741 分钟前
【Linux 技巧】如何在登录时自动激活 Conda Base 环境
linux·运维·conda
z***75151 小时前
SpringBoot集成MQTT客户端
java·spring boot·后端
凌寒111 小时前
Linux(Debian)安装、卸载 MySQL
linux·运维·mysql·debian
q***69771 小时前
java进阶1——JVM
java·开发语言·jvm