How to install RavenDB on a VM in Azure (step-by-step, part 1)
This is a three part guide if you want to install RavenDB on a virtual machine in Azure. Sounds tricky? Let's start from the beginning.
Working with document databases can at first feel strange as a developer who have worked with relational databases. But after a while you really start to appreciate its beauty, possibilities and constraints. If you are new to document modelling then I highly recommend this video Modeling in a Non Relational World, by the author of RavenDB.
RavenDB is a full-featured NoSQL document database that works on multiple platforms including Windows, Linux, Docker…) It’s also open-source and the source-code can be found in their GitHub repository. RavenDB is written in C# and client libraries exists for .NET, Java, C++, Node.js, Python, Ruby, Go…
Installing Raven is fairly easy and you do recognise the time they have spent on polishing the setup- experience to make it as smooth as possible. However, when trying to get up and running in a secure way on a production server, you still will stumble up-on some gotchas that can give you some minor pain. In this blog-post I will present how I got RavenDB up and running on a plain Windows Server 16 virtual machine hosted in Azure to act as a production database.
I am sure there’s smarter ways of achieving the same thing, but this is how I did it and this guide is based on RavenDB version 4.1.5 (April 2019). Feedback or suggestions are always appreciated.
Our goal of this blog post is to setup a RavenDB instance on a clean Windows Server 2016 virtual machine instance and to be able to securely authenticate and connect to it from a .NET Core console application.
The Virtual machine
I won’t go into how you create the VM itself and most of the steps described here will be the same regardless of if you use Amazon, Google or some other provider hosting your VM. I also assume you are administrator and that you can remote-desktop into the machine.
In this example I have created a fresh Windows Server 2016 (Data Center edition) VM in Azure with a plain standard configuration.
Of course, we need to first install standard tools like Fiddler, Google Chrome, FireFox… and for that I use Chocolatey. Chocolatey is a Windows package manager allow you to install applications unattended, just like we use NuGet for our .NET dependencies. To make it even smoother, I first create a Install_Applications.bat that will allow me to both install Chocolatey and all my desired applications in one go:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco install notepadplusplus --x86 -y
choco install 7zip.install -y
choco install GoogleChrome -y
choco install firefox -y
choco install vcredist-all -y
choco install fiddler4 -y
(The first line is the script that installs Chocolatey as described in the installation instructions here)
Then I simply execute this file from an administrator command prompt:
Microsoft Visual C++ Redistributable Package is installed as part of the script above because RavenDB have a dependency on this library.
Don’t’ forget to set Chrome or Firefox as your default browser, because Internet Explorer 11 is the default browser in Windows Server 2016.
First, we need to download RavenDB for Windows. After download right-click on the .ZIP file to view the Properties dialog and Unblock the file, just to avoid any issues later on:
Then unzip the file and move the content to a new folder named c:\RavenDB.
Network and firewalls
In our setup we want to expose RavenDB to the public Internet so that clients outside Azure can connect to it.
In our case we choose the following two non-standard ports:
- Port 50000 for HTTPS traffic (default 443)
- Port 50001 for TCP/IP traffic (default 38888)
In Azure we first add an inbound security rule to open up port 50000 and 50001.
Then we need to add an inbound rule to the Windows firewall to open up port 50000 and 50001 for TCP/IP traffic.
You do this from the command line using:
netsh advfirewall firewall add rule name="RavenDB" dir=in action=allow protocol=TCP localport=50000,50001
(Or use the Windows Firewall application in Windows)
Setting up RavenDB
RavenDB can be run as a normal executable or as a Windows service in the background. We choose to run it as a service, because we want the database to always start when windows start-up. More about the various deployment options.
On the server, start a new PowerShell window, then navigate to c:\RavenDB and just simply launch the installation by running the .\setup-as-service.ps1 script:
The script will automatically register RavenDB as a service for you. When RavenDB starts up it will launch the RavenDB studio in your default web browser. Read through the EULA and accept it.
Read more about setting up RavenDB in part 2 of the guide.
C# Master Class
This class teaches you how to take advantage of what C# and .Net offer. It takes a range of real-world problems, and uses modern C# and .Net features to build clean, well designed, multi-paradigm solutions.Category: .NETDuration: 3 daysPrice: 25 900 SEK
How do you avoid making your project a big ball of mud? How do you balance a wide range of design concerns and constraints? How do you map customer requirements to working software? This course provides you with the means and methods to face these challenges.Category: Software ArchitectureDuration: 2 daysPrice: 21 500 SEK
Web Security for Developers
The web is a great software delivery platform, making your software available to users around the world with zero installation and easily deployed updates. Unfortunately, it also exposes you to an army of adversaries - some human, some bot - who have darker goals: to cause loss to your data or reputation, subvert your resources for their own gain or attack your user base.Category: Web DevelopmentDuration: 2 daysPrice: 21 500 SEK
Beginning ASP.NET Core
This course will give your ASP.NET Core development a solid start - in the right direction!Category: .NETDuration: 3 daysPrice: 25 900 SEK