TeamSpeak 3 Server with MySQL Database - audio/teamspeak3-server

This article will detail the installation and configuration of TeamSpeak 3 Server from ports - audio/teamspeak3-server

TeamSpeak 3 Server will connect to a MySQL Server for its database and works with MySQL 5.5 or higher.

 

Install and Configure Teamspeak 3 Server

audio/teamspeak3-server depends on security/ca_root_nss

cd /usr/ports/audio/teamspeak3-server

make config

The configuration dialog has an option to enable MySQL database support.
It is not required to enable this as It will only add MySQL server as a required installation and runtime dependency of teamspeak3-server on the local system. The database plugins the teamspeak3-server needs to connect to a MySQL database server are always installed in /usr/local/lib/teamspeak/server/ irrespective of this setting. Enable the option only if you intend to install MySQL server, or if it is already installed on the local system. If enabled, ensure your desired MySQL server version is specified in /etc/make.conf prior to installing teamspeak3-server e.g. DEFAULT_VERSIONS+= php=7.2 python=3.7 python3=3.7 perl5=5.28 ssl=openssl111 mysql=8.0

<Accept> terms of license.

make install clean

 

Create a new server ini file /usr/local/etc/teamspeak/ts3server.ini with the following configuration:

dbplugin=ts3db_mariadb
dbpluginparameter=mysql.ini
dbsqlcreatepath=create_mariadb/
logappend=1

NOTE: As per Teamspeak documentation, the ts3db_mariadb plugin and the create_mariadb/ path are used to connect to both MySQL and MariaDB database servers. Also note that the actual plugin filename(s) begin with lib but this is deliberately omitted when specifying dbplugin=

Many other command line configuration options exist, such as changing the voice, query, or file transfer ports. Refer to /usr/local/share/doc/teamspeak3-server/server_quickstart.txt for the complete list including default values for each. Only command line options that need to be altered from the defaults need be specified in ts3server.ini.

 

Create a new database for the TeamSpeak 3 server on your MySQL server.
Create a user account configured to use Native MySQL authentication and grant it full rights to the Teamspeak 3 server database only.

 

Create the configuration file for the MySQL server connection /var/db/teamspeak/mysql.ini  the filename is specified with dbpluginparameter= in ts3server.ini. Specify the MySQL username, password, and database name that was used when creating the TeamSpeak database. Use single quotes around the password to ensure that special characters are used correctly.

[config]
host=localhost
port=3306
username=teamspeak
password='password'
database=ts3server

If the Teamspeak server daemon will be running on the same system as the MySQL server then you can optionally take advantage of MySQL sockets by adding the following line:

socket=/tmp/mysql.sock

NOTE: When using sockets host= must be localhost for sockets to work and socket= supersedes port= which can be removed from the configuration.

 

To enable the teamspeak server add the following to /etc/rc.conf

teamspeak_enable="YES"

Other optional rc.conf configuration options are available with default values shown:

teamspeak_pidfile="/var/db/teamspeak/teamspeak_server.pid"
teamspeak_db_dir="/var/db/teamspeak"
teamspeak_log_dir="/var/log/teamspeak"

Start the Teamspeak Server service:

service teamspeak start

 

Gain Administrative Control

A synopsis of server_quickstart.txt - Section 8. Gaining Administrator Access

View the contents of the /var/log/teamspeak/ts3server_1.log file to obtain the ServerAdmin token used to gain administrative control of the Teamspeak server:

ServerAdmin token created, please use the line below
token=ppEa0Wp6hopKBzKhH5RiUtb5Ggve5aI8J7ifu+/P

To gain global administration permissions for ServerQuery access, the first time the server instance
is started a ServerQuery password is printed to the console output:

Server Query Admin Acccount created
loginname= “serveradmin”, password= “BAIPwM8X”

If for any reason this was not displayed then the password can be set by temporarily adding the following command line parameter to ts3server.ini:

serveradmin_password='password'

 

Stopping and Restarting Teamspeak 3 Server

The examples in this section are entirely optional. The usual service teamspeak start|stop|restart commands work as intended.

When executing service teamspeak start the rc.d script /usr/local/etc/rc.d/teamspeak executes FreeBSD's builtin daemon(8) utility to start and daemonize the ts3server process. The modified teamspeak rc.d startup script (below) adds -r to the daemon startup command line. The -r option instructs daemon(8) to supervise and automatically restart its child process after a one second delay if it is terminated. However if we deliberately stop the TeamSpeak server with service teamspeak stop, the daemon process will dutifully launch ts3server again. The modified rc.d script adds a custom stop method that sends SIGTERM to the parent daemon process. daemon(8) then by design forwards SIGTERM to its child ts3server process terminating it, next it removes both pid files, and lastly the daemon process terminates.

The following rc.d script modifications are not required and intended only to accommodate the daemon(8) command-line option -r to supervise and restart the ts3server process as just described.

Edit /usr/local/etc/rc.d/teamspeak inserting items highlighted in bold

#!/bin/sh

# $FreeBSD: head/audio/teamspeak3-server/files/teamspeak.in 492462 2019-02-08 20:58:56Z ultima $
#
# PROVIDE: teamspeak
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# teamspeak_enable (bool):   Set to NO by default.
#               Set it to YES to enable teamspeak server.
#

. /etc/rc.subr

name="teamspeak"
rcvar=teamspeak_enable

load_rc_config $name

: ${teamspeak_enable:="NO"}
: ${teamspeak_pidfile:="/var/db/teamspeak/teamspeak_server.pid"}
: ${teamspeak_db_dir:="/var/db/teamspeak"}
: ${teamspeak_log_dir:="/var/log/teamspeak"}

stop_cmd="${name}_stop"
teamspeak_stop()
{
   kill `cat $daemon_pidfile`
}

daemon_pidfile=/var/db/teamspeak/daemon.pid
procname=/usr/local/libexec/ts3server
command=/usr/sbin/daemon
command_args="-fp "$teamspeak_pidfile" -r -P $daemon_pidfile -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath="$teamspeak_log_dir" license_accepted=1"
teamspeak_chdir="$teamspeak_db_dir"
required_dirs="$teamspeak_db_dir $teamspeak_log_dir"

LD_LIBRARY_PATH=/usr/local/lib/teamspeak/server:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
export LANG=en_US.UTF-8

run_rc_command "$1"

NOTE: The teamspeak rc.d file is replaced every time the Teamspeak server port is updated. A backup copy of the modified version of the file will need to be copied back into place after every update.

 

Logging and Log Rotation

By default the server creates new log files with each service (re)start. The created log file names include the exact date and time the service was started. The logappend=1 option specified in ts3server.ini suppresses this file name construct behavior and instead creates two log files named simply ts3server_0.log and ts3server_1.log and appends to these two log files perpetually. This makes it more suitable for newsyslog to rotate and save archive copies of the logs.

The following example configuration added to /etc/newsyslog.conf will rotate the logs on the first day of every month at midnight keeping 4 archive files.

/var/log/teamspeak/*.log teamspeak:wheel 600 4 * $M1D0 ZG /var/db/teamspeak/teamspeak_server.pid

The G flag allows us to specify a wildcard *.log to rotate and create archives for both of TeamSpeak server's log files.

NOTE: It is necessary to restart the ts3server process to continue logging properly after a log rotation. The process identified by teamspeak_server.pid will be sent a SIGHUP when newsyslog rotates the log files. The ts3server process will simply shutdown in response to a HUP signal which is not optimal. However if daemon(8) command line parameter -r is used as detailed in the previous section, then ts3server will be automatically restarted and logging will continue normally.

 

Adding a SRV Record to DNS

Adding a _ts3._udp. SRV resource record to the authoritative DNS zone of the TeamSpeak server, allows administrators to control the destination target IP address and port of clients connecting to a given FQDN. Clients configure their bookmarks with the FQDN only and no port. Administrative changes to destination IP address or port can be made without the need for clients to update their bookmarks.

The format is  _ts3._udp.name TTL IN SRV priority weight port target

_ts3._udp.example.org.    IN    SRV    0 5 9987 example.org.

NOTE: The target in the SRV record must point to a hostname that has an A and/or AAAA resource record. Pointing to a hostname that has a CNAME resource record is not a valid configuration.

 

Pertinent File/Folder Locations

Server configuration - /usr/local/etc/teamspeak/ts3server.ini

Database configuration - /var/db/teamspeak/mysql.ini

Logs - /var/log/teamspeak/

TeamSpeak icons, client avatars, and file transfer folders/files - /var/db/teamspeak/files/

Documentation /usr/local/share/doc/teamspeak3-server/ 

 

Server working directory - /var/db/teamspeak/

Database plugins (dbplugin=ts3db_mariadb) - /usr/local/lib/teamspeak/server/

SQL script files directory (dbsqlpath=) - /usr/local/share/teamspeak/server/sql/

TeamSpeak startup script - /usr/local/etc/rc.d/teamspeak