CentOS Redis environment construction

1 Configure the basic environment

CentOS Linux release 7.6.1810 (Core) 
redis 5.0.5 
Copy the code

1. Download and decompress Redis and download the latest 5.0.5 version from the official website through wget

Wget HTTP: / / http://download.redis.io/releases/redis-5.0.5.tar.gzCopy the code

Note that wGET is not installed

-bash: wget: command not found
Copy the code

Install wget as follows

yum -y install wget
Copy the code

2 decompression redis

The tar - XZVF redis - 5.0.5. Tar. GzCopy the code

3. Install the required environment

Installing the GCC Environment

yum install gcc-c++
Copy the code

The installation process needs to download 21M size package, enter: y, press Enter to continue the installation, finally appear Complete! Indicates the installation is complete.

4. Compile

Go to the redis-5.0.5 directory and run make install in the SRC directory

CD redis - 5.0.5 / SRC make installCopy the code

The following error may be reported

Solution Run the following command

make install MALLOC=libc	
Copy the code

Reason: For allocator, if the MALLOC environment variable is available, it will be used to create Redis. And liBC is not the default allocator, jemalloc is the default, because jemalloc has been proven to have fewer fragmentation problems than LIBC. But if you don’t have jemalloc and you only have libc of course make fails. So I add this argument.

Installation completed as follows

5. Configure and start the configuration

1. Create a data directory and create folders bin and etc in the data directory

mkdir /data
cd /data
mkdir bin
mkdir etc
Copy the code

2. Move the file

2.1 Move the main configuration file redis.conf in redis-5.0.5 to the newly created etc folder

cdRedis - 5.0.5 mv redis. Conf/data/redis/etcCopy the code

2.2 Move all the files marked with green in the SRC directory to the bin folder

cd src/
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /data/redis/bin/
Copy the code

2.3 Modifying the Master Configuration File

2.3.1 Go to the etc directory and modify the redis.conf file
cd /data/redis/etc
vi redis.conf
Copy the code
2.3.2 Comment out the bind 127.0.0.1 line or change it to 0.0.0.0 (resolves the restriction that only certain network segments can be connected)

2.3.3 Change the protected-mode attribute to no (turn off the protected mode, otherwise remote access will be blocked)

2.3.4 Change the daemonize property to yes (so that startup is started in the background)

2.3.5 Setting a Password (Optional. You are advised to set a password)

After the modification is complete, save wq and exit (press Esc, then enter :wq).

3 start

1. Run the command in the redis bin directory

cd /data/redis/bin
./redis-service /data/redis/etc/redis.conf
ps -ef | grep redis
Copy the code

2. Enable the firewall

Firewall-cmd --zone=public --add-port=6379/ TCP --permanent ## Open port firewall-cmd --query-port=6379/ TCP ## Open port: Firewall-cmd --reload ## reload the firewall: firewall-cmd --list-port ##Copy the code

The public,

If you want to follow my updated articles and shared dry goods in real time, you can follow my official account.