I know most of you will be here for the EPIC title picture, the dinosaurs are from http://deviantart.com/susannehs/ – I hope she isn’t too disappointed 😮 The other art, well, that’s all mine… if you want graph information – feel free to ask, and if after seeing that picture you want art – let’s talk!
In the last post we looked at running Neo4j on a server running Windows Server 2019 Core. But what we did was run it in console mode so whenever you logged off, the server would shut down – which many would say is not ideal for a server.
So let’s install it as a service, as we’re adding a service into the server, we’re going to need to be an admin, so log on to your server as an admin (or use SSH – I will be).
Get to the right place
You don’t need to do this – but it makes life a bit easier. In your PowerShell window, let’s get to the right directory:
cd C:\Neo4j\neo4j-enterprise-4.2.1\
NB your Neo4j version might be different depending on when you do this. The script in the previous post will get the latest version.
Install as a service
.\bin\neo4j.bat install-service
Uh oh:
Invoke-Neo4j : Unable to determine the path to java.exe
At C:\Neo4j\neo4j-enterprise-4.2.1\bin\neo4j.ps1:18 char:7
+ Exit (Invoke-Neo4j -Verbose:$Arguments.Verbose -Command $Arguments.Ar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-Neo4j
Setup the Environment
This is because the scripts we’ve used to start the server so far call an environment.bat file beforehand – which sets up Java etc, but that is on a session by session basis – so we need to add the JAVA_HOME environment variable now:
If you look at the environment.bat file (micro ..\scripts\environment.bat) you’ll see this:
set zuluVersion=11.43.55
set jreVersion=11.0.9.1
set JAVA_HOME=%CD%\zulu%zuluVersion%-ca-jre%jreVersion%-win_x64
Again Version alert!! They may be different values on your server!!
So we want to set the JAVA_HOME environment variable, and we’ll add it to the path as well, unfortunately, these are cmd commands, so set JAVA_HOME doesn’t work in PowerShell, so we need to run:
One of the things which puts people off of Windows (and this likely won’t solve it, but hey!) is that it’s seen as BLOATWARE. Needing lots of RAM just to start up. Largely, that’s due to the UI, and whilst personally, I’m ok with the trade off (I think 2GB to be able to see what you’re doing is OK), not everyone is of that opinion. Also, there’s a shed load of things that don’t need a UI. Now, I’m not going to set up a server with SSL, the correct domain access etc – as that’s way beyond the scope of this, but I will get one up and running with Neo4j.
Java as a platform works just fine on Windows now, performance wise – there’s not much in it, the biggest difference is likely the cost of licenses – i.e. Ubuntu is free, Windows Server – not so much. But you might have licenses, and indeed engineers/admins who are already experienced in Windows, and don’t really know Linux (ahem – like me).
Things to note, there are things Windows doesn’t have by default, most notably, an ‘in-powershell-editor’ sigh – I remember good old edit but apparently, that’s not been available on x64 systems for ever, so we’ll put an editor in place for that, we’ll also be using a script to download and setup the whole thing, as it’s a lot easier than manually doing it – if you’re interested, you should be able to parse the script files to see what they are doing.
I’m going to start on the principle that you have got Server 2019 (I’m using 20H2) installed and you’re at the initial ‘admin’ prompt, in ‘Command Prompt’ (shudder). I am setting this up for me to use, so I’ll be setting some defaults that I want, you may not want/nor need to do it, but I like it, so :p
1. Install SSH
I want to SSH to my server, whilst I am running it in VMWare and so can do it via remote, I’d rather just open up MobaXTerm and connect in. To do that we need SSH to be setup, so first, just to check it’s not already installed (as of 20H2, it’s not be default), start Powershell:
C:\> powershell
Now run:
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
You should see if it’s installed or not, if either aren’t then run the appropriate commands below to install: (for example, I only had to install the server)
We’re nearly able to SSH, and you’ve got 2 options here, 1 – just use the current computer name, which will be a randomly generated string, and you’ll get that by running:
$env:computername
So – either use that, or change the computer name (which will force a restart):
Rename-Computer -computername 'NAME FROM ABOVE' -newname 'NEW_NAME' -force -restart
3. Update PowerShell You don’t need to do this
SSH to your server (or carry on using your VM host) – I use SSH from MobaXTerm as it allows me to do Copy/Paste easier, anyhews. To update to the Core version of PowerShell first download it:
I mean, it’s 2020, why PowerShell isn’t the default normally is a mystery to me. Anyhews, we have two places to set it – one is for the VM connection (which you may not need if you never intend to connect that way – but it might be useful), the other is for the SSH users out there:
This is from here, and it gives us an editor inside PowerShell, which is what we want. Install is probably too big-a-word for it, first we’ll download the release for us:
We’ll want this to allow us to edit the neo4j.conf file if we want to, and it’s nice to be able to edit locally. We should also add this to the PATH so we don’t have to know where it is all the time,
and edit within the SSH session. Obviously, you can change this to your editor of choice – vim etc
6. Let’s add a non-admin user:
The first line below will allow you to enter a password without the world seeing it, I mean – on your own VM for testing, you probably don’t need to do it – but good practices and all!
We’re going to download a script that will download all the appropriate programs (Neo4j Server, Java 11 etc) and configure things so we’re all ready to go. NB. The step where we cd into the C:\Neo4j folder IS IMPORTANT
This will set the default neo4j user to have the password neo
What you should see if you run the script
9. Change the scripts config
By default – it will allocate a heap of 2 GiB, and 1 GiB of page cache, I’ve been memory sensitive and only allocated 2GiB in total to my server, so if I run Neo4j now, it’ll use it all up and b0rk.
Go all the way to the bottom of the file and change the memory settings so they fit in your server, in my case, Heap = 256M, PageCache = 256M
Quick Micro tips
Backspace doesn’t work, use Delete instead
CTRL+S saves
CTRL+Q quits
10. Start Neo4j
We’re going to run this in console mode initially, allowing us to see it’s all ok, so run:
.\Scripts\start.ps1
What the ‘start’ script should output.
11. Allow the Firewall to have access (Admin)
Right, we’re nearing the home stretch, we need to add a Firewall rule to allow us to access the server, which we have to do as an Admin. Obviously, for a production environment, you’d set this all up properly, in particular the Profile – here, I’ve used 'Domain' and 'Private' – which means your network connection needs to be one of those, ideally, it would be one of those.
12. Set the Network profile to be ‘Private’ (Admin)
By default the connection you are on will be Public – which means the Firewall will block connections via our new rule, so for me, I’m going to change the network to be Private as it’s my own internal network and that’s accurate.
First, I need to get the network adapter name:
Get-NetAdapter
The red arrow points to the name we need
Now we have that, we need to get the current profile, which should be public: