..
..
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
..     http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.
..

*****************************
Traffic Server Administration
*****************************
Installing Traffic Server
=========================

#. Build the Traffic Server RPM. The best way to do this is to follow the `Apache Traffic Server documentation <https://docs.trafficserver.apache.org/en/7.1.x/getting-started/index.en.html#installation>`_.

#. Build the astats RPM using the appropriate version number - ours are built `here <https://github.com/apache/trafficcontrol/tree/master/traffic_server>`_

	.. note:: The ``astats`` plugin is bundled as a part of Apache Traffic Server as of version 7.2.

#. Install Traffic Server and astats

	.. code-block:: bash
		:caption: Apache Traffic Server Installation Using :manpage:`yum(8)`

		yum -y install trafficserver-*.rpm astats_over_http*.rpm

#. Add the server using the Traffic Portal UI:

	#. Go to :menuselection:`Configure --> Servers`
	#. Click on the :guilabel:`+` button at the top of the page.
	#. Complete the form. Be sure to fill out all fields marked 'Required'

		* Set 'Interface Name' to the name of the network interface device from which Apache Traffic Server delivers content.
		* Set 'Type' to 'MID' or 'EDGE'.
		* If you wish for the server to immediately be polled by the :ref:`health-proto`, set 'Status' to 'REPORTED'.

	#. Click on the :guilabel:`Create` button to submit the form.
	#. Verify that the server status is now listed as **Reported**

#. Install the :term:`ORT` script and run it in 'BADASS' mode to create the initial configuration

	.. seealso:: :ref:`traffic-ops-ort`

#. Start :abbr:`ATS (Apache Traffic Server)`

	.. code-block:: bash
		:caption: Starting :abbr:`ATS (Apache Traffic Server)` with :manpage:`systemd(1)`

		systemctl start trafficserver

#. (Optional) Configure :abbr:`ATS (Apache Traffic Server)` to start automatically when the system powers on

	.. code-block:: bash
		:caption: Configuring :abbr:`ATS (Apache Traffic Server)` to Start Automatically Using :manpage:`systemd(1)`

		systemctl enable trafficserver

#. Verify that the installation is working

		#. Make sure that the service is running

			.. code-block:: bash
				:caption: Checking that :abbr:`ATS (Apache Traffic Server)` is Running Using :manpage:`systemd(1)`

				systemctl status trafficserver

		#. Assuming a Traffic Monitor is already installed somewhere, check the "Cache States" table in its Web UI to verify that the :abbr:`ATS (Apache Traffic Server)` server appears.

.. _traffic-ops-ort:

Configuring Traffic Server
==========================
All of the :abbr:`ATS (Apache Traffic Server)` application configuration files are generated by Traffic Ops and installed by :term:`ORT`. The :file:`traffic_ops_ort.pl` file should be installed on all :term:`cache servers` (See `Installing the ORT Script`_), usually in ``/opt/ort``. It is used to do the initial install of the configuration files when the :term:`cache server` is being deployed, and to keep the configuration files up-to-date when the :term:`cache server` is already in service.

.. _config-generation:

ORT Config File Generation
--------------------------

In the past, ATS config files were generated by Traffic Ops. Traffic Control is in the process of moving ATS config file generation to a library for generic use, and to an application which uses the library and resides on the cache.

The library, ``lib/go-atscfg``, allows users to write their own applications and servers, if they wish to generate ATS configuration files and deploy them to caches via other means. For example, if you wish to generate config files with an additional service, or continue generating config files on Traffic Ops itself via a plugin or local service.

The app, ``atstccfg``, is installed by the traffic_ops_ort RPM alongside the ORT script. This app makes standard API calls to Traffic Ops, and uses their data to build the ATS config files. The ORT script now requests all config through the app, which generates config files it has, and requests directly from Traffic Ops the files it doesn't recognize.

This provides several benefits. Primarily, reduces the overhead and risk of the monolithic Traffic Ops installation and upgrade process, and allows operators to canary-test config changes one cache at a time, and in the event of an error, only rolling back a few canary caches rather than the entire Traffic Ops instance.

In order to see which config files are generated by a given ``ORT`` or ``atstccfg`` version, run ``/opt/ort/atstccfg --print-generated-files``.

.. _installing-ort:

Installing the ORT Script
-------------------------
#. Build the :term:`ORT` script RPM by following the instructions in :ref:`dev-building` and install it with :manpage:`rpm(8)` or :manpage:`yum(8)`.
#. Install modules required by :term:`ORT` if needed

	.. code-block:: bash
		:caption: Example Installation of Perl Packages Occasionally Missing from Install

		yum install -y perl-JSON perl-Crypt-SSLeay

#. For initial configuration or when major changes (like a :term:`Profile` change) need to be made, run the script in "BADASS". All required RPM packages will be installed, all :abbr:`ATS (Apache Traffic Server)` configuration files will be fetched and installed, and (if needed) the :abbr:`ATS (Apache Traffic Server)` service will be restarted.

	.. Note:: The first run gives a lot of state errors that are expected. The "BADASS" mode fixes these issues. If you run it a second time, this should be cleaner. Also, note that many "ERROR" messages emitted by :term:`ORT` are actually information messages. Do not panic.

#. Create a :manpage:`cron(8)` entry for running :term:`ORT` in "SYNCDS" mode every 15 minutes. This makes Traffic Control check periodically if the server has updates pending, and if so get the updated configuration.

	.. Note:: By default, running :term:`ORT` on an Edge-tier :term:`cache server` will cause it to first wait for its parents (usually Mid-tier :term:`cache server` s) to download their configuration before downloading its own configuration. Because of this, scheduling :term:`ORT` for running every 15 minutes (with 5 minutes default dispersion) means that it might take up to ~35 minutes for queued updates to affect all :term:`cache server` s. To customize this dispersion time, use the command line option ``--dispersion=x`` where ``x`` is the number of seconds for the dispersion period. Servers will select a random number from within this dispersion period to being downloading configuration files from Traffic Ops. Another option, ``--login_dispersion=x`` can be used to create a dispersion period after the job begins during which ORT will wait before logging in and checking Traffic Ops for updates to the server. This defaults to 0. If ``use_reval_pending``, a.k.a. "Rapid Revalidate" is enabled, Edge-tier :term:`cache servers` will **not** wait for their parents to download their configuration before downloading their own.

	.. Note:: In "SYNCDS" mode, the :term:`ORT` script updates only configurations that might be changed as part of normal operations, such as:

		* :term:`Delivery Services`
		* SSL certificates
		* Traffic Monitor IP addresses
		* Logging configuration
		* Revalidation requests (By default - if "Rapid Revalidate" is enabled, this will only be checked by using a separate revalidate command in :term:`ORT`)


#. If "Rapid Revalidate" is enabled in Traffic Ops, create a second :manpage:`cron(8)` job for revalidation checks by running :term:`ORT` in "REVALIDATE" mode. :term:`ORT` will not check revalidation files if "Rapid Revalidate" is enabled. This setting allows for a separate check to be performed every 60 seconds to verify if a revalidation update has been made.
