当前位置:网站首页>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
边栏推荐
- sql里,我想设置外键,为什么出现这个问题
- STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
- What development models did you know during the interview? Just read this one
- ‘module‘ object is not callable错误
- Flet教程之 15 GridView 基础入门(教程含源码)
- Learning notes | data Xiaobai uses dataease to make a large data screen
- Unsupervised learning of visual features by contracting cluster assignments
- The running kubernetes cluster wants to adjust the network segment address of pod
- Use metersphere to keep your testing work efficient
- 聊聊SOC启动(七) uboot启动流程三
猜你喜欢
聊聊SOC启动(十) 内核启动先导知识
Summed up 200 Classic machine learning interview questions (with reference answers)
【全栈计划 —— 编程语言之C#】基础入门知识一文懂
Verilog design responder [with source code]
超标量处理器设计 姚永斌 第8章 指令发射 摘录
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
Reasons for the failure of web side automation test
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Talk about SOC startup (VI) uboot startup process II
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
随机推荐
The road to success in R & D efficiency of 1000 person Internet companies
What is cloud computing?
总结了200道经典的机器学习面试题(附参考答案)
What is high cohesion and low coupling?
The database synchronization tool dbsync adds support for mongodb and es
Automated testing framework
聊聊SOC启动(六)uboot启动流程二
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
Talk about SOC startup (VII) uboot startup process III
Flet教程之 14 ListTile 基础入门(教程含源码)
【滤波跟踪】基于matlab扩展卡尔曼滤波EKF和无迹卡尔曼滤波UKF比较【含Matlab源码 1933期】
Distributed database master-slave configuration (MySQL)
相机标定(1): 单目相机标定及张正友标定基本原理
深度学习秋招面试题集锦(一)
Enclosed please find. Net Maui's latest learning resources
.NET MAUI 性能提升
OneDNS助力高校行业网络安全
通过环境变量将 Pod 信息呈现给容器
博客搬家到知乎
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full