Sentry’s cross-platform application monitoring helps teams in analysing the error and bugs in live applications. We internally use Sentry to track errors on our price comparison API This makes it easy for the team to analyse the error in various parts of the application and fix errors fastly. Today we will see how to set up sentry up and running on a ubuntu machine. There are official sentry docs on how to install sentry with docker, we tried the best to set it up from scratch on a vanilla machine faster.
Install sentry with docker
Swap Memory
We are considering a 1GB machine for the tutorial, however, it’s suggested to have at least 4GB machine so that memory issues won’t be popping up while installation.
SSH in to your machine.
We are adding a 4GB swap memory (since 1GB RAM can cause memory issues while installation). First, check if the system has configured any swap memory. You can skip this step if your machine has enough memory (At least 4GB)
sudo swapon –show
Then verify that there are no active swap utilized by the system by running,
free -h
Create a 4B swap using the following command.
sudo fallocate -l 4G /swapfile
Verify the allocation using the command.
ls -lh /swapfile
Now, apply the permissions to the swap file by running:
sudo chmod 600 /swapfile
Mark the file as swap by running the command:
sudo mkswap /swapfile
Now, enable the swap by running the command:
sudo swapon /swapfile
Rerun, the command to confirm that the swap is available.
free -h
2. Installing Docker
Now, let’s install docker into the machine. Set up the docker repository by running the following.
sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Once the repository has been set up, let install Docker CE
sudo apt-get update sudo apt-get install docker-ce
Finish the docker setup by verifying the installation by running,
sudo docker run hello-world
3. Installing Sentry on-premise
Now, clone the sentry on-premise repo using the following command.
https://github.com/getsentry/onpremise.git
Then cd into the folder and create a file and copy-paste the contents in the below file. Make the necessary changes in the config section on the top of the file before you begin the installation. The system.url-prefix will be the URL where the sentry will be available after installation. (Note: You need to config domain accordingly on your webserver).
cd onpremise && sudo nano installer.sh
#!/usr/bin/env bash echo "Applying config.yml values" cat <<EOT > config.yml auth.allow-registration: false #prevents public registration beacon.anonymous: true mail.backend: 'smtp' mail.from: "[email protected]" mail.host: "smtp.yourdomain.com" mail.password: "password" mail.port: 465 mail.use-tls: true mail.username: "[email protected]" system.admin-email: "[email protected]" system.url-prefix: "https://sentry.yourdomain.com" EOT echo "Building Sentry onpremise" make build docker container stop sentry-cron sentry-worker sentry-web sentry-postgres sentry-redis docker container rm sentry-cron sentry-worker sentry-web sentry-postgres sentry-redis docker run \ --detach \ --name sentry-redis \ redis:3.2-alpine docker run \ --detach \ --name sentry-postgres \ --env POSTGRES_PASSWORD='sentry' \ --env POSTGRES_USER=sentry \ -v /opt/docker/sentry/postgres:/var/lib/postgresql/data \ postgres:latest echo "Generating secret key" docker run --rm sentry-onpremise config generate-secret-key > key SENTRY_SECRET_KEY=$(cat key) echo "Running migrations" echo "This can take time based on memory usage" docker run \ --rm \ -it \ --link sentry-redis:redis \ --link sentry-postgres:postgres \ --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \ -v /opt/docker/sentry/sentry:/var/lib/sentry/files \ sentry-onpremise \ upgrade echo "Installing plugins" docker run \ --rm \ -it \ --link sentry-redis:redis \ --link sentry-postgres:postgres \ --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \ -v /opt/docker/sentry/sentry:/var/lib/sentry/files \ sentry-onpremise \ pip install sentry-plugins echo "Running service WEB" docker run \ --detach \ --link sentry-redis:redis \ --link sentry-postgres:postgres \ --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \ --name sentry-web \ --publish 9000:9000 \ -v /opt/docker/sentry/sentry:/var/lib/sentry/files \ sentry-onpremise \ run web sleep 15 echo "Running service WORKER" docker run \ --detach \ --link sentry-redis:redis \ --link sentry-postgres:postgres \ --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \ --name sentry-worker \ -v /opt/docker/sentry/sentry:/var/lib/sentry/files \ sentry-onpremise \ run worker sleep 15 echo "Running service CRON" docker run \ --detach \ --link sentry-redis:redis \ --link sentry-postgres:postgres \ --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \ --name sentry-cron \ -v /opt/docker/sentry/sentry:/var/lib/sentry/files \ sentry-onpremise \ run cron date sleep 60 date docker exec sentry-web sentry config set sentry:version-configured '9.1.0'
The above script is available on the internet and credit goes to the original author. The script will ask you to set up the default credentials during the process. Please note that the whole process can take some time based on your server capacity. If the process exited, it means that your server doesn’t have the required memory to run the process, either increase the swap or consider upgrading to a better machine.
Once installed, you can navigate over to the following address and finish the final stages.
your_server_ip:9000
4. Setting up Nginx
Setting up Nginx to serve your custom domain.
Install Nginx by running the below command.
sudo apt-get update sudo apt-get install nginx sudo ufw allow 'Nginx HTTP'
If you now navigate to your server IP address, you will be seeing the Nginx welcome page.
Add a configuration for your site.
cd /etc/nginx/sites-available sudo cp default sentry.yourdomain.com sudo nano sentry.yourdomain.com
Then paste the contents. Note: This is a bare minimum installation, add the security measures if needed.
server { listen 80; server_name sentry.yourdomain.com; location / { proxy_pass http://localhost:9000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Now, enable server blocks and restart nginx.
sudo ln -s /etc/nginx/sites-available/sentry.yourdomain.com /etc/nginx/sites-enabled/ sudo systemctl restart nginx
5. Add HTTPS using LetsEncrypt
Finally, we are adding HTTPS using Letsencrypt. Install certbot using the command.
sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-nginx
Once installed, generate a new HTTPS certificate using
sudo certbot –nginx -d sentry.yourdomain.com
Now, you can log in to sentry.yourdomain.com with the credentials you set up during the installation process; Now you have successfully set up sentry on-premise. If you liked our tutorial, you can read about our how-to article on Redis CSV import.
Let us know what you think about the tutorial in the comment box below.