
Setup a teamspeak server on Debian 9
Two years ago, someone asked me to write a tutorial about how to setup a teamspeak server on Ubuntu 15.04. That turorial had been seen so many times, with alot of comments, I thought a new update could be usefull. If you want to see the other tutorial, check https://www.digitalocean.com/community/questions/setup-teamspeak-server-ubuntu-15-04
If you got any problems after using this tutorial, please make a comment. I made this tutorial in a way I think is the best, if you got any improvements or want to use something else please tell me.
Prerequisites
- A droplet with Debian 9.3 ( $5 is enough for a ts server) –> Use my referral link for a free $10: https://m.do.co/c/fd86b04158d8
- An SSH client / SFTP client ( I am using PuTTY and WinSCP )
What we will do
-
- Install MariaDB
- Install Teamspeak
- Configure Teamspeak
- Create an autostart script
Connect to the droplet
First we need to connect to the droplet we created. Once the droplet is created, you will get an email with all the credentials in it. Open PuTTY and use these credentials to login; the first time you login you need to change the password. To make this server secure, I always like to use a RSA key. So I always install my droplet with an SSH key.
Install MariaDB
MariaDB is a replacement for MySQL with a better performance. The database will hold all users/settings etc. of the Teamspeak server instead of SQLlite. If you already have a SQL database running, skip the first few steps and continue on making a new user for the teamspeak server.
Before we can install MariaDB, we need to update & upgrade the packages. So run the following:
1 |
apt-get update && apt-get upgrade |
Now thats done, we can install MariaDB:
1 |
apt-get install mariadb-client mariadb-server |
Hit Y when they want you to confirm
Once the install process is finished, you have to setup your MariaDB install with new root password (default is blank). Issue this command:
1 |
/usr/bin/mysql_secure_installation |
1 2 3 4 5 6 7 |
Enter current password for root (enter for none): Enter Set root password? [Y/n] y New password: PassWordGoesHere Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y |
Now the MariaDB service should be running with a new root password.
Lets configure the database now. We will create a new user and database for the Teamspeak server. Create the database with your own password:
1 2 3 4 |
mysql -u root -p Enter the root user password create database teamspeak3; GRANT ALL PRIVILEGES ON teamspeak3.* TO 'teamspeak3'@'localhost' IDENTIFIED BY 'TeamspeakUserPasswordGoesHere'; |
Change TeamspeakUserPasswordGoesHere with a secure password
1 2 |
flush privileges; quit |
Install Teamspeak
First we will create a new user with its own directory in /opt/. Then we will download the latest teamspeak server and unpack it.
1 |
useradd -d /opt/teamspeak3-server -m teamspeak3-user |
Now go to the temp dir, there we will download the Teamspeak server
1 |
cd /tmp |
To find the latest download link, go to https://www.teamspeak.com/en/downloads.html#server and click on the Copy button next to the Server 64-bit. Then we can download the Teamspeak server:
1 |
wget <your copied url> |
In our case:
1 |
wget http://dl.4players.de/ts/releases/3.0.13.8/teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 |
Then extract the files of the tarbal:
1 |
tar -vxjf teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 |
You can easily find the proper name of the tarbal, by typing the first 2-3 characters of the name and then hitting TAB. Debian will search the rest for you.
Now lets move the files to the opt directory, change the permissions of the teamspeak server files and remove all the downloaded files:
1 2 3 |
mv teamspeak3-server_linux_amd64/* /opt/teamspeak3-server/ chown teamspeak3-user:teamspeak3-user /opt/teamspeak3-server -R rm -rf teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 teamspeak3-server_linux_amd64/ |
Then symlink the libmariadb.so.2 library from /redist folder to TeamSpeak3 server directory.
1 |
ln -s /opt/teamspeak3-server/redist/libmariadb.so.2 /opt/teamspeak3-server/libmariadb.so.2 |
Run ldd to prints the shared libraries required by TeamSpeak3 server.
1 |
ldd /opt/teamspeak3-server/libts3db_mariadb.so |
If libmariadb.so.2 ==> not found shows, use the following command:
1 |
apt-get install libmariadb2 |
Configure Teamspeak
We are going to configure TeamSpeak3 server with the MySQL-MariaDB database,
We have to manually create configfiles:
- queryipblacklist.txt
- queryipwhitelist.txt
- ts3server.ini
- ts3db_mariadb.ini
Create the blacklist configfile.
1 |
touch /opt/teamspeak3-server/query_ip_blacklist.txt |
Create the whitelist configfile.
1 2 3 |
cat << EOT > /opt/teamspeak3-server/query_ip_whitelist.txt 127.0.0.1 EOT |
Create the configfile with MySQL-MariaDB database option.
1 |
nano /opt/teamspeak3-server/ts3server.ini |
With the following inside of it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
machine_id= default_voice_port=9987 voice_ip=0.0.0.0 licensepath= filetransfer_port=30033 filetransfer_ip=0.0.0.0 query_port=10011 query_ip=0.0.0.0 query_ip_whitelist=query_ip_whitelist.txt query_ip_blacklist=query_ip_blacklist.txt dbsqlpath=sql/ dbplugin=ts3db_mariadb dbsqlcreatepath=create_mariadb/ dbpluginparameter=ts3db_mariadb.ini dbconnections=10 logpath=logs logquerycommands=0 dbclientkeepdays=30 logappend=0 query_skipbruteforcecheck=0 |
To save: Hit CTRL + X –> Y
Create the configfile for the database for the TeamSpeak3 server.
Change PASSWORD the same password you have created configuring the MySQL database.
1 |
nano /opt/teamspeak3-server/ts3db_mariadb.ini |
Input:
1 2 3 4 5 6 7 |
[config] host=127.0.0.1 port=3306 username=teamspeak3 password=PASSWORD database=teamspeak3 socket= |
Now you need to change permissions of the new config files:
1 |
sudo chown teamspeak3-user:teamspeak3-user /opt/teamspeak3-server -R |
Now the configuration is done.
Create ts3 init script of TeamSpeak3 server (autostart)
With the autoscript you don’t have to worry about exiting the teamspeak server when you leave the SSH connection. The script will take care of running the server.
Create the script:
1 |
nano /etc/init.d/ts3 |
With:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#! /bin/sh ### BEGIN INIT INFO # Provides: ts3 # Required-Start: $network mysql # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: TeamSpeak3 Server Daemon # Description: Starts/Stops/Restarts the TeamSpeak Server Daemon ### END INIT INFO set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="TeamSpeak3 Server" NAME=teamspeak3-server USER=teamspeak3-user DIR=/opt/teamspeak3-server OPTIONS=inifile=ts3server.ini DAEMON=$DIR/ts3server_startscript.sh #PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 sleep 2 sudo -u $USER $DAEMON $1 $OPTIONS |
Now change permissions for the scripts:
1 2 3 4 |
chmod a+x /etc/init.d/ts3 chmod a+x /opt/teamspeak3-server/ts3server_startscript.sh chmod a+x /opt/teamspeak3-server/ts3server_minimal_runscript.sh update-rc.d ts3 defaults |
Now everything should be done, and ready to go. Lets start the Teamspeak3 server for the first time:
1 |
sudo /etc/init.d/ts3 start |
For the token key to become a superadmin on the server, you can check the logs. Make sure you copy this and use it the first time you enter. The logs you can find in this directory:
1 |
/opt/teamspeak3-server/logs |
The file will look something like this
1 |
ts3server_2017-12-29__12_01_21.906198_1.log |
You can now connect to the teamspeak server, using the IP of the Droplet.
Hope this tutorial will help you! If you have got any questions, don’t hesitate to ask me in the comments.
Troubleshooting
Upgrading
When a new version comes out, you can easily upgrade the Teamspeak server. The steps that are needed:
- Stop the Teamspeak server
- Download the latest version
- Change the permissions so the teamspeak user has access
- Run the Teamspeak server
1 Shutdown the server:
1 |
/etc/init.d/ts3 stop |
2 Download the latest version (which you can find on their website), extract it, move it and change the permissions:
1 2 |
cd /tmp wget http://dl.4players.de/ts/releases/3.0.13.8/teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 |
Then exctract the files of the tarbal:
1 |
tar -vxjf teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 |
You can easily find the proper name of the tarbal, by typing the first 2-3 characters of the name and then hitting TAB. Debian will search the rest for you.
Now lets move the files to the opt directory, change the permissions of the teamspeak server files and remove all the downloaded files:
1 2 3 |
mv teamspeak3-server_linux_amd64/* /opt/teamspeak3-server/ chown teamspeak3-user:teamspeak3-user /opt/teamspeak3-server -R rm -rf teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2 teamspeak3-server_linux_amd64/ |
3 Start the server again:
/etc/init.d/ts3 start
Using an external database
I do not recommend using an external database. It only slows down writing the data and settings and it is not really needed. Instead, use the SQLite database. This is also working the same as the MariaDB database, except you can’t get inside the records. For that, don’t use the ts3db_mariadb.ini
and use the following ts3server.ini
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
machine_id= default_voice_port=9987 voice_ip=0.0.0.0 licensepath= filetransfer_port=30033 filetransfer_ip=0.0.0.0 query_port=10011 query_ip=0.0.0.0 query_ip_whitelist=query_ip_whitelist.txt query_ip_blacklist=query_ip_blacklist.txt dbsqlpath=sql/ dbplugin=ts3db_sqlite3 dbsqlcreatepath=create_sqlite/ dbpluginparameter= dbconnections=10 logpath=logs logquerycommands=0 dbclientkeepdays=30 logappend=0 query_skipbruteforcecheck=0 |
If you really want to use an external MariaDB database tho, make sure the following is correct:
- the mysql server is running on that host, and binded to the external address (so not running locally)
- it is actually listening to the given port
- the mysql user is allowed to log into mysql from the ip address of the Teamspeak server
- the firewall on the mysql host allows connections to the mysql port
You can’t get into the logs directory or edit the log file
This can happen when you aren’t logged in as root, because we changed the permissions of the teamspeak-server directory so only the teamspeak user has access. Things you can do to still open the files:
- Change to the root user
- Change to the teamspeak user
To change to root, you need to know the password of the root account OR have sudo permissions. First try with sudo permissions:
sudo su
If you don’t have sudo permissions, you need to give the teampseak3-user a password and change to that user. To change the password, run the following:
1 |
passwd teamspeak3-user |
After changing the password, you can change user and check the logs:
1 2 |
su teamspeak3-user cd /opt/teamspeak3-server/logs |
Server() unable to initialize database
If you get the above error, there might be something wrong with the MariaDB / Teamspeak configuration. To debug this issue, try one of the following
- Check the
ts3db_mariadb.ini
configuration. Is everything correct? Is the password the same as the MariaDB user password? - Try to remove the
socket=
inside thets3db_mariadb.ini
configuration. This helps sometimes. - Try to use another MariaDB user password. Don’t make it to complicated with alot of symbols etc. A simple password sometimes does work.
Share This Post
Recent Posts
- How to secure Debian Server 9.X – Scan for malicious items (Rkhunter)
- How to secure Debian Server 9.X – Setup a firewall
- How to secure Debian Server 9.X – Disable root login & change SSH port
- How to secure Debian Server 9.X – Setup SSH keys
- How to make a WordPress website running on a Linux webserver – Part 1
Leave a Reply