When running Asterisk PBX on Ubuntu, you might encounter situations where the default file descriptor limit (1024) becomes restrictive. This is particularly common in high-call-volume environments. The challenge arises because Asterisk typically runs as a non-login system user, making traditional ulimit
commands ineffective.
Ubuntu has two levels of file descriptor limits:
1. System-wide limit (check with: cat /proc/sys/fs/file-max)
2. Per-process limit (check with: cat /proc/$(pidof asterisk)/limits | grep "Max open files")
Here's the proper sequence to implement permanent changes:
# 1. Edit systemd service file (for Ubuntu 16.04+)
sudo systemctl edit --full asterisk
# Add these lines under [Service]:
LimitNOFILE=2048
LimitNPROC=4096
# 2. Update pam limits (works for both systemd and sysvinit)
sudo nano /etc/security/limits.conf
Add these entries:
asterisk soft nofile 2048
asterisk hard nofile 2048
@asterisk soft nofile 2048
@asterisk hard nofile 2048
For older systems using sysvinit or to ensure complete coverage:
# Edit sysctl configuration
sudo nano /etc/sysctl.conf
# Add these lines:
fs.file-max = 65536
fs.nr_open = 65536
# Apply changes immediately
sudo sysctl -p
After making changes, verify with:
# Check current process limits
cat /proc/$(pidof asterisk)/limits | grep "Max open files"
# Check system-wide limit
cat /proc/sys/fs/file-max
# Check user limits (as root)
su - asterisk -s /bin/bash -c "ulimit -n"
If changes don't take effect:
1. Ensure you've restarted Asterisk AND the server (some changes require full reboot)
2. Check for apparmor/selinux restrictions
3. Verify asterisk is running under the correct user
4. Check for conflicting configurations in /etc/security/limits.d/
For high-performance installations, consider these additional tweaks:
# Increase epoll limits
echo 1048576 > /proc/sys/fs/epoll/max_user_watches
echo "fs.epoll.max_user_watches=1048576" >> /etc/sysctl.conf
# Optimize TCP settings
echo "net.ipv4.tcp_max_syn_backlog=4096" >> /etc/sysctl.conf
echo "net.core.somaxconn=4096" >> /etc/sysctl.conf
Here's a comprehensive guide to properly configure file descriptor limits for the Asterisk PBX daemon on Ubuntu systems. The standard approaches often fail because Asterisk runs as a system service with specific initialization requirements.
The default 1024 file descriptor limit becomes problematic for Asterisk when handling high call volumes or multiple concurrent connections. Even when modifying /etc/security/limits.conf
, the changes don't persist because:
- Systemd services ignore traditional limits.conf settings
- Asterisk typically runs as a non-login service account
- Ubuntu's PAM configuration may not apply to daemon processes
For modern Ubuntu systems using systemd, we need a multi-layer approach:
1. Systemd Service Configuration
Create or modify the Asterisk service override file:
sudo mkdir -p /etc/systemd/system/asterisk.service.d
sudo nano /etc/systemd/system/asterisk.service.d/limits.conf
Add these contents:
[Service]
LimitNOFILE=2048
LimitNPROC=4096
2. Asterisk Built-in Limits
Configure Asterisk's internal file handling in /etc/asterisk/asterisk.conf
:
[options]
maxfiles = 2048
3. Sysctl Configuration (Optional)
For systems expecting very high loads, adjust kernel-level limits:
sudo nano /etc/sysctl.conf
Add these lines:
fs.file-max = 65536
fs.nr_open = 65536
After applying all changes, execute:
sudo systemctl daemon-reload
sudo systemctl restart asterisk
Then verify with:
pid=$(pgrep asterisk)
cat /proc/$pid/limits | grep "Max open files"
If you still see 1024:
- Check for conflicting settings in
/etc/pam.d/common-session
- Verify Asterisk isn't being started via init.d (use systemd instead)
- Ensure no SELinux/AppArmor restrictions exist (uncommon on Ubuntu)
For a high-volume server handling 500 concurrent calls:
# /etc/systemd/system/asterisk.service.d/limits.conf
[Service]
LimitNOFILE=8192
LimitNPROC=16384
# /etc/asterisk/asterisk.conf
[options]
maxfiles = 8192
maxload = 1.4
# /etc/sysctl.conf
fs.file-max = 131072