Redis7.X stand-alone environment source code installation guide


foreword

The first blog in the Redis series starts with the installation and deployment. Here I choose the latest stable versionRedis 7.0.9 Released


1. Official documents

Official website address: https://redis.io/docs/getting-started/installation/install-redis-from-source/

In addition, you can also view the files under the installation package during the installation process README.md.
insert image description here
Tip:
To learn a new technology, it is recommended to check the official documentation first. It may not be the most detailed and easy to understand, but it must be the most comprehensive and accurate.

2. Environmental description

  • CentOS 7.X
  • Redis 7.0.X

3. Source code installation

The official website provides us with 4 installation methods, here is the 4th method: installation based on source code Install Redis from Source.
insert image description here

1. Basic steps

The code is as follows (example):

//一般用户自行安装的软件都放在/usr/local/目录下
cd /usr/local/

//下载最新的稳定版本
wget https://download.redis.io/redis-stable.tar.gz

//解压
tar -xzvf redis-stable.tar.gz
cd redis-stable

//编译,需要gcc编译器
make

//测试:官方建议操作,但比较耗时,可以跳过,需要tcl 8.5
//make test

//安装服务
make install

//启动redis服务
redis-server

make install instructions:
The make install command will install the service to the /usr/local/redis-stable/src/and /usr/local/bin/directory by default.
insert image description here
If you want to re-specify the installation directory, you can apply the PREFIX parameter:
insert image description here

The redis-server service started successfully:insert image description here

2. Abnormal record

1) make compilation exception: make[3]: cc: command not found

insert image description here
Solution:
The reason is that gcc is missing in the CentOS7 virtual machine system, so just install gcc

yum -y install gcc

2) Make compilation exception: zmalloc.h:50:31: Fatal error: jemalloc/jemalloc.h: No such file or directory

insert image description hereSolution:
Since the gcc compiler was not installed in advance when decompressing, a lot of garbage problems have been generated in the first make.
At this time, you need to delete the previous compilation file and execute the make compilation operation again.

cd /usr/local/
rm -fr redis-stable
tar -xzvf redis-stable.tar.gz
cd redis-stable
make

You can also use make distcleanthe command to clear the cache file generated by executing make before compiling, and then recompile:

make distclean
make

3)make test异常:You need tcl 8.5 or newer in order to run the Redis test

insert image description here
solution:

yum install -y tcl-devel

It can also be installed through source code, but the download speed is very slow.

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz  
cd  /usr/local/tcl8.6.1/unix/
./configure
make
make install

Test passed:
insert image description here

3. Testing service

Open a new connection window and use redis-cli to test the redis service

[root@localhost ~]# cd /usr/local/
[root@localhost local]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set laowan 666
OK
127.0.0.1:6379> get laowan
"666"
127.0.0.1:6379> incr mycounter
(integer) 1
127.0.0.1:6379> incr mycounter
(integer) 2
127.0.0.1:6379> exit

4. Basic configuration

Here I directly modify the default configuration file redis.conf in the redis directory. You can also copy the new configuration file and then edit the properties:

cd /usr/local/redis-stable
vi redis.conf 
# 设置redis服务监听的实例,只有绑定IP的服务器才能访问redis服务,这里设置为全部开放,可以改为自己需要访问redis服务器的具体IP
bind * -::*

#保护模式,默认开启,此时远程服务器需要密码才能访问redis服务
protected-mode yes

#守护进程启动,也就是后台启动,会将进程pid写入/var/run/redis.pid文件中,systemd下无效
daemonize yes
#配置pid文件的保存地址
pidfile /var/run/redis_6379.pid

#日志等级
loglevel notice
#日志文件,默认/dev/null
logfile ""

#认证配置
#redis7中推荐采用acl认证
#aclfile /etc/redis/users.acl
#密码认证
requirepass 123456

#设置最大内存,避免Redis使用的内存达到系统限制时会因内存不足而崩溃
maxmemory 1g
#过期淘汰策略,默认是noeviction不淘汰,这里设置为淘汰最不经常使用的过期key
maxmemory-policy volatile-lfu

5. Other recommended configurations

It can be found that there will be some warning ⚠️ information in the redis startup log, try to optimize according to the prompts.
insert image description here

  • TCP backlog backlog setting, indicating the upper limit of the backlog of socket listening (listen). The backlog is the listening queue of the socket. When a request (request) has not been processed or established, it will enter the backlog. The default /proc/sys/net/core/somaxconnvalue is increase.
  • Enable memory overcommit: Add vm.overcommit_memory = 1to /etc/sysctl.conf, execute sysctl vm.overcommit_memory=1 to make the configuration take effect.
  • Turn off the kernel feature transparent huge pages, which can have a negative impact on memory usage and latency.echo never > /sys/kernel/mm/transparent_hugepage/enabled
  • Reduce the use of swap memory and improve performance.

Add the following to /etc/sysctl.conf:

//开启内存过量使用,避免后台保存或复制可能会在内存不足的情况下失败。 被禁用时,它也可能在没有低内存条件的情况下导致失败
vm.overcommit_memory = 1

//TCP积压backlog设置
net.core.somaxconn = 2048

//可以打开的最大文件数
fs.file-max = 6553560

//尽量少使用swap空间,swappiness=0的时候表示最大限度使用物理内存,然后才是swap空间,swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。linux的基本默认设置为60
//由于内存的速度会比磁盘快很多,这样子会加大系统IO,同时造的成大量页的换进换出,严重影响系统的性能,所以我们在操作系统层面,要尽可能使用内存,对该参数进行调整
vm.swappiness = 1

Execute the following command to make the parameters take effect

sysctl -p

6. Remote connection

RedisInsight is a Redis visualization client tool recommended by the official website, known as the best Redis GUI.
Here we use it to test the remote connection of the Redis service.

RedisInsight download link
insert image description here

Here my virtual machine IP is: 192.168.206.129, connection information:
insert image description here
the connection is successful:
insert image description here
insert image description here

Redis-6.x installation and troubleshooting
Set the swappiness parameter under Linux to configure how much memory is used before starting to use the swap partition

Guess you like

Origin blog.csdn.net/w1014074794/article/details/129352185