当前位置:网站首页>Steps of redis installation and self startup configuration under CentOS system
Steps of redis installation and self startup configuration under CentOS system
2022-07-07 11:49:00 【Full stack programmer webmaster】
I'm sure you all know that Redis It's a C The implementation is memory based 、 Persistent key value pairs for database , It is often used as a caching service in distributed services . So this article will introduce in detail CentOS How to install from scratch to configure and start the service under the system . If necessary, we can refer to .
One . install Redis
Redis The installation of is actually quite simple , The recommended way is to download redis Source code , And install after native compilation .
Enter the download directory of the main folder for the first time , perform wget Download the source code
[[email protected] ~]$
cd
download
[[email protected] download ]$ wget http:
//download
.redis.io
/redis-stable
.
tar
.gzNext, after decompression , Move to /usr/redis Under the table of contents
[[email protected] download ]$
tar
-zxvf redis-stable.
tar
.gz
[[email protected] download ]$
su
mv
redis-stable
/usr/redisThen enter redis Catalog , perform make command , compile redis Source code
[[email protected] download ]
# cd /usr/redis/
[[email protected] redis]
# make After compiling , stay src Directory is 2 An important program generation , One is redis-server, The other is redis-cli; Then enter the src Catalog , perform make install, At this time, these executable programs will be copied to /usr/local/bin Under the table of contents , because /usr/local/bin Is the environment variable in the system $PATH Defined , Therefore, the terminal can execute... At any position redis-server and redis-cli 了 .
[[email protected] redis]
# cd src/
[[email protected] src]
# make installInstall here redis That's it .
Let's see what the compiled programs do :
redis-server: seeing the name of a thing one thinks of its function ,redis service
redis-cli:redis client, Provide a redis client , For connection to redis service , Add, delete, modify, check, etc
redis-sentinel:redis Instance monitoring management 、 Notification and instance failure backup service
redis-benchmark:redis Performance testing tools for
redis-check-aof: If the AOF Way to generate logs , It is used to repair quickly when accidents happen
redis-check-rdb: If the RDB Way to generate logs , It is used to repair quickly when accidents happen
After installation , start-up redis-server, And run redis-cli To test
[[email protected] ~]$ redis-server[[email protected] ~]$ redis-cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> So to speak redis The service has been working normally , If redis Service not started , Then run redis-cli It will be reported in time Could not connect to Redis at 127.0.0.1:6379: Connection refused Error of .
Two . Configure self startup
In order to make redis-server It can run automatically when the system starts , Need to put redis Services as daemons (daemon) To run the , We go back to /usr/redis/ Found one in the directory redis.conf The file of , This file is redis Configuration loaded by service runtime , Let's take a look at the content first
[[email protected] redis]$
vi
redis.conf This file is very long , But most of them are annotations , We focus on several of these settings daemonize and pidfile:
among daemonize The default value is false,pidfile The default value is pidfile /var/run/redis_6379.pid
The first indicates whether daemon turn , Obviously, we need to change it to daemonize yes;
The second means that when the service is running as a daemon ,redis By default the pid write in /var/run/redis_6379.pid file , The file exists when the service is running , Once the service stops, the file is automatically deleted , So it can be used to judge redis Is it running .
Exit after saving .
With the basic configuration ,redis There also needs to be a management startup 、 close 、 A script to restart .redis In fact, an initialization script has been provided in the source code , Position in /usr/redis/utils/redis_init_script.
Let's see what this script does :
#!/bin/sh#
REDISPORT=6379
EXEC=
/usr/local/bin/redis-server
CLIEXEC=
/usr/local/bin/redis-cli
PIDFILE=
/var/run/redis_
${REDISPORT}.pid
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 The port... Is specified in the script 、server route 、cli route 、pidfile Path and conf route , The above yellow areas need to be configured correctly , Many say , When installing make install, So the script here doesn't need to be changed much , because make install hold server and cli All copied to /usr/local/bin The following the .
In addition, see here conf The path of , We need to take redis In the catalog redis.conf File copy to /etc/redis/6379.conf
[[email protected] utils]
# cd /etc
[[email protected] etc]
# mkdir redis
[[email protected] etc]
# cp /usr/redis/redis.conf /etc/redis/6379.conf And then redis_init_script Copy the script to /etc/init.d/redisd
[[email protected] etc]
# cp /usr/redis/utils/redis_init_script /etc/init.d/redisdstay /etc/init.d The following scripts are all services that can be started automatically when the system starts , But now there is still a lack of configuration when the system starts :
[[email protected] zhxilin]
# chkconfig redisd onThen you will find that an error is reported : service redisd I won't support it chkconfig ?
It's because we need to be in redis_init_script Add a small change at the beginning of :
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database Save and copy to /etc/init.d/redisd after , Run again chkconfig It's done. .
When everything is ready , You can execute the following command to verify service Whether the setting is successful :
[[email protected] zhxilin]
# service redisd start
[[email protected] zhxilin]
# service redisd stopEquivalent to
[[email protected] zhxilin]
# /etc/init.d/redisd start
[[email protected] zhxilin]
# /etc/init.d/redisd stopsummary
Finally restart the system , Run directly after entering the system redis-cli test redis Whether the service has run automatically . The above is the whole content of this article , I hope the content of this article can bring some help to your study or work , If you have any questions, you can leave a message .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113810.html Link to the original text :https://javaforall.cn
边栏推荐
- EasyUI learn to organize notes
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
- STM32入门开发 编写DS18B20温度传感器驱动(读取环境温度、支持级联)
- 【系统设计】指标监控和告警系统
- SwiftUI 教程之如何在 2 秒内实现自动滚动功能
- R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
- Case study of Jinshan API translation function based on retrofit framework
- Flet教程之 17 Card卡片组件 基础入门(教程含源码)
- 软件内部的定时炸弹:0-Day Log4Shell只是冰山一角
- Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
猜你喜欢

Flet教程之 17 Card卡片组件 基础入门(教程含源码)

浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派

清华姚班程序员,网上征婚被骂?

MySQL安装常见报错处理大全

Talk about SOC startup (11) kernel initialization

【滤波跟踪】基于matlab扩展卡尔曼滤波EKF和无迹卡尔曼滤波UKF比较【含Matlab源码 1933期】

超标量处理器设计 姚永斌 第10章 指令提交 摘录

In my limited software testing experience, a full-time summary of automation testing experience

La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
![[shortest circuit] acwing1128 Messenger: Floyd shortest circuit](/img/a4/783bdcc2b97938efc77b7da6442866.png)
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
随机推荐
聊聊SOC启动(九) 为uboot 添加新的board
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
竟然有一半的人不知道 for 与 foreach 的区别???
请查收.NET MAUI 的最新学习资源
What is high cohesion and low coupling?
《论文阅读》Neural Approaches to Conversational AI(1)
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
The running kubernetes cluster wants to adjust the network segment address of pod
Easyui学习整理笔记
Tsinghua Yaoban programmers, online marriage was scolded?
STM32入门开发 编写DS18B20温度传感器驱动(读取环境温度、支持级联)
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
分布式数据库主从配置(MySQL)
The Oracle message permission under the local Navicat connection liunx is insufficient
Unsupervised learning of visual features by contracting cluster assignments
一起探索云服务之云数据库
Network protocol concept
對比學習之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments
In depth learning autumn recruitment interview questions collection (1)