Table of contents
1. Linux (centos8) install redis database
3.1 Install cpolar intranet penetration
3.2 Create a tunnel mapping local port
4. Configure a fixed TCP port address
4.1 Reserve a fixed tcp address
4.2 Configure fixed TCP address
4.3 Use a fixed tcp address to connect
foreword
Redis, as a cached database of key-value key-value pairs, is widely used in many scenarios. Since the data is stored in memory, the reading and writing efficiency is extremely high.
The following describes how to build redis in linux of the internal network virtual machine and realize public network access through cpolar internal network penetration
1. Linux (centos8) install redis database
-
Enter the local directory under user, usually the external software is installed in this directory
cd /usr/local
-
download redis
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
-
After downloading, unzip redis
tar xzf redis-6.2.6.tar.gz
-
After decompression, enter the redis directory to compile
cd redis-6.2.6/
-
Enter after entering
make
, wait for the compilation to complete after entering
After compiling, enter the following command to install redis
make install PREFIX=/usr/local/redis-6.2.6
After installation, enter the redis directory and execute the following command to start redis. The default port is6379
./bin/redis-server redis.conf
then Ctrl+C
exit
2. Configure redis database
Configure redis to run in the background, edit the configuration fileredis.conf
vim /usr/local/redis-6.2.6/redis.conf
daemonize no
Change todaemonize yes
Also modify the following two parameters separately to enable remote access
After the modification is completed, save and exit the configuration file, restart redis and then execute the following startup command again, and find that the redis graphic is gone, which is the background startup
./bin/redis-server redis.conf
3. Intranet penetration
cpolar is an intranet penetration software, easy to use, safe and reliable, free to use, unlimited traffic, support http/https/tcp protocol. We can expose the local port 6379 to the public network through cpolar, and then use tools for remote access.
cpolar official website: cpolar - a secure intranet penetration tool
3.1 Install cpolar intranet penetration
-
Linux supports installation using one-click script commands
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
-
token authentication
Log in to the background of the cpolar official website, click the verification on the left to view your own authentication token, and then execute the following command, where xxxx is the token code
cpolar authtoken xxxxxxx (your token)
-
Add services to the system (to facilitate self-starting at boot)
sudo systemctl enable cpolar
-
Start the cpolar service
sudo systemctl start cpolar
3.2 Create a tunnel mapping local port
After cpolar is successfully installed, enter the following command on the command line to expose the local redis on port 6369 to the public network
cpolar tcp 6379
The following interface appears to indicate success, and then copy the public network address
Use the redis graphical interface to remotely connect to redis, enter the copied tcp address, and click Test Connection
appears successful
to indicate success
Note: If you want to make the tunnel accessible for a long time, you can save it to the configuration file to implement background services. Please refer to cpolar official website - documentation - command line to create a tunnel - configure the tunnel as a background service
4. Configure a fixed TCP port address
The above steps use a random temporary tcp port address, and the generated public network address is a random temporary address, which will change randomly within 24 hours. And we can configure a fixed public network address for it to facilitate subsequent long-term remote.
4.1 Reserve a fixed tcp address
Log in to the cpolar official website, click Reserve on the left, and find the reserved tcp address. Let's reserve a fixed tcp address for the remote Redis database:
-
Region: Select China VIP
-
Description: It is a note, which can be customized
click保留
After the address is successfully reserved, the system will generate a corresponding fixed public network address and copy it down
4.2 Configure fixed TCP address
Edit the cpolar configuration file
vim /usr/local/etc/cpolar/cpolar.yml
Copy and add the following information, the remote_addr parameter is the reserved tcp address copied above
redis: addr: 6379 proto: tcp remote_addr: 3.tcp.vip.cpolar.cn:11506
After modifying, save and exit, then restart the cpolar service
sudo systemctl start cpolar
4.3 Use a fixed tcp address to connect
If successful appears, it means success