How to Configure and Optimize Don’t Starve Dedicated Server?
Running a Don’t Starve dedicated server in Hong Kong offers unique advantages for gamers across Asia. This comprehensive guide walks through the technical aspects of server setup, optimization, and maintenance. Whether you’re a seasoned system administrator or a dedicated gamer, you’ll find detailed instructions for creating a robust gaming environment.
System Requirements and Preparation
Before diving into configuration, let’s examine the optimal server specifications for Don’t Starve hosting in Hong Kong:
- CPU: Intel Xeon or AMD EPYC
- RAM: Minimum 4GB, recommended 8GB
- Storage: 20GB SSD recommended
- OS: Ubuntu 20.04 LTS or CentOS 8
- Network: 100Mbps minimum, with DDoS protection
Initial Server Setup Process
Let’s begin with the installation process. We’ll use Ubuntu as our base system. First, establish SSH access to your Hong Kong server and execute these commands:
# Update system packages
sudo apt-get update && sudo apt-get upgrade -y
# Install required dependencies
sudo apt-get install lib32gcc1 lib32stdc++6 libcurl4-gnutls-dev:i386 screen -y
# Create dedicated user for DS
sudo useradd -m -r -s /bin/bash dsserver
sudo su - dsserver
# Install SteamCMD
mkdir ~/steamcmd
cd ~/steamcmd
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz
Server Installation and Configuration
After installing SteamCMD, we’ll proceed with Don’t Starve server installation. The following script demonstrates the installation process:
# Launch SteamCMD and install DS server
./steamcmd.sh +login anonymous +force_install_dir ~/ds_server +app_update 343050 validate +quit
# Create server startup script
cat > ~/start_ds.sh << 'EOL'
#!/bin/bash
cd ~/ds_server/bin
screen -S "ds_server" ./dontstarve_dedicated_server_nullrenderer -console
EOL
chmod +x ~/start_ds.sh
Now, let's configure the server settings. Navigate to the configuration directory:
cd ~/.klei/DoNotStarve/settings.ini
Here's an optimized server configuration template:
[network]
server_port = 10999
max_players = 6
pvp = false
pause_when_empty = true
[steam]
authentication_port = 8768
master_server_port = 27016
[misc]
console_enabled = true
autocompiler_enabled = true
Performance Optimization Techniques
For optimal performance on Hong Kong servers, implement these critical optimizations:
- Configure TCP BBR for improved network throughput
- Implement proper disk I/O scheduling
- Optimize system memory allocation
Add these kernel parameters to /etc/sysctl.conf:
# Network optimization
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_congestion_control = bbr
# I/O optimization
vm.swappiness = 10
vm.vfs_cache_pressure = 50
Mod Management System
Implementing a robust mod management system is crucial for server stability. Here's how to set up and manage mods effectively:
# Create mods directory
mkdir -p ~/.klei/DoNotStarve/mods
# Create mod configuration file
cat > ~/.klei/DoNotStarve/mods/dedicated_server_mods_setup.lua << 'EOL'
-- Server-side Mods Configuration
ServerModSetup("347079953") -- Example: Health Info
ServerModSetup("378160973") -- Example: Global Positions
ServerModSetup("462434129") -- Example: Server Restart Announcer
-- Mod Configuration
ServerModConfiguration = {
["347079953"] = {
configuration_options = {
display_mode = 0,
show_max_health = true
}
}
}
EOL
Security Hardening
Security is paramount for Hong Kong-based game servers. Implement these essential security measures:
# Configure UFW firewall
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 10999/udp
sudo ufw allow 8768/udp
sudo ufw enable
# Set up fail2ban
sudo apt-get install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# Add custom jail rules
[ds-server]
enabled = true
filter = ds-server
action = iptables-multiport[name=DS, port="10999,8768"]
logpath = ~/.klei/DoNotStarve/server_log.txt
maxretry = 3
bantime = 3600
Automated Maintenance Scripts
Create automated maintenance scripts to ensure server stability:
#!/bin/bash
# backup_ds.sh - Daily backup script
BACKUP_DIR="/home/dsserver/backups"
DATE=$(date +%Y%m%d)
# Create backup directory
mkdir -p $BACKUP_DIR
# Backup save files
tar -czf $BACKUP_DIR/ds_save_$DATE.tar.gz ~/.klei/DoNotStarve/save/
# Keep only last 7 days of backups
find $BACKUP_DIR -name "ds_save_*.tar.gz" -mtime +7 -delete
Performance Monitoring and Troubleshooting
Implement these monitoring tools to maintain optimal server performance on Hong Kong infrastructure:
# Install monitoring tools
sudo apt-get install htop iotop netdata -y
# Create performance monitoring script
cat > ~/monitor_ds.sh << 'EOL'
#!/bin/bash
LOG_FILE="/home/dsserver/server_stats.log"
while true; do
echo "$(date) - Server Statistics" >> $LOG_FILE
echo "CPU Usage: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}')%" >> $LOG_FILE
echo "Memory Usage: $(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2}')" >> $LOG_FILE
echo "Disk Usage: $(df -h | awk '$NF=="/"{printf "%s", $5}')" >> $LOG_FILE
sleep 300
done
EOL
chmod +x ~/monitor_ds.sh
Common Issues and Solutions
Here are solutions for frequently encountered issues when running Don't Starve servers in Hong Kong:
# Server crash recovery script
cat > ~/crash_recovery.sh << 'EOL'
#!/bin/bash
if ! screen -list | grep -q "ds_server"; then
echo "Server crashed. Restarting..."
~/start_ds.sh
echo "$(date) - Server restarted after crash" >> ~/crash.log
fi
EOL
# Add to crontab
(crontab -l 2>/dev/null; echo "*/5 * * * * /home/dsserver/crash_recovery.sh") | crontab -
Advanced Configuration Tips
For experienced administrators, these advanced configurations can further enhance server performance:
- Implement custom server-side event scheduling
- Configure automatic world regeneration
- Set up cross-region connection optimization
Example of an advanced event scheduler:
-- Advanced Event Scheduler
local function ScheduleServerEvents()
local events = {
{day = 1, action = "c_regenerateworld()"},
{day = 15, action = "c_save()"},
{day = 30, action = "c_reset()"}
}
for _, event in ipairs(events) do
if TheWorld.state.cycles == event.day then
ExecuteConsoleCommand(event.action)
end
end
end
AddPrefabPostInit("world", function(inst)
inst:DoPeriodicTask(TUNING.TOTAL_DAY_TIME, ScheduleServerEvents)
end)
Recommended Server Configurations
Based on extensive testing with Hong Kong server infrastructure, here are the optimal configurations for different player bases:
Player Count | CPU Cores | RAM | Network |
---|---|---|---|
1-4 | 2 cores | 4GB | 100Mbps |
5-8 | 4 cores | 8GB | 200Mbps |
9+ | 6 cores | 16GB | 500Mbps |
Final Optimization Steps
Implement these final optimizations to ensure peak performance:
# Performance tuning script
cat > ~/performance_tune.sh << 'EOL'
#!/bin/bash
# Set CPU governor to performance
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Optimize network settings
sysctl -w net.ipv4.tcp_fastopen=3
sysctl -w net.ipv4.tcp_slow_start_after_idle=0
# Optimize file system
echo "deadline" | sudo tee /sys/block/sda/queue/scheduler
EOL
chmod +x ~/performance_tune.sh
Conclusion and Best Practices
Operating a Don't Starve server in Hong Kong requires careful attention to configuration details and ongoing maintenance. By following this guide's optimization techniques and security measures, you can ensure a stable and responsive gaming experience for players across Asia. Remember to regularly monitor server performance and update configurations as needed.
For optimal results, consider implementing automated monitoring and maintenance scripts, regularly backing up your server data, and staying informed about the latest Don't Starve updates and security patches. Hong Kong's strategic location makes it an ideal choice for DS server hosting, providing excellent connectivity to players throughout the Asia-Pacific region.