Tutorial - Setup Teamspeak Server Debian 9.3

December 29, 2017 5.5k views
Deployment Getting Started Applications MariaDB Open Source Debian Ubuntu Ubuntu 16.04

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

  1. Install MariaDB
  2. Install Teamspeak
  3. Configure Teamspeak
  4. 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:

apt-get update && apt-get upgrade

Now thats done, we can install MariaDB:

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:

/usr/bin/mysql_secure_installation
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:

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
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.

useradd -d /opt/teamspeak3-server -m teamspeak3-user

Now go to the temp dir, there we will download the Teamspeak server

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:

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:

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:

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.

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.

ldd /opt/teamspeak3-server/libts3db_mariadb.so

If libmariadb.so.2 ==> not found shows, use the following command:

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.

touch /opt/teamspeak3-server/query_ip_blacklist.txt

Create the whitelist configfile.

cat  << EOT > /opt/teamspeak3-server/query_ip_whitelist.txt
127.0.0.1
EOT

Create the configfile with MySQL-MariaDB database option.

nano /opt/teamspeak3-server/ts3server.ini

With the following inside of it:

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.

nano /opt/teamspeak3-server/ts3db_mariadb.ini

Input:

[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:

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:

nano /etc/init.d/ts3

With:

#! /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:

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:

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:

/opt/teamspeak3-server/logs

The file will look something like this

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:

/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:

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:

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:

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:

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:

passwd teamspeak3-user

After changing the password, you can change user and check the logs:

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

  1. Check the ts3db_mariadb.ini configuration. Is everything correct? Is the password the same as the MariaDB user password?
  2. Try to remove the socket= inside the ts3db_mariadb.ini configuration. This helps sometimes.
  3. Try to use another MariaDB user password. Don't make it to complicated with alot of symbols etc. A simple password sometimes does work.
2 comments
  • Great guide, one thing - with the newest version of ts3 you need to accept a license via global variable or a text file. Easy enough to implement:

    sudo touch /opt/teamspeak3-server/.ts3serverlicenseaccpted

    Hope this helps if your server isn't starting.

  • Great guide. One thing - the newest version of TeamSpeak required you to accept a license via global environment variable or a text file. Easy to implement:

    sudo touch /opt/teamspeak3-server/.ts3serverlicenseaccepted

    Hope this helps if your server won't start.

1 Answer

Works great. A note for those on the latest version of teamspeak you need to accept the license agreement with a global environment variable or with a file. Easy to implement:

[sudo touch /opt/teamspeak3-server/.ts3serverlicenseaccepted]

Hope that helps anyone with a server that won't start.

Have another answer? Share your knowledge.