Error Medic

Resolving 'Connection Refused TCP 127.0.0.1:6379' and Extending LVM Storage in RHEL 7/8

Fix Redis connection refused tcp 127.0.0.1:6379 errors caused by out-of-memory or full disks. Learn to use lvextend and vgextend in RHEL 7/8 to expand storage.

Last updated:
Last verified:
1,522 words
Key Takeaways
  • Redis Connection Refused on 127.0.0.1:6379 is most frequently caused by the Redis daemon crashing, binding to the wrong interface, or storage exhaustion preventing RDB/AOF writes.
  • Disk space exhaustion in /var/lib/redis triggers MISCONF errors, abruptly stopping the Redis service and rejecting incoming TCP connections.
  • You can resolve storage-based Redis crashes using the lvextend command in RHEL 7 or RHEL 8 to dynamically increase logical volume size without downtime.
  • If the volume group lacks free physical extents, the vgextend command in RHEL 8 allows you to seamlessly integrate new block storage devices into your storage pool.
  • Always verify your filesystem type (XFS vs EXT4) before growing the partition, as RHEL 7 and RHEL 8 heavily favor XFS via the xfs_growfs utility.
Troubleshooting Approaches Compared
MethodWhen to UseTimeRisk
Service RestartTransient memory glitch or minor configuration update1-2 minsLow
Bind Address FixRedis listening on IPv6 (::1) or wrong network interface5 minsLow
lvextend (RHEL 7/8)Disk is 100% full, Redis cannot persist data to disk10 minsMedium
vgextend (RHEL 8)No free Physical Extents (PE) left in the Volume Group15 minsMedium

Understanding the Error: TCP 127.0.0.1:6379 Connection Refused

When working with caching layers, message brokers, or in-memory databases, developers frequently encounter the dreaded Could not connect to Redis at 127.0.0.1:6379: Connection refused error. This network-level rejection means your application (or the redis-cli utility) attempted a TCP handshake with the localhost loopback address on port 6379, but the operating system's networking stack firmly rejected it via an RST (Reset) packet.

While developers often assume this is a firewall issue or a corrupted redis.conf file, in production environments—specifically those running heavily utilized Linux servers—the root cause is frequently infrastructure-related. Specifically, the Redis daemon has crashed or been killed by the Linux OOM (Out of Memory) killer, or the underlying storage holding the Redis persistent data (dump.rdb or appendonly.aof) has reached 100% utilization.

When Redis attempts a background save (BGSAVE) and fails due to disk space, it throws a fatal MISCONF error and shuts down. To the end user or application, this manifests simply as a refused connection on tcp 127.0.0.1 6379.

Step 1: Diagnose the Service and Storage

Before making arbitrary changes, verify the status of the Redis service and the underlying disk. First, check if Redis is actively running and bound to the correct port:

systemctl status redis
netstat -plntu | grep 6379

If the service is listed as failed or inactive (dead), interrogate the system journal for the exact moment of failure:

journalctl -u redis -n 100 --no-pager

If you see log entries such as Can't save in background: fork: Cannot allocate memory or Short read or OOM loading DB, you have a resource limitation. The next step is to check your filesystem utilization, particularly the mount point housing /var/lib/redis (or your configured dir in redis.conf).

df -h /var/lib/redis

If the Use% column reports 100%, you have found the culprit. The Redis service will refuse to start or accept connections until it has sufficient space to write its persistence files.

Step 2: The Linux Logical Volume Management (LVM) Rescue

Enterprise Linux distributions like Red Hat Enterprise Linux (RHEL) abstract physical disks using LVM, allowing administrators to dynamically resize storage pools. To fix our broken Redis instance, we must execute a linux extend logical volume operation.

First, check if your Volume Group (VG) has any free space available to allocate to the Logical Volume (LV):

vgs

Look at the VFree column. If you have free space, you can proceed directly to extending the logical volume. If VFree is 0 or near zero, you must first add a new physical disk to the server (e.g., attaching a new EBS volume in AWS, or a new virtual disk in VMware) and extend the Volume Group.

Adding Physical Storage: vgextend command in RHEL 8

Assuming you have attached a new block device (/dev/sdb), you must initialize it as an LVM Physical Volume (PV) and add it to your existing Volume Group (let's call it rhel_vg). The vgextend command in rhel 8 functions flawlessly to expand the storage pool dynamically:

# Initialize the new disk
pvcreate /dev/sdb

# Extend the Volume Group
vgextend rhel_vg /dev/sdb

# Verify the new free space
vgs
Resizing the Logical Volume: lvextend command in RHEL 7 and RHEL 8

With free Physical Extents (PE) now available in your Volume Group, you can assign this space to the specific logical volume that holds your Redis data.

The lvextend command in rhel 7 and the lvextend command in rhel 8 share the exact same syntax, ensuring backward and forward compatibility across major OS releases. LVM is designed for online resizing, meaning you do not need to unmount the volume or boot into rescue mode.

To allocate 100% of the newly available free space to the Redis volume (e.g., /dev/mapper/rhel_vg-redis_lv), execute:

lvextend -l +100%FREE /dev/mapper/rhel_vg-redis_lv

Alternatively, if you only want to add a specific amount of space, such as 50 Gigabytes, you can use:

lvextend -L +50G /dev/mapper/rhel_vg-redis_lv

Step 3: Growing the Filesystem

Extending the LVM logical volume only increases the size of the block device. The filesystem sitting on top of that block device (XFS or EXT4) is completely unaware that the underlying disk has grown. You must explicitly instruct the filesystem to expand into the newly provided boundaries.

In both RHEL 7 and RHEL 8, XFS is the default filesystem for structural partitions. To grow an XFS filesystem online, use the xfs_growfs utility targeting the mount point:

xfs_growfs /var/lib/redis

If you are operating on an older EXT4 filesystem, you would instead use resize2fs targeting the device path:

resize2fs /dev/mapper/rhel_vg-redis_lv

Validate that the space is now available by running df -h /var/lib/redis again. The Use% should have dropped significantly.

Step 4: Restoring the Redis Service

With the storage bottleneck eliminated, you can safely restart the Redis daemon and resolve the connection refused tcp 127.0.0.1 6379 error.

systemctl start redis
systemctl status redis

Ensure the service says active (running). Finally, validate the TCP connection manually using the Redis CLI:

redis-cli -h 127.0.0.1 -p 6379 ping

If the response is PONG, you have successfully triaged a complex, multi-layered infrastructure failure.

Preventive Measures for the Future

To prevent this scenario from recurring:

  1. Monitoring: Implement Prometheus and Node Exporter to alert when filesystem utilization exceeds 85%.
  2. Redis Memory Limits: Configure maxmemory and an appropriate eviction policy (e.g., allkeys-lru) in redis.conf to prevent uncontrolled dataset growth.
  3. Log Rotation: Ensure /var/log/redis/ is managed by logrotate to prevent application logs from quietly consuming your LVM partitions.

Frequently Asked Questions

bash
# 1. Verify the exact connection refused error
redis-cli -h 127.0.0.1 -p 6379 ping
# Output: Could not connect to Redis at 127.0.0.1:6379: Connection refused

# 2. Check disk utilization causing the crash
df -h /var/lib/redis

# 3. Create a new Physical Volume (assuming /dev/sdb is attached)
pvcreate /dev/sdb

# 4. Extend the Volume Group (RHEL 8/7)
vgextend rhel_vg /dev/sdb

# 5. Extend the Logical Volume to use all new free space
lvextend -l +100%FREE /dev/mapper/rhel_vg-redis_lv

# 6. Grow the XFS filesystem online
xfs_growfs /var/lib/redis

# 7. Restart Redis and verify connection
systemctl restart redis
redis-cli ping
# Output: PONG
E

Error Medic Editorial

Error Medic Editorial is managed by a team of Senior Site Reliability Engineers and Linux Sysadmins. We specialize in root-cause analysis, high-availability architecture, and actionable disaster recovery guides for enterprise environments.

Sources

Related Articles in Other

Explore More Linux Sysadmin Guides