Howto install JetBrains TeamCity v6.5.1 on CentOS v5.x
This howto describes getting a TeamCity appliance up and running to the point that a web browser can be used to configure it. Installation of the a TeamCity Build Agent(s) is not covered by this howto.
Note:
- JetBrains recommends the use of a 32bit JDK. I exclusively use 64bit CentOS so using a 64bit JVM is the most straightforward option.
- JetBrains doesn't support OpenJDK. I have no idea why but I have had good success with TeamCity and the openjdk. I tend to use the supported JDK on Windows build agents.
Tasks
- Machine configuration
- Disk Partition
- MySQL
- OpenJDK
- Configure a reverse proxy in front of the TomCat server
- TeamCity
Machine Configuration
Prerequisite machine configuration information
- CentOS v5.x (machine name is olive)
- x86_64
- 1GB RAM, with 2GB swap
- 4 CPU's
- 8GB / (root) partition
- 32GB /srv partition for TeamCity data
- IPv4 and IPv6
- SMTP mailer (postfix)
- IPv4 and IPv6 firewall
TeamCity partition
The TeamCity server application comes as a binary blob. For simplicity this document describes putting it as a blob on it's own filesystem. This will grow with logs and artifacts. It should be sized based on the expected growth given the projects being managed by the server. Format the /srv partition with an ext4 filesystem:
# yum install e4fsprogs # mkfs.ext4 -L /srv /dev/xvdc1
Add the following mount entry to '/etc/fstab' and mount:
LABEL=/srv /srv ext4 defaults 1 2
MySQL
Install MySQL server
yum install mysql-server
Since the database is only required by local processes, ensure it only listens on the loopback interface in '/etc/my.cnf'. MySQL v5.1 didn't seem to want to run with an IPv6 loopback address.
[mysqld] bind-address = localhost
Enable and start services:
# for A in mysqld; do chkconfig $A on ; service $A start ; done
Install MySQL Java connector
This is distributed as part of the EPEL repository. Install the EPEL repository:
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
Install the connector:
# yum install mysql-connector-java
OpenJDK
Install openjdk from the CentOS repository:
# yum install java-1.6.0-openjdk
Firewall configuration
The Teamcity server will require the following network communications:
- incoming http to the Tomcat server on TCP port 8111
- outgoing http to TCP port 9090 on build agents
- outgoing XMPP to TCP port 5222
- outgoing SMTP to TCP port 25
Add the following rules to the IPv4 firewall rules:
# Teamcity server -A tcpIn -p tcp -m tcp --source 10.20.7.0/24 --dport 8111 -m state --state NEW -j ACCEPT # TeamCity Build agent -A tcpOut -p tcp -m tcp --dport 9090 -m state --state NEW -j ACCEPT # XMPP client -A tcpOut -p tcp -m tcp --dport 5222 -m state --state NEW -j ACCEPT
Reverse proxy
A caching reverse proxy is used in front of the TeamCity server. This provides:
- simplified external access through the firewall
- TLS/SSL offload
- TLS SNI extensions
- caching (varnish)
- unified access for IPv4 and IPv6
Nginx configuration
Add the following Nginx configuration file '/etc/nginx/conf.d/teamcity.lucidsolutions.co.nz.conf':
# # TeamCity server # # All http traffic is redirected to https. The https traffic is proxied # to the local varnish cache before going to the teamcity server on # port 8111. # server { listen [::]:80; server_name teamcity.lucidsolutions.co.nz; location / { # redirect to secure page [permanent | redirect] rewrite ^ https://teamcity.lucidsolutions.co.nz$request_uri? permanent; } } server { listen [::]:443; server_name teamcity.lucidsolutions.co.nz; keepalive_timeout 70; ssl on; ssl_certificate certs/teamcity.lucidsolutions.co.nz.startssl.crt; # ssl_certificate certs/teamcity.lucidsolutions.co.nz.self-signed.crt; ssl_certificate_key certs/teamcity.lucidsolutions.co.nz.key; access_log /var/log/nginx/teamcity.lucidsolutions.co.nz.access.log main; location / { # proxy via the local varnish cache proxy_pass http://localhost:6081/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10M; } }
A public key certificate with the necessary certificate chain will need to be produced/procured. Test the configuration and then reload it:
# service nginx reload
Varnish configuration
Add a backend to the configuration:
backend TeamCity { .host = "2001:4428:225:14::2"; .port = "8111"; }
Add a match on the URL and proxy to the backend :
if (...) { ... } else if ( req.http.host ~ "^teamcity.lucidsolutions.co.nz$" ) { set req.backend = TeamCity; }
Reload the varnish configuration with this script.
TeamCity
Read the JetBrains TeamCity installation instructions. The following directory structure is used by the TeamCity installation:
-+ srv +- teamcity Home directory for the 'teamcity' user +- 6.5.1 v6.5.1 installation directory (of the binary blob) | +- bin | +- logs Server log files are written here | +- ... +- .BuildServer This directory is created during the first start +- config The server configuration +- lib +- plugins +- system +- artifacts The artifacts from the build server [this can grow] +- ...
Unpack the archive
Download the tar.gz archive from JetBrains and extract it to the '/srv' directory:
# adduser -c "TeamCity Build Server" -m -d /srv/teamcity -r teamcity # su teamcity -c "tar -xpzf TeamCity-6.5.1.tar.gz -C /srv/teamcity" # mv /srv/teamcity/TeamCity /srv/teamcity/6.5.1
Init script
Add the init script '/etc/init.d/teamcity' from the appendix, and configure the init script:
# chmod +x /etc/init.d/teamcity # chkconfig --add teamcity
Add a configuration file for the init script to point to the team city package.
# cat > /etc/sysconfig/teamcity <<EOF TEAMCITY_SERVER_MEM_OPTS="-Xmx768m -XX:MaxPermSize=150m" TEAMCITY_DIR=/srv/teamcity/6.5.1 EOF
Start the teamcity server. It will start with it's internal database and create the '.BuildServer' directory with configuration files. The web interface should show the starting message.
# service teamcity start
MySQL setup
Use MySQL to store configuration information. Read the instructions for setting up an external database. Create an empty database using the root user (the mysql root user should be secured with a strong pass phrase, as well as the teamcity user):
# mysql mysql> CREATE DATABASE teamcity DEFAULT CHARACTER SET utf8; mysql> GRANT USAGE ON *.* TO 'teamcity'@'localhost' IDENTIFIED BY 'teamcity'; mysql> GRANT ALL ON teamcity.* TO 'teamcity'@'localhost'; mysql> flush privileges;
Use the sample database properties file '~teamcity/.Buildserver/config/database.mysql.properties.dist' to create the following '~/teamcity/.BuildServer/config/database.properties':
connectionUrl=jdbc:mysql://localhost:3306/teamcity connectionProperties.user=teamcity connectionProperties.password=teamcity maxConnections=50 # connectionProperties.useUnicode=true # connectionProperties.characterEncoding=UTF-8 testOnBorrow=true
The MySQL Connector driver must be present in the '.BuildServer/lib/jdbc/' directory. It isn't sufficient for this to be installed on the machine.
# ln -s /usr/share/java/mysql-connector-java.jar ~teamcity/.BuildServer/lib/jdbc/
Start TeamCity
The first startup of the TeamCity server will be lost in the embedded database. For a new installation there should be no information/content to migrate. Start the server with the mysql server backend:
service teamcity start
The empty database is detected by the TeamCity server.
Get the token from the log file '/srv/teamcity/6.5.1/logs/teamcity-server.log'.
Confirm the details:
The server takes a few seconds to start up
Confirm the license agreement
And create the first administrator user
Links
- JetBrains TeamCity
- Installation Instructions
- System requirements
- Setting up an external database
- Jabber 503 error TW-13565
- Howto install Java on CentOS 4 and CentOS 5
Appendices
/etc/init.d/teamcity
#!/bin/bash # # teamcity TeamCity Continuous Integration Server # # chkconfig: 345 80 30 # description: TeamCity is a continuous Integration Server # processname: teamcity # config: /etc/sysconfig/teamcity # # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. if [ -f /etc/sysconfig/teamcity ] ; then . /etc/sysconfig/teamcity else echo "No teamcity configuration" exit 0 fi RETVAL=0 start() { # Start daemons. echo -n $"Starting TeamCity " daemon --user teamcity "( cd $TEAMCITY_DIR && bin/teamcity-server.sh start )" && success || failure $"$prog start" RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/teamcity echo return $RETVAL } stop() { # Stop daemons. echo -n $"Shutting down TeamCity: " ( cd $TEAMCITY_DIR && bin/teamcity-server.sh stop ) && success || failure $"$prog start" RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/teamcity echo return $RETVAL } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit $?
MySQL Server
Packages installed for mysql-server:
============================================================================== Package Arch Version Repository Size ============================================================================== Installing: mysql-server x86_64 5.0.77-4.el5_6.6 updates 9.8 M Installing for dependencies: mysql x86_64 5.0.77-4.el5_6.6 updates 4.8 M perl-DBD-MySQL x86_64 3.0007-2.el5 base 148 k perl-DBI x86_64 1.52-2.el5 base 600 k
MySQL Java Connector
The EPEL MySQL connector has a few dependencies:
==================================================================================== Package Arch Version Repository Size ==================================================================================== Installing: mysql-connector-java x86_64 1:5.1.12-2.el5 epel 2.5 M Installing for dependencies: antlr x86_64 2.7.6-4jpp.2 base 1.1 M atk x86_64 1.12.2-1.fc6 base 224 k axis x86_64 1.2.1-2jpp.6 base 3.6 M bcel x86_64 5.1-8jpp.1 base 1.1 M bitstream-vera-fonts noarch 1.10-7 base 343 k cairo x86_64 1.2.4-5.el5 base 386 k classpathx-jaf x86_64 1.0-9jpp.1 base 111 k classpathx-mail x86_64 1.1.1-4jpp.2 base 1.2 M cups-libs x86_64 1:1.3.7-26.el5_6.1 updates 195 k fontconfig x86_64 2.4.1-7.el5 base 175 k geronimo-specs x86_64 1.0-0.M2.2jpp.12.el5.centos base 259 k geronimo-specs-compat x86_64 1.0-0.M2.2jpp.12.el5.centos base 5.5 k gjdoc x86_64 0.7.7-12.el5 base 886 k gnutls x86_64 1.4.1-3.el5_4.8 base 364 k gtk2 x86_64 2.10.4-21.el5_5.6 base 6.6 M hicolor-icon-theme noarch 0.9-2.1 base 25 k jakarta-commons-discovery x86_64 1:0.3-4jpp.1 base 150 k jakarta-commons-httpclient x86_64 1:3.0-7jpp.1 base 596 k jakarta-commons-logging x86_64 1.0.4-6jpp.1 base 115 k java-1.4.2-gcj-compat x86_64 1.4.2.0-40jpp.115 base 29 k libICE x86_64 1.0.1-2.1 base 54 k libSM x86_64 1.0.1-3.1 base 28 k libXcursor x86_64 1.1.7-1.1 base 32 k libXfixes x86_64 4.0.1-2.1 base 15 k libXft x86_64 2.1.10-1.1 base 44 k libXinerama x86_64 1.0.1-2.1 base 9.8 k libXrandr x86_64 1.1.1-3.3 base 15 k libart_lgpl x86_64 2.3.17-4 base 75 k libgcj x86_64 4.1.2-50.el5 base 18 M libtiff x86_64 3.8.2-7.el5_6.7 updates 314 k log4j x86_64 1.2.13-3jpp.2 base 728 k mx4j x86_64 1:3.0.1-6jpp.4 base 2.7 M pango x86_64 1.14.9-8.el5.centos.2 updates 338 k regexp x86_64 1.4-2jpp.2 base 102 k tomcat5-servlet-2.4-api x86_64 5.5.23-0jpp.17.el5_6 updates 163 k wsdl4j x86_64 1.5.2-4jpp.1 base 429 k xml-commons x86_64 1.3.02-0.b2.7jpp.10 base 19 k xml-commons-apis x86_64 1.3.02-0.b2.7jpp.10 base 388 k xml-commons-resolver x86_64 1.1-1jpp.12 base 170 k zip x86_64 2.31-2.el5 base 136 k
OpenJDK
=================================================================================================== Package Arch Version Repository Size =================================================================================================== Installing: java-1.6.0-openjdk x86_64 1:1.6.0.0-1.22.1.9.8.el5_6 updates 37 M Installing for dependencies: alsa-lib x86_64 1.0.17-1.el5 base 414 k freetype x86_64 2.2.1-28.el5_5.1 base 311 k giflib x86_64 4.1.3-7.3.3.el5 updates 39 k jpackage-utils noarch 1.7.3-1jpp.2.el5 base 61 k libX11 x86_64 1.0.3-11.el5 base 798 k libXau x86_64 1.0.1-3.1 base 18 k libXdmcp x86_64 1.0.1-2.1 base 19 k libXext x86_64 1.0.1-2.1 base 37 k libXi x86_64 1.0.1-4.el5_4 base 26 k libXrender x86_64 0.9.1-3.1 base 28 k libXtst x86_64 1.0.1-3.1 base 16 k libjpeg x86_64 6b-37 base 139 k libpng x86_64 2:1.2.10-7.1.el5_5.3 base 234 k tzdata-java x86_64 2011g-1.el5 updates 180 k xorg-x11-filesystem noarch 7.1-2.fc6 base 5.4 k