当前位置:网站首页>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
边栏推荐
- There are ways to improve self-discipline and self-control
- Cmu15445 (fall 2019) project 2 - hash table details
- 【全栈计划 —— 编程语言之C#】基础入门知识一文懂
- 聊聊SOC启动(六)uboot启动流程二
- 核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
- Flet教程之 16 Tabs 选项卡控件 基础入门(教程含源码)
- Flet教程之 14 ListTile 基础入门(教程含源码)
- 【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
- Verilog design responder [with source code]
- Neural approvals to conversational AI (1)
猜你喜欢
超标量处理器设计 姚永斌 第8章 指令发射 摘录
【全栈计划 —— 编程语言之C#】基础入门知识一文懂
Summed up 200 Classic machine learning interview questions (with reference answers)
STM32F1与STM32CubeIDE编程实例-315M超再生无线遥控模块驱动
LeetCode - 面试题17.24 最大子矩阵
MySQL安装常见报错处理大全
聊聊SOC启动(六)uboot启动流程二
【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】
Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]
随机推荐
自律,提升自制力原来也有方法
Apprentissage comparatif non supervisé des caractéristiques visuelles par les assignations de groupes de contrôle
深度学习秋招面试题集锦(一)
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
Various uses of vim are very practical. I learned and summarized them in my work
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
Unsupervised learning of visual features by contracting cluster assignments
How to write test cases for test coupons?
博客搬家到知乎
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting boxplot, and add significance levels and jitter points
正在运行的Kubernetes集群想要调整Pod的网段地址
Talk about SOC startup (VI) uboot startup process II
electron 添加 SQLite 数据库
Learning notes | data Xiaobai uses dataease to make a large data screen
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
《论文阅读》Neural Approaches to Conversational AI(1)
Solve the problem that vscode can only open two tabs
R语言使用magick包的image_mosaic函数和image_flatten函数把多张图片堆叠在一起形成堆叠组合图像(Stack layers on top of each other)
Two week selection of tdengine community issues | phase II
Half of the people don't know the difference between for and foreach???