Install Redis on Ubuntu 22.04 LTS

Redis Installation Guide on Ubuntu 22.04 LTS

Redis is an open source in-memory data storage that can be used as a database, cache, message broker, etc. This article will introduce two different installation methods, including compiling and installing from source code and installing through the apt package manager.

1. Compile and install Redis from source code

First, we need to download the latest Redis source code. Open a terminal and enter the following command:

# 下载源码
wget http://download.redis.io/releases/redis-7.0.10.tar.gz
# 解压
tar xzf redis-7.0.10.tar.gz
# 进入目录
cd redis-7.0.10

Then, run the make command to compile the Redis source code:

# 编译
make

Next, we switch to the root user and execute the make install command to install Redis:

sudo make install

Finally, we need to create a data directory called redis and set the correct permissions:

# 创建目录
mkdir /var/lib/redis
# 设置权限
chown redis:redis /var/lib/redis

2. Install Redis through apt package manager

For those who prefer to install software through a package manager, you can install Redis through apt on Ubuntu 22.04 LTS. First, update your package list:

sudo apt update

Then, install the Redis server and client:

sudo apt install redis-server redis-tools

After the installation is complete, you can verify that Redis is installed correctly by running the redis-cli command:

sudo systemctl status redis-server.service
redis-cli 

Insert image description here

If you can see PONG in response, then Redis has been installed successfully!

3. Configure redis port, password, and IP

Open the Redis configuration file. The default configuration file path is /etc/redis/redis.conf.

sudo vim /etc/redis/redis.conf

Modify port:
Find the line port 6379 in the configuration file. The 6379 here is the Redis default Listening port. You can change it to any other unoccupied port, such as 6380, 6381, etc.

Set password:
Find the line requirepass foobared in the same configuration file. Here foobared is the default password for Redis, to improve security we should replace it with your own password.

Set IP:
found in the file bind and protected-mode this Two options. Change the value in the bind option to your IP address or 0.0.0.0 to allow access from all IPs. Set the protected-mode option to no or yes to disable or enable protected mode.

Restart Redis:
After modifying the configuration file, remember to save and exit. Then restart Redis and the new port and password will take effect. In Linux or Mac, you can use the service redis restart command, and in Windows, you can use the restart function in the Task Manager.

sudo service redis restart
sudo systemctl restart redis-server.service

Summarize

Whether you choose to compile and install from source or install through the apt package manager, you can easily install Redis on Ubuntu 22.04 LTS. Redis is a very powerful and flexible data storage tool that is worth trying and using in your projects.

Guess you like

Origin blog.csdn.net/weixin_45626288/article/details/134684876