当前位置:网站首页>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
.gz
Next, 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/redis
Then 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 install
Install 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/redisd
stay /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 on
Then 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 stop
Equivalent to
[[email protected] zhxilin]
# /etc/init.d/redisd start
[[email protected] zhxilin]
# /etc/init.d/redisd stop
summary
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
边栏推荐
- Internet Protocol
- Automated testing framework
- 聊聊SOC启动(十一) 内核初始化
- 大佬们有没有人遇到过 flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取
- 一起探索云服务之云数据库
- 'module 'object is not callable error
- Complete collection of common error handling in MySQL installation
- 核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
- Mastering the new functions of swiftui 4 weatherkit and swift charts
- 【数据聚类】基于多元宇宙优化DBSCAN实现数据聚类分析附matlab代码
猜你喜欢
聊聊SOC启动(十一) 内核初始化
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
. Net Maui performance improvement
Talk about SOC startup (11) kernel initialization
Flet教程之 14 ListTile 基础入门(教程含源码)
What development models did you know during the interview? Just read this one
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
总结了200道经典的机器学习面试题(附参考答案)
随机推荐
Half of the people don't know the difference between for and foreach???
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
相机标定(1): 单目相机标定及张正友标定基本原理
【数据聚类】基于多元宇宙优化DBSCAN实现数据聚类分析附matlab代码
Case study of Jinshan API translation function based on retrofit framework
STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
[Yugong series] go teaching course 005 variables in July 2022
超标量处理器设计 姚永斌 第10章 指令提交 摘录
Flet教程之 15 GridView 基础入门(教程含源码)
《论文阅读》Neural Approaches to Conversational AI(1)
【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
Android 面试知识点
禁锢自己的因素,原来有这么多
[system design] index monitoring and alarm system
Onedns helps college industry network security
What development models did you know during the interview? Just read this one
The running kubernetes cluster wants to adjust the network segment address of pod
Talk about SOC startup (IX) adding a new board to uboot
一起探索云服务之云数据库
Audit migration