Redis is an in-memory key-value store prized for microsecond-level latency. Running it in side a private network is straightforward, but making it reachable from anywhere requires an extra hop. Below you’ll learn how to compile Redis on CentOS 8, seecure it for remote clients, and then punch a stable TCP tunnel through any NAT or firewall using cpolar.
- Build Redis from source
cd /usr/local
curl -O https://download.redis.io/releases/redis-7.2.4.tar.gz
tar xf redis-7.2.4.tar.gz
cd redis-7.2.4
make -j$(nproc)
make install PREFIX=/opt/redis
The binaries now live under /opt/redis/bin. Start the server once to verify everything works, then stop it with Ctrl-C.
- Harden the configuration
cp /opt/redis/redis.conf /opt/redis/redis.conf.bak
vim /opt/redis/redis.conf
Apply these changes:
daemonize yes– detach from the terminalbind 0.0.0.0– listen on every interface (or restrict to specific IPs)protected-mode no– required when no password is set (see next bullet)requirepass Sup3rSecret!– enforce authenticationmaxmemory 256mb– optional safeguard against RAM exhaustion
/opt/redis/bin/redis-server /opt/redis/redis.conf
Redis is now running in the background on port 6379.
- Install cpolar
curl -fsSL https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
sudo cpolar authtoken <YOUR-TOKEN>
sudo systemctl enable --now cpolar
Confirm the daemon is active:
sudo systemctl status cpolar
- Expose Redis to the Enternet
4.1 Quick one-off tunnel
cpolar tcp 6379
The CLI prints a temporary hostname and port (e.g., 3.tcp.cpolar.io:11235). You can connect immediately with:
redis-cli -h 3.tcp.cpolar.io -p 11235 -a Sup3rSecret!
This endpoint expires after 24 hours.
4.2 Persistent reserved endpoint
- Log in to the cpolar dashboard → Reserved → TCP Address.
- Select region
China VIP, add a description likeprod-redis, and click Reserve. - Copy the fixed address shown (e.g.,
redis-prod.tcp.cpolar.io:18543). - Create a permanent tunnel configuration:
sudo mkdir -p /etc/cpolar
sudo vim /etc/cpolar/redis.yml
/etc/cpolar/redis.yml
tunnels:
redis-prod:
proto: tcp
addr: 6379
remote_addr: redis-prod.tcp.cpolar.io:18543
sudo systemctl restart cpolar
From now on, every reboot will automatically re-establish the tunnel to the same public host and port.
- Verify remote connectivity
Using redis-cli from any machine:
redis-cli -h redis-prod.tcp.cpolar.io -p 18543 -a Sup3rSecret! ping
Expected response:
PONG
You can also point GUI clients like RedisInsight or Another Redis Desktop Manager to the same endpoint.
- Security checklist
- Keep
requirepassstrong and rotate it periodically. - If feasible, restrict source IPs in the cpolar dashboard.
- Consider enabling TLS (stunnel or Redis 6+ native TLS) to protect data in transit.
- Monitor
MONITORorSLOWLOGfor suspicious activity.