Records : 399
Scenario : Install redis-6.2.5 on Linux.
Official website address : https://redis.io/
Source address : https://github.com/redis/redis
Download address : http://download.redis.io/releases/
Version : redis-6.2.5, CentOS 7.9.
Description : Install redis-6.2.5 by compiling source code.
1. Download redis-6.2.5
Download command: wget http://download.redis.io/releases/redis-6.2.5.tar.gz
Analysis: After the download is complete, the package is redis-6.2.5.tar.gz.
2. Unzip redis- 6.2.5
Unzip redis-6.2.5 to the specified directory /opt/redis/.
Command: tar -zxvf redis-6.2.5.tar.gz -C /opt/redis/
Analysis: After decompression, the full path of the source code is: /opt/redis/redis-6.2.5.
3. Install gcc
To install redis-6.2.5 by compiling source code, a higher version of gcc is required. The following method can solve this requirement.
(1) Install gcc
Installation command: yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils gcc
(2) configure gcc
Contents: echo 'source /opt/rh/devtoolset-9/enable'>>/etc/profile
Effective: source /etc/profile
(3) Check the gcc version
Command: gcc --version
Print information: gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
4. Compile redis-6.2.5
Operation directory: cd /opt/redis/redis-6.2.5
Compile command: make -C /opt/redis/redis-6.2.5
Analysis: After redis is compiled, .o files and redis-server files are generated in the redis-6.2.5/src directory, and the ./deps folder is generated.
5. Install redis-6.2.5
Install redis to the specified directory, the default is /usr/local/.
5.1 install redis
Operation directory: cd /opt/redis/redis-6.2.5
Installation command: make install PREFIX=/opt/redis/redis-6.2.5
Analysis: Install redis-6.2.5 into the /opt/redis/redis-6.2.5 directory. Generate a bin directory, which contains the installed redis.
5.2 Redis generated files
After the installation is complete, there are files under the installation directory /opt/redis/redis-6.2.5/bin: redis-benchmark, redis-check-aof -> redis-server, redis-check-rdb -> redis-server, redis- cli, redis-sentinel -> redis-server, redis-server. Where -> is a soft link symbol.
Analysis: If you need to move the contents of the bin directory, you can go to the /opt/redis/redis-6.2.5/src directory and copy the source files away.
6. Create a redis node
The result files generated by compiling redis-6.2.5 are in the /opt/redis/redis-6.2.5/bin directory. Multiple redis nodes on one host can share these files. Therefore, creating a redis node means that each node creates an independent configuration file on the line.
This example deploys a singleton redis. Node name: node-28001. The port number is 28001. Below is the node directory.
Configuration directory: mkdir -p /opt/redis/node-28001/conf
Data directory: mkdir -p /opt/redis/node-28001/data
Log directory: mkdir -p /opt/redis/node-28001/log
Running directory: mkdir -p /opt/redis/node-28001/run
7. Copy the redis configuration to the node directory
Copy the redis.conf configuration file from /opt/redis/redis-6.2.5 to the cluster configuration directory.
Node 28001: cp -r /opt/redis/redis-6.2.5/redis.conf /opt/redis/node-28001/conf/
8. Modify the configuration file
Modify the file: vi /opt/redis/node-28001/conf/redis.conf
Modifications:
port 28001
bind 192.168.19.203
daemonize yes
pidfile /opt/redis/node-28001/run/redis.pid
logfile "/opt/redis/node-28001/log/stdout.pid"
dir /opt/redis/node-28001/data
appendonly yes
masterauth <h123456>
requirepass h123456
#bind 127.0.0.1 -::1
9. Start redis
9.1 start
Operation directory: /opt/redis/redis-6.2.5/bin
Start the node: /opt/redis/redis-6.2.5/bin/redis-server /opt/redis/node-28001/conf/redis.conf
9.2 Check the startup log
View logs: tail -f -n 300 /opt/redis/node-28001/log/stdout.pid
9.3 Check the listening port
Command: netstat -atulnp | grep redis
10. Log in to redis using the command line
Operation directory: /opt/redis/redis-6.2.5/bin
Login command: ./redis-cli -h 192.168.19.203 -p 28001 -a h123456
Exit command: exit
Parsing: ./redis-cli, client command; -h, specify host IP; -p, specify port; -a demo123456, specify password.
11. Use RedisDesktopManager to log in to redis
IP/Port: 192.168.19.203:28001
Password: h123456
12. Based on the use of redis by ordinary users
When starting redis, do not use the root user to start directly, it is recommended to use a normal user.
Just change the installation directory and assign it to a normal user.
12.1 Create common user actions
Create user command: useradd learn
Change password command: passwd
Analysis: When executing passwd, it prompts for a password. User information can be viewed: cat /etc/passwd.
12.2 Ordinary user information
Username/Password: learn/h123456
12.3 Authorize the redis installation directory to ordinary users
命令:chown -R learn:learn /opt/redis
12.4 start redis
Switch user: su learn
Operation directory: cd /opt/redis/redis-6.2.5/bin
Start: /opt/redis/redis-6.2.5/bin/redis-server /opt/redis/node-28001/conf/redis.conf
Above, thanks.
April 11, 2023