Deploying a Spring boot application to ubuntu
- create a ubuntu vm
- Install jdk 11
sudo apt update
sudo apt install openjdk-11-jdk -y
wget https://storage.googleapis.com/qtreferenceapplications/spring-petclinic-2.4.2.jar
sudo useradd bootuser
sudo mkdir /usr/share/petclinic
sudo cp spring-petclinic-2.4.2.jar /usr/share/petclinic/spring-petclinic-2.4.2.jar
sudo chown bootuser:bootuser /usr/share/petclinic/spring-petclinic-2.4.2.jar
sudo chmod 500 /usr/share/petclinic/spring-petclinic-2.4.2.jar
- Now create a file in /etc/systemd/system/springpetclinic.service with the following content
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
User=bootuser
ExecStart=java -jar /usr/share/springpetclinic/spring-petclinic-2.4.2.jar
SuccessExitStatus=143
Restart=always
StandardOutput=append:/var/log/petclinic.log
StandardError=append:/var/log/petclinicerrors.log
[Install]
WantedBy=multi-user.target
- Now reload the system daemon and start the spring petclinic
sudo systemctl daemon-reload
sudo systemctl start springpetclinic.service
sudo systemctl status springpetclinic.service
- The logs of this application are generated in
- /var/log/petclinic.log
- /var/log/petclinicerrors.log
- Individual log
#log
2021-04-29 02:34:01.020 DEBUG 353 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet : Completed 200 OK
# grok patterns
%{SYSLOGTIMESTAMP : datetime}%{SPACE}%{WORD:application}%{SPACE}(?<thread>java\[\d+\]:\s)%{TIMESTAMP_ISO8601}%{SPACE}%{LOGLEVEL:level}%{SPACE}(?<thread_info>\d+\s+---\s\[[\b\w*\d*-]*\]\s)%{JAVACLASS:class}%{SPACE}%{GREEDYDATA:logmessage}
- Now install and configure filebeat to send the logs from the above two files to logstash running on 5045 port
- edit the filebeat.yml file at /etc/filebeat/filebeat.yml
- Now login into vm with logstash and create a new file /etc/logstash/conf.d/petclinic.conf
input {
beats {
host => "10.128.15.198"
port => 5045
}
}
filter{
grok {
match => {"message" => "%{TIMESTAMP_ISO8601}%{SPACE}%{LOGLEVEL:level}%{SPACE}(?<thread_info>\d+\s+---\s\[[\b\w*\d*-]*\]\s)%{JAVACLASS:class}%{SPACE}%{GREEDYDATA:logmessage}"}
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => "http://10.128.15.198:9200"
index => "springpetclinic-%{+YYYY.MM.dd}"
}
}
- Start the logstash service
sudo serivce
- Once the data is arrived create a index pattern in kibana
- Now use kql to search the logs Refer Here