Home > Database > Redis > How to start redis in linux environment

How to start redis in linux environment

Release: 2019-07-08 09:16:12
Original
20380 people have browsed it

How to start redis in linux environment

启动redis

redis可执行文件说明:

redis-server:redis服务器

redis-cli:redis命令行客户端

redis-benchmark:redis性能测试工具

redis-check-aof:aof文件修复工具

redis-check-dump:rdb文件检查工具

1、直接启动

直接运行redis-server即可以启动redis

redis服务器默认会使用6379端口,通过--port参数可以自定义端口号:

redis-server --port 6380

如果出现警告:

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 

To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。

按这个提示来做,警告排除。

2、通过初始化脚本启动redis

redis源码目录的utils文件夹中有一个名为redis-init_script的初始化脚本文件

步骤

(1)配置初始化脚本。

首先将初始化脚本复制到/etc/init.d目录中,文件名为redis_端口号(redis_6379),然后修改脚本第6行的REDISPORT的变量值为同样的端口号(ubuntu)

如果是centos或者redhat则使用以下脚本(端口号根据实际情况修改)

#chkconfig: 2345 90 10

#description: Redis is a persistent key-value database

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379

EXEC=/usr/local/bin/redis-server

REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_6379.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

if [ "$?"="0" ]

then

echo "Redis is running..."

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo "$PIDFILE does not exist, process is not running"

else

PID=$(cat $PIDFILE)

echo "Stopping ..."

$REDIS_CLI -p $REDISPORT SHUTDOWN

while [ -x ${PIDFILE} ]

do

echo "Waiting for Redis to shutdown ..."

sleep 1

done

echo "Redis stopped"

fi

;;

restart|force-reload)

${0} stop

${0} start

;;

*)

echo "Usage: /etc/init.d/redis_6379 {start|stop|restart|force-reload}" >&2

exit 1

esac
Copy after login

(2)建立需要的文件夹

/etc/redis    存放redis配置文件

/var/redis/端口号    存放redis的持久化文件

(3)修改配置文件

把配置文件模板复制到/etc/redis目录中,已端口号命名(如“6379.conf”)

需要修改的配置及说明:

daemonize  yes:使redis以守护进程模式运行

pidfile /var/run/redis_端口号.pid:设置redis的pid文件位置

port 端口号:设置redis监听的端口号

 dir /var/redis/端口号:设置持久化文件存放位置

设置开机启动服务:

sudo update-rc.d redis_端口号 defaults // 告诉系统启动时候,自动执行redis_端口号 这个脚本。(ubuntu)

更多Redis相关知识,请访问Redis使用教程栏目!

The above is the detailed content of How to start redis in linux environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template