linux 启动 redis
时间: 2023-10-18 20:30:38 浏览: 91
要在Linux上启动Redis,可以按照以下步骤进行操作:
1. 假设Redis已经安装,并将版本设置为3.2.4。
2. 将配置文件redis.conf复制到/etc/redis目录下,并重命名为6379.conf。
3. 复制启动脚本redis_init_script到/etc/init.d/redis目录下,并设置为可执行权限。
4. 将redis-server可执行文件复制到/usr/local/bin目录下。
5. 执行以下命令启动Redis:
```
cd redis-3.2.4
./redis-server &
```
这将使Redis以后台程序方式运行。
另外,如果想要设置Redis在开机时自动启动,可以使用redis_init_script脚本进行配置。该脚本位于Redis的/utils/目录下,代码如下所示:
```shell
#!/bin/sh
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# Redis服务器监听的端口
REDISPORT=6379
# 服务端所处位置
EXEC=/usr/local/bin/redis-server
# 客户端位置
CLIEXEC=/usr/local/bin/redis-cli
# Redis的PID文件位置,需要修改
PIDFILE=/var/run/redis_${REDISPORT}.pid
# Redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/etc/redis/${REDISPORT}.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
```
通过使用这个脚本,可以在启动脚本redis_init_script中设置开机自启动。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Linux中设置Redis开机启动的方法](https://download.csdn.net/download/weixin_38679276/14907649)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [redis的三种启动方式](https://blog.csdn.net/weixin_30838921/article/details/97570391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文