Out task is to deploy
YouTrack on CentOS 7.X behind Nginx.
What we need to be done for that task:
- Download and install rpm with latest java from java.com
- Download YouTrack jar file
- Add new user for youtrack process and home dir for files
- Create youtrack.service file for systemd for youtrack service management
- Configure host in nginx
1 and 2 need no additional comments. Only one thing, I placed youtrack jar file in /usr/local/sbin and created symlink to current version:
~ la -l /usr/local/sbin/
total 115508
-rwxr-xr-x 1 root root 118280108 Dec 9 13:42 youtrack-6.5.16953.jar
lrwxrwxrwx 1 root root 22 Dec 17 12:41 youtrack.jar -> youtrack-6.5.16953.jar
From management and security point of view it's better to create new user for new service:
useradd -m -d /opt/youtrack youtrack
Now we need .service file for youtrack in systemd:
~ cat /etc/systemd/system/youtrack.service
; /etc/systemd/system/youtrack.service
[Unit]
Description=JetBrains Youtrack
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=youtrack.target
[Service]
User=youtrack
Group=youtrack
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir -p /var/run/youtrack
ExecStartPre=/usr/bin/chown -R youtrack:youtrack /var/run/youtrack/
PIDFile=/var/run/youtrack/main.pid
ExecStart=/usr/bin/java -Xmx1g -Djava.security.egd=/dev/zrandom -Djava.awt.headless=true -Duser.home=/opt/youtrack -Djetbrains.youtrack.disableBrowser=true -jar /usr/local/sbin/youtrack.jar 127.0.0.1:4080
ExecStop=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
Two things are important here. Since /var/run is in tempfs in CentOS 7.X you need to create pid file dir before service starting up:
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir -p /var/run/youtrack
ExecStartPre=/usr/bin/chown -R youtrack:youtrack /var/run/youtrack/
And second one is youtrack's start command in:
ExecStart=/usr/bin/java -Xmx1g -Djava.security.egd=/dev/zrandom -Djava.awt.headless=true -Duser.home=/opt/youtrack -Djetbrains.youtrack.disableBrowser=true -jar /usr/local/sbin/youtrack.jar 127.0.0.1:4080
Last part is nginx config:
server {
server_name youtrack.domain.com;
listen 80;
charset utf8;
rewrite ^ https://$host$request_uri? permanent;
}
server {
server_name youtrack.domain.com;
listen 443 ssl;
charset utf8;
root /www/youtrack.domain.com/htdocs;
ssl on;
ssl_certificate /etc/nginx/ssl/youtrack.domain.com.crt;
ssl_certificate_key /etc/nginx/ssl/youtrack.domain.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://localhost:4080/;
client_max_body_size 64M;
}
access_log /var/log/nginx/youtrack.domain.comu/access.log main;
error_log /var/log/nginx/youtrack.domain.com/error.log warn;
}