redis如何随系统启动
Redis可以通过命令redis-server启动,但这种启动方式适用于开发环境,对于生产环境来说,配置好redis的配置文件,并使redis随linux启动则更加方便些,下面则记录下redis如何随linux自动启动。
redis版本:5.0.3
1、在redis的安装目录的utils文件夹中找到初始化脚本文件redis_init_script,完整目录是/user/local/redis-5.0.3/utils/redis_init_script,将其复制到/etc/init.d文件夹中,命名为redis_+端口号,如redis_6379,该端口号是redis需要监听的端口号。
2、建立启动redis需要的配置文件及相关目录
| 目录名 | 说明 |
| /etc/redis |
存放redis的配置文件 |
| /var/redis/端口号 |
存放redis持久化文件 |
| 文件名 | 说明 |
| /var/run/redis_端口号.pid | redis的pid文件 |
| /var/log/redis.log | redis的日志文件 |
3、配置配置文件
在redis根目录下有个叫redis.conf的配置文件,放在上面建立的/etc/redis文件夹下,命名为端口号.conf,如6379.conf。修改相应的配置:
| 参数 | 值 | 说明 |
| daemonize | yes | 使redis以守护进程模式运行 |
| pidfile | /var/run/redis_端口号.pid | 设置redis的PID文件位置 |
| port | 端口号 | 设置redis要监听的端口号 |
| dir | /var/redis/端口号 | 设置持久化文件存放位置 |
| logfile | /var/log/redis.log | 设置配置文件位置 |
4、修改初始化脚本redis_init_script
修改后的文件如下:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/6379.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
5、将redis的初始化脚本加入linux的启动项中
$sudo update-rc.d redis_端口号 defaults
6、经过上述步骤后,可重启计算机,通过redis-cli看看是否有自动启动redis,如果不行,可以通过指令redis-server /etc/redis/端口号.conf启动redis,通过这串指令可以让redis按照配置文件载入配置,redis启动失败,可能是配置文件中的配置找不到相应的文件夹或者文件造成的,根据终端返回的错误信息解决即可。
redis如何随系统启动的更多相关文章
- aws上redhat安装redis服务记
1.准备 官网下载
- CentOS搭建Apache+php+MySQL+Redis环境
要搭建一个本地linux服务器环境,按照网络教程依葫芦画瓢,噼里啪啦搭好后,发现redis服务怎么也弄不好,不喜欢那种明知有问题却无从下手又无能为力的感觉,碰了无数次壁以后,我决定卸载,重头来过,并尽 ...
- Centos7 安装 Redis
关闭防火墙:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启 ...
- Centos7安装Redis 3.2.8
关闭防火墙和SELinx 关闭防火墙 [root@node1 ~]# systemctl stop firewalld 开启防火墙 [root@node1 ~]# systemctl enable f ...
- NoSQL -- Redis使用
NoSQl简介: ubuntun CTRL+alt+F1 图形切换到命令行 CTRL+alt+F7 命令行切换到图形界面 redis介绍 + 实践 Redis是什么? Redis 安装 edis是当 ...
- CentOS 7安装配置Redis数据库
Redis源码获取 1.进入Redis官网获取Redis最新稳定版下载地址 2.通过wget命令下载 Redis 源代码. Redis编译 1.通过tar -xvf redis-3.0.2.tar ...
- centos7上安装redis
关闭防火墙:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启 ...
- CentO7 安装 redis, 主从配置,Sentinel集群故障转移切换
一.Redis的安装(前提是已经安装了EPEL) 安装redis: yum -y install redis 启动/停止/重启 Redis 启动服务: systemctl start re ...
- centos7配置安装redis
关闭防火墙:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启 ...
随机推荐
- HBase启动后RegionServer自动挂原因及解决办法
zookeeper在同步和管理集群时依赖节点系统时间,每隔一定周期zookeeper master会监测所有节点的连接状态.所以解决办法就是利用ntp对集群局域网进行时间同步. CentOS设置系统时 ...
- Package has no installation candidate解决方法
今天在安装软件的时候出现了Package has no installation candidate的问题,如:# apt-get install <packagename>Reading ...
- css加载字体跨域问题
刚才碰到一个css加载字体跨域问题,记录一下.站点的动态请求与静态文件请求是不同的域名的.站点的域名为 www.domain.com,而静态文件的域名为 st.domain.com.问题:页面中加载c ...
- Typescript学习总结1
Typescript字符串处理 首先打开运行Typescript的编辑器 http://www.typescriptlang.org/play/index.html 1. 调用变量和方法 var my ...
- python 中变量引用问题
普通变量,如a=10,str="fdaf",它们在函数内的值是不会被带到函数外的,除非在函数内加上global,而引用是惰性原则,从最近的同名父级同名变量引用值 其它变量如列表,字 ...
- Delphi 与 C/C++ 数据类型对照表
Delphi 数据类型 C/C++ ShorInt 8位有符号整数 char Byte 8位无符号整数 BYTE,unsigned short SmallInt 16位有符号整数 short Word ...
- 一个简单的PHP短信群发
function bulksms(){ ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limit( ...
- JAVA常量与变量
顺着箭头的转换为自动转换逆这箭头的转换为强制转换. 常量 关键字FINAL 命名为大写 标识符 1要以字母数字下划线和¥组成 2首字母不能为数字 3不能是JAVA的关键字和 保留字 4数据类型分为基本 ...
- http网站上传文件大小问题【没测试过】
web.config <httpRuntime maxRequestLength="" executionTimeout=""/> IIS 请求筛选 ...
- a标签返回上一页,并刷新
<a href="javascript:" onclick="self.location=document.referrer;">返回上一页并刷新& ...