TeamCity on Centos 7 – Continuous Integration

by Yaroslav Shypunov
8 miesięcy ago

Making sure your most recent fix doesn’t mess up with the rest of the code is one of the most tedious, yet extremely crucial tasks. In lots of the projects we take over after some other developers, there are no mechanisms to make the task less repetitive and more pleasant. The only way it works is going over full system and checking if nothing has crashed after we made our change. The change takes 5 minutes. The testing – 5 hours. It’s a waste of money! At IdeaSpot we optimize those terrible tasks with PhpUnit and Continuous Integration. In this cycle of posts we’ll show you how to configure your own CI stack for continuous functional testing of Symfony Framework applications. In this post we will guide you through the installation of the 2017.1 version of TeamCity on Centos 7.

What we do at IdeaSpot, is automate the testing process with PhpUnit and Continuous Integration. Symfony Framework offers a brilliant tool for creating functional and regression tests, check it out here. But before we can make your development and testing easier and more bug-proof, first we have to survive the fight with TeamCity installation. Although we trully believe all JetBrains applications are really good, the installation process of their server applications such as Upsource and TeamCity are quite difficult, especially for us, PHP developers, who don’t use Tomcat on a daily basis. In this post we’ll guide you through the process of installation of the 2017.1 version of TeamCity on Centos 7.

TeamCity on Centos 7 – Prerequisites

Here is a short list of things that we’ll need in this post:

  • A server with at least 2GB RAM – you can try the servers from DreamHost, they have great VPS hosting with marvellous award-winning support (tested!) starting at $15/mo. Alternative sources we tested and can suggest are DigitalOcean or OVH.
  • Some knowledge of Centos 7 administration.
  • Some knowledge of MySQL / MariaDB administration.
  • Java knowledge usefull, but we’ll manage without it 🙂

Preparation of the Server for TeamCity on Centos 7

Let’s start! First thing you need to do at this stage is get your server. According to TeamCity installation manual, you can install it on any OS: Windows, Mac or Linux. In this post we focus on Centos 7, as the RedHat Linux family is the one we’re most comfortable with. Since TeamCity runs on Java, there’s no chance you can go on shared hosting. In our opinion, the best shot to run TeamCity is a VPS. As mentioned above you can go with a one from DreamHost, DigitalOcean, OVH or Contabo. Contabo has really best prices and we recommend it for non-critical infrastructure. On this guide, we go with a VPS with 2GB RAM assigned, with Centos 7 pre-installed. Before proceeding, make sure you configure the server securely:

  • create users in a single administrative group and add this group to the sudoers file
  • make sure you can sudo with your users
  • disable root login over SSH
  • enable firewall – unlock ports 80, 443 and 8111

Installing Java (OpenJDK) and MySQL connector

Let’s start with the hardest part 🙂 Installing Java on our server. JetBrains in their TeamCity manual suggest using the Oracle version of Java, however, OpenJDK is also supported, and, it’s easier to install for TeamCity on Centos 7. For small installations, it is recommended to use 32-bit Java. It is available via the yum updates repository, so all you need to do is type:

sudo yum install java-1.8.0-openjdk.i686

Yum will get all dependencies for you and install java. You can check if the installation was successful by running command:

java -version

The second step is to install MySQL connector, available from the base yum repository:

sudo yum install mysql-connector-java

We’re done!

Installing MariaDB / MySQL

TeamCity, as most web applications, requires some sort of database to store information. In this guide we’ll use MySQL. Or MariaDB to be precise, as it is the default distribution of MySQL available with Centos since its 7th release. MariaDB is available as a yum repository:

sudo yum install mariadb-server

After MariaDB is downloaded and installed, make sure you enable it, run it and make the necessary security fixes:

sudo systemctl enble mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

Answer all the questions to disable remote root login, delete sample users and databases. When complete – you’re safe.

Now it’s time to create a new user and database for TeamCity on Centos 7. For doing this, we usually choose the SQLyog Community, but to make this guide complete, we’re providing a code snippet:

mysql -p
GRANT USAGE ON *.* TO 'teamcity'@'localhost' IDENTIFIED BY 'yourpassword!';
GRANT ALL ON teamcity.* TO 'teamcity'@'localhost';

The above lines will create a new user ‚teamcity’ with password ‚yourpassword!’, as well as a create and grant access to the new ‚teamcity’ database.

Creating user for TeamCity on Centos 7

We start the actual installation of TeamCity on Centos 7 by creating the user under which TeamCity will run. We’ll name the user „teamcity” and create a home directory for this user at /srv:

sudo useradd -m -d /srv/teamcity -r teamcity

In the command above, the -m flag implies creation of a home directory, the -d flag points to where the user’s home directory should be created, and the -r parameter flags the user as a system user.

Downloading and Installing TeamCity on Centos 7

You can download the most recent version of TeamCity from here. It’s best to upload it directly to the server with wget. The software comes bundled in a tar.gz archive. Login as teamcity:

sudo su - teamcity

and unpack the contents to the home directory (/srv/teamcity). By default, the archive unpacks to TeamCity directory. Rename it to the current version, for easier updating in the future and create a symlink for teamcity:

mv TeamCity /srv/teamcity/2017.1
ln -s /srv/teamcity/2017.1 /srv/teamcity/teamcity

Next, we need to create a service, so we will be able to run TeamCity automatically when the server reboots. Create a file /lib/systemd/system/teamcity.service with the following contents (see source at lucidsolutions):

Description=JetBrains TeamCity

ExecStart=/srv/teamcity/teamcity/bin/ start
ExecStop=/srv/teamcity/teamcity/bin/ stop


Now, we need to pass Java parameters on TeamCity start – create file /etc/sysconfig/teamcity. Here we show an example of configuration for minimum RAM instance:

TEAMCITY_SERVER_MEM_OPTS="-Xmx750m -Djava.awt.headless=true -XX:+UseConcMarkSweepGC "

As mentioned in TeamCity manual, the above is the minimum configuration. A recommended configuration for medium use would be 1024 megabytes.

Finally, we need to enable and start TeamCity service:

sudo systemctl enable teamcity
sudo systemctl start teamcity

Unlocking Firewall

By default, TeamCity on Centos 7 listens on port 8111, which is blocked on the firewall. To allow communication with the application, unlock port 8111 on your firewall. This can be easily done in mc-like GUI with system-config-firewall application, available from yum base repository:

sudo system-config-firewall

Enabling firewall:

Enabling Firewall

Adding port 8111:

Adding port 8111

That’s it! Now you can access your TeamCity on Centos 7 via

Configuring TeamCity on Centos 7

To run TeamCity on Centos 7 run command:

sudo systemctl start teamcity

Now you can navigate with your browser of preference to Now we wait. Wait long. It’s Java.



Tagi: , ,

Dodaj komentarz