Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Redis under Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to build Redis under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

Redis is a high-performance key-value database. The emergence of redis makes up for the deficiency of keyvalue storage such as memcached to a great extent, and can play a good complementary role to relational database in partial situations.

download

Download from the official website: http://redis.io/download

Installation

Tar zxvf redis-2.8.9.tar.gz # decompress cd redis-2.8.9 # enter the directory make # directly make compile make install # you can use the root user to execute `make install` and copy the executable file to the / usr/local/bin directory, so you can directly type the name to run the program

Start (there are three ways)

Direct start

1. Execute the command:

. / redis-server & # plus `&` to make redis run as a daemon

2. Detection

Ps-ef | grep redis # detects whether netstat-lntp exists in the background process | grep 6379 # detects whether port 6379 is listening. / redis-cli # uses the `redis- cli` client to detect whether the connection is normal 127.0.0.1grep redis 6379 > keys * (empty list or set) 127.0.0.1lntp 6379 > set key "hello world" OK127.0.0.1:6379 > get key "hello world"

3. Stop

Redis-cli shutdown # uses client-side kill-9 PID # because Redis can properly handle SIGTERM signals, so direct kill-9 is also possible

Start by specifying a configuration file

1. The configuration file can be used to specify the configuration file for redis service startup. The configuration file redis.conf is located in the Redis root directory:

Daemonize yes # modify daemonize to yes, that is, run port 6380 # in daemon mode by default. The default listening port can be modified. The original value is 6379. We modified it to 6380logfile "/ home/futeng/logs/redis.log" # modify the default log file location # modify the default log file location dir / home/futeng/data/redisData # modify the default log file location

2. Specify the configuration file at startup

Redis-server. / redis.conf # specify a configuration file in the directory redis-cli-p 6380 # if you change the port, you also need to specify the port when using the `redis- cli` client connection

Other starts and stops are the same as direct start-up mode. Configuration files are very important configuration tools, which will be especially important as they are used more and more deeply. It is recommended to use configuration files at the beginning.

Use the Redis startup script to set up boot self-startup

1. Startup script it is recommended to use startup script to start redis service in production environment. Startup script redis_init_script is located in the / utils/ directory of Redis:

# A general glance at the startup script shows that redis habitually uses the port name of the listener as the name of the configuration file, and we follow this convention later. # the location of the REDISPORT=6379# server on which the redis server listens is stored as `/ usr/local/bin/redis- server` by default after make install. If there is no make install, the path needs to be modified, as shown below. EXEC=/usr/local/bin/redis-server# client location CLIEXEC=/usr/local/bin/redis-cli#Redis PID file location PIDFILE=/var/run/redis_$ {REDISPORT} .pid # configuration file location, need to modify CONF= "/ etc/redis/$ {REDISPORT} .conf"

2. According to the requirements of the startup script, the configuration environment copies a copy of the modified configuration file to the specified directory under the name of the port. You need to use the root user:

Mkdir / etc/rediscp redis.conf / etc/redis/6379.conf

Copy the startup script to the / etc/init.d directory. In this example, the startup script is named redisd (usually ending with d to indicate a background self-starting service):

Cp redis_init_script / etc/init.d/redisd

Set to boot self-startup, which is directly configured here.

Chkconfig redisd on

An error will be reported: service redisd does not support chkconfig, we need to add the following two lines at the beginning of the startup script to modify its run level:

#! / bin/sh # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database # can be successfully set again.

Chkconfig redisd on # set to boot the server service redisd start # turn on the service service redisd stop # turn off the service

Thank you for reading this article carefully. I hope the article "how to build Redis under Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report