Skip to content

Commit d9e369d

Browse files
Docker first look with openssl, mTLS and agent self registration (#158)
* corrected docker compose syntax. Folder is not specified this way anymore, and we don't actually need to specify it. * made URL point to Ops Manager artifacts * made URL point to Ops Manager artifacts * improved description of GRPC_SERVER_SECURITY_CLIENT_AUTH * updated to use openssl for certificate creation, mTLS and agent self-registration * corrected values to be replaced * typos * typos * made more compact without loosing information * refer to docker first look guide for a concrete example to avoid duplication * moved reference to the example to be a note in front of the steps * updated to use 5.x Neo4j setting names * Apply suggestions from code review Co-authored-by: Jessica Wright <[email protected]> * updated to use 5.x Neo4j setting names --------- Co-authored-by: Jessica Wright <[email protected]>
1 parent 8ab5c52 commit d9e369d

File tree

10 files changed

+156
-212
lines changed

10 files changed

+156
-212
lines changed

modules/ROOT/pages/addition/agent-installation/agent-self-signed-certificates.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ The NOM agent contains a utility to generate a self-signed certificate suitable
1515
----
1616
$> agent ssc --help
1717
18-
utility to generate self signed certificate for TEST purposes only
18+
utility to generate self-signed certificate for TEST purposes only
1919
2020
sample usage:
2121
22-
to generate a self signed certificate for 'localhost', which could either be
22+
to generate a self-signed certificate for 'localhost', which could either be
2323
accessed through DNS names of 'localhost.localdomain' or 'my.custom.domain', or
2424
with IP addresses of '127.0.0.1' or '192.168.100.5';
2525

modules/ROOT/pages/addition/docker/compose.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ test_local:
4343
NEO4J_ACCEPT_LICENSE_AGREEMENT: "yes"
4444
NEO4J_AUTH: neo4j/passw0rd
4545
NEO4J_EDITION: "enterprise"
46-
NEO4J_metrics_prometheus_enabled: "true"
47-
NEO4J_metrics_prometheus_endpoint: "localhost:2004"
48-
NEO4J_metrics_filter: "*"
46+
NEO4J_server_metrics_prometheus_enabled: "true"
47+
NEO4J_server_metrics_prometheus_endpoint: "localhost:2004"
48+
NEO4J_server_metrics_filter: "*"
4949
volumes:
5050
- /path/to/custom/entrypoint:/custom
5151
# - /path/to/agent/bin:/var/lib/neo4j/bin
5252
----
5353

54-
Above Neo4j instance as a Docker compose service can be used with similar instances as part of single compose deployment in test and local environments.
54+
Above Neo4j instance as a Docker compose service can be used with similar instances as part of single compose deployment in test and local environments.

modules/ROOT/pages/addition/docker/container.adoc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
= Monitor instance in standalone Docker container
22

3-
Running additional processes which are not tied to the lifecycle of container process is not a best practice for containerized applications. Nevertheless, it is possible transparently monitor a containerized Neo4j instance in following ways:
3+
Running additional processes that are not tied to the lifecycle of the container process is not a best practice for containerized applications.
4+
Nevertheless, it is possible to transparently monitor a containerized Neo4j instance in following ways:
45

56
[NOTE]
67
====
7-
All methods below use a bundled NOM agent inside the Neo4j image instead of downloaded agent packages. Replacing `products/neo4j-ops-manager-agent-*-linux-amd64.tar.gz` with
8-
path to NOM agent package downloaded should give the same results.
8+
Both methods below use a bundled NOM agent inside the Neo4j image instead of downloaded agent packages.
9+
Replacing `products/neo4j-ops-manager-agent-*-linux-amd64.tar.gz` with path to NOM agent package downloaded should give the same results.
910
====
1011

11-
. Monitoring a Neo4j instance Running inside a Docker container;
12-
12+
. Monitoring a Neo4j instance Running inside a Docker container:
13+
+
1314
[source, shell, role=noheader]
1415
----
1516
docker exec -dit <neo4j container name> /bin/sh 'tar -xzf products/neo4j-ops-manager-agent-*-linux-amd64.tar.gz --strip-components 1 \
@@ -29,14 +30,14 @@ CONFIG_INSTANCE_1_QUERY_LOG_MIN_DURATION="100" \
2930
NEO4J_ACCEPT_LICENSE_AGREEMENT="yes" \
3031
NEO4J_AUTH=neo4j/passw0rd \
3132
NEO4J_EDITION="enterprise" \
32-
NEO4J_metrics_prometheus_enabled="true" \
33-
NEO4J_metrics_prometheus_endpoint="localhost:2004" \
34-
NEO4J_metrics_filter="*" \
33+
NEO4J_server_metrics_prometheus_enabled="true" \
34+
NEO4J_server_metrics_prometheus_endpoint="localhost:2004" \
35+
NEO4J_server_metrics_filter="*" \
3536
agent console -s'
3637
----
3738

38-
. Start a Neo4j instance Docker container with NOM agent using a custom entry point;
39-
39+
. Start a Neo4j instance Docker container with NOM agent using a custom entry point:
40+
+
4041
[[entrypoint]]
4142
.entrypoint.sh
4243
[source, shell]
@@ -61,12 +62,12 @@ CONFIG_INSTANCE_1_QUERY_LOG_MIN_DURATION="100" \
6162
NEO4J_ACCEPT_LICENSE_AGREEMENT="yes" \
6263
NEO4J_AUTH=neo4j/passw0rd \
6364
NEO4J_EDITION="enterprise" \
64-
NEO4J_metrics_prometheus_enabled="true" \
65-
NEO4J_metrics_prometheus_endpoint="localhost:2004" \
66-
NEO4J_metrics_filter="*" \
65+
NEO4J_server_metrics_prometheus_enabled="true" \
66+
NEO4J_server_metrics_prometheus_endpoint="localhost:2004" \
67+
NEO4J_server_metrics_filter="*" \
6768
agent console -s
6869
----
69-
70+
+
7071
[source, shell, role=noheader]
7172
----
7273
docker run --entrypoint /custom/entrypoint.sh -e NEO4J_ACCEPT_LICENSE_AGREEMENT=yes -v <path/to/custom/entrypoint>:/custom $NEO4J_IMAGE

modules/ROOT/pages/addition/kubernetes/sidecar.adoc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
= NOM agent as a Sidecar
22

3-
A NOM agent can be deployed as a Sidecar container within the same pod as Neo4j instance in a Kubernetes cluster. Agent sidecar does not need to use a official agent image.
4-
An agent can simply be run in a lightweight linux based container such as `alpine`. The agent binary can be either mounted into container or can be extracted from Neo4j image using an init container.
3+
A NOM agent can be deployed as a Sidecar container within the same pod as Neo4j instance in a Kubernetes cluster.
4+
The agent Sidecar does not need to use an official agent image.
5+
An agent can simply be run in a lightweight Linux-based container such as `alpine`.
6+
The agent binary can be either mounted into a container or can be extracted from the Neo4j image using an init container.
57

68
[WARNING]
79
====
8-
An agent Sidecar container cannot access all resources that Neo4j pod uses and the host-metrics of the cluster node.
9-
For example, for disk usage metrics, the agent needs access to the file system or persistent volumes that Neo4j pod uses.
10-
These need to be mounted to the agent Daemon pod.
11-
The agent Sidecar can only report host metrics of its own contained environment which is not a complete view of resource usage of the cluster node.
10+
An agent Sidecar container cannot access all resources that the Neo4j pod uses and the host-metrics of the cluster node.
11+
For example, for disk usage metrics, the agent needs access to the file system or persistent volumes that the Neo4j pod uses.
12+
These need to be mounted to the agent Daemon pod.
13+
The agent Sidecar can only report host metrics of its own contained environment which is not a complete view of the resource usage of the cluster node.
1214
====
1315

1416
Following is a sample `values.yaml` file for Neo4j Helm charts with NOM agent sidecar configured:

modules/ROOT/pages/first-look/docker-first-look.adoc

Lines changed: 97 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,55 @@ Docker compose can be used to provision a set of related containers as services
66

77
Docker does not recommend using compose for production.
88

9-
The manual installation, configuring and running of agents on the Neo4j containers is lost if the container is stopped.
10-
119
== Prerequisites
1210
* Unix-based operating system
1311
* Docker
1412
* Docker compose
1513

1614
== Prepare hosts file
1715

18-
You need to set up the following host names in your `/etc/hosts` or `C:/windows/system32/drivers/etc/hosts file`;
16+
You need to set up the following host names in your `/etc/hosts` file:
1917
[source,, role=noheader]
2018
----
2119
127.0.0.1 storage server db-single
2220
----
2321

24-
== Create persistence DBMS and NOM server
25-
26-
=== Generate self-signed certificates
22+
== Generate self-signed certificates
2723

2824
. Create a directory *`~/.nom/ssc`* on your local machine before running Docker compose.
29-
The compose files below specify that this directory will be mounted into the docker container to make the generated certificates available to the NOM server and the agent.
25+
The compose files below specify that this directory will be mounted into the Docker container to make the generated certificates available to the NOM server and the agent.
26+
. Change to *`~/.nom/ssc`* and generate self-signed certificates using `server` as common name (CN) and DNS name, and `127.0.0.1` as IP address (details see *xref:installation/self-signed-certificate.adoc[here]*):
3027
+
28+
[source, shell]
29+
----
30+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
31+
-subj "/CN=server" \
32+
-addext "subjectAltName = DNS:server, IP:127.0.0.1" \
33+
-addext "keyUsage = critical, digitalSignature, keyEncipherment" \
34+
-addext "extendedKeyUsage = serverAuth" \
35+
-addext "authorityKeyIdentifier = keyid:always,issuer:always" \
36+
-keyout "server.key" \
37+
-out "server.cer"
38+
39+
openssl pkcs12 -export \
40+
-inkey "server.key" \
41+
-in "server.cer" \
42+
-out "server.pfx" \
43+
-password "pass:changeit"
44+
----
45+
This results in the creation of `server.cer`, `server.key` and `server.pfx`.
46+
. Use the password applied for the certificate store (`changeit`) instead of `<SSC_PASSWORD>` in the next sections.
47+
3148
[NOTE]
3249
====
33-
For *`sudo`* docker compose command, make sure the correct path to *`.nom/ssc`* is set in the bind section below.
50+
To keep this example simple, the generated certificates are used for both NOM server and agents.
3451
====
35-
. Change to *`~/.nom/ssc`* and generate self-signed certificates as described *xref:installation/self-signed-certificate.adoc[here]*, using `server` as common name (CN) and DNS name, and `127.0.0.1` as IP address.
36-
This results in the creation of `server.cer` and `server.pfx`.
37-
. Use the password applied for the certificate store instead of `<SSC_PASSWORD>` in the next sections.
38-
39-
=== Copy docker compose file
4052

41-
Following is a docker compose file that can be used to start up a NOM server and Enerprise Neo4j Persistence system without any customization.
42-
Copy this to your local machine as `docker-compose.yaml`.
53+
== Create the Docker compose file
4354

44-
Edit the yaml as follows:
45-
46-
* replace all three occurrences of <PERSISTENCE_PASSWORD> with a secure password.
47-
* replace all three occurrences of <SSC_PASSWORD> with a secure password.
55+
Following is a Docker compose file that can be used to start up a NOM server including its persistence and a single Neo4j Enterprise instance that will be managed by NOM.
56+
Create the file `docker-compose.yaml` in an empty directory on your local machine.
57+
This directory is referenced as `INSTALLATION_ROOT` later in this document.
4858

4959
.docker-compose.yaml
5060
[source, yaml]
@@ -55,7 +65,7 @@ networks:
5565
services:
5666
storage:
5767
hostname: storage
58-
image: neo4j:4.4.8-enterprise
68+
image: neo4j:enterprise
5969
networks:
6070
- lan
6171
ports:
@@ -93,6 +103,8 @@ services:
93103
GRPC_SERVER_SECURITY_KEY_STORE_PASSWORD: <SSC_PASSWORD>
94104
CORS_ALLOWEDHEADERS: "*"
95105
CORS_ALLOWEDORIGINS: "http://localhost:[*],https://localhost:[*], http://server:[*]"
106+
GRPC_SERVER_SECURITY_TRUST_CERT_COLLECTION: file:/certificates/server.cer
107+
GRPC_SERVER_SECURITY_CLIENT_AUTH: OPTIONAL
96108
volumes:
97109
- type: bind
98110
source: ~/.nom/ssc
@@ -101,55 +113,20 @@ services:
101113
- "sh"
102114
- "-c"
103115
- "java -jar app.jar"
104-
----
105-
106-
Documentation for NOM server docker image is *xref:installation/docker/container.adoc[here]*.
107-
108-
=== Run docker compose
109-
Run the follwing command:
110-
111-
[source, shell]
112-
----
113-
docker compose -f docker-compose.yaml up <folder for context, typically current folder>
114-
----
115-
116-
=== Open NOM UI
117-
Wait for the server container to start and then go to https://server:8080.
118-
Login as admin:passw0rd and accept license terms.
119-
120-
== Set up instance and agent
121-
122-
=== Register agent
123-
In NOM UI - navigate to Agent settings (clicking on the sad robot takes you to the correct page) and add a new agent.
124-
Copy environment variables that are provided.
125-
126-
Full documentation on registering an agent is *xref:addition/index.adoc#register[here]*.
127-
128-
=== Create docker compose file for Neo4j instance (pre-configured for agent)
129-
130-
Copy compose file below into `docker-compose.instance.yaml` and edit as follows:
131-
132-
* Replace `<CONFIG_TOKEN_CLIENT_ID from register agent step>` and `<CONFIG_TOKEN_CLIENT_SECRET from register agent step>` with the values shown during the reigister agent step in the NOM UI.
133-
* Replace all three occurrences of <NEO4J_INSTANCE_PASSWORD> with a secure password.
134-
135-
.docker-compose.instance.yaml
136-
[source, yaml]
137-
----
138-
services:
139116
db-single:
140117
hostname: db-single
141-
image: neo4j:5.5.0-enterprise
118+
image: neo4j:enterprise
142119
networks:
143120
- lan
144121
ports:
145122
- "10000:10000"
146123
- "10001:10001"
147124
environment:
148-
CONFIG_SERVER_ADDRESS: "server:9090"
149-
CONFIG_TOKEN_URL: "https://server:8080/api/login/agent"
150-
CONFIG_TOKEN_CLIENT_ID: "<CONFIG_TOKEN_CLIENT_ID from register agent step>"
151-
CONFIG_TOKEN_CLIENT_SECRET: "<CONFIG_TOKEN_CLIENT_SECRET from register agent step>"
125+
CONFIG_SERVER_GRPC_ADDRESS: "server:9090"
126+
CONFIG_SERVER_HTTP_ADDRESS: "https://server:8080"
152127
CONFIG_TLS_TRUSTED_CERTS: "/certificates/server.cer"
128+
CONFIG_TLS_CLIENT_CERT: "/certificates/server.cer"
129+
CONFIG_TLS_CLIENT_KEY: "/certificates/server.key"
153130
CONFIG_LOG_LEVEL: "debug"
154131
CONFIG_INSTANCE_1_NAME: "single-instance"
155132
CONFIG_INSTANCE_1_BOLT_URI: "bolt://db-single:10001"
@@ -170,8 +147,11 @@ services:
170147
NEO4J_server_metrics_filter: "*"
171148
volumes:
172149
- type: bind
173-
source: ~/.nom/ssc
174-
target: /certificates
150+
source: ~/.nom/ssc
151+
target: /certificates
152+
- type: bind
153+
source: agent
154+
target: /agent
175155
healthcheck:
176156
test: [ "CMD-SHELL", "echo RETURN 1 | cypher-shell -a bolt://db-single:10001 -u neo4j -p <NEO4J_INSTANCE_PASSWORD> || exit 1" ]
177157
interval: 10s
@@ -180,23 +160,71 @@ services:
180160
start_period: 5s
181161
----
182162

183-
=== Run docker compose
184-
Run the follwing command:
163+
Documentation for NOM server Docker image is *xref:installation/docker/container.adoc[here]*.
164+
165+
Edit `docker-compose.yaml` as follows:
166+
167+
* Replace all occurrences of `<SSC_PASSWORD>` with the certificate store password applied above.
168+
* Replace all occurrences of `<PERSISTENCE_PASSWORD>` with a secure password.
169+
* Replace all occurrences of `<NEO4J_INSTANCE_PASSWORD>` with a secure password.
170+
171+
== Start the Docker compose environment
172+
Run the following command in your `INSTALLATION_ROOT`:
185173

186174
[source, shell]
187175
----
188-
docker compose -f docker-compose.instance.yaml up <folder for context, typically current folder>
176+
docker compose -f docker-compose.yaml up
189177
----
190178

191-
=== Run agent
179+
Watch the output and make sure that the Docker containers `storage`, `server` and `db-single` are started successfully.
192180

181+
== Download and start the NOM agent
182+
183+
* Download NOM agent binaries TAR from https://neo4j.com/download-center/#ops-manager[here] and execute the following commands in your `INSTALLATION_ROOT`:
184+
+
193185
[source, shell]
194186
----
195-
docker compose -f docker-compose.instance.yaml exec sh -c tar -xvf products/neo4j-ops-manager-agent-*-linux-amd64.tar.gz && neo4j-ops-manager-agent-*/bin/agent console
187+
mkdir agent
188+
tar -xvf <DOWNLOADED_AGENT_BINARIES_TAR> -C agent --strip-components=1
189+
----
190+
* In `INSTALLATION_ROOT`, start the agent in self-registration mode:
191+
+
192+
[source, shell]
193+
----
194+
docker compose -f docker-compose.yaml exec db-single sh -c "/agent/bin/agent console -s"
196195
----
197196

197+
Full documentation on registering an agent is *xref:addition/agent-installation/index.adoc[here]*.
198+
198199
== Explore NOM UI
199-
Go to NOM UI and wait for DBMS to appear - this may take a few minutes.
200-
You should be able to see that the agent has connected in the agents listing.
200+
201+
* Wait for the server container to start and then go to https://server:8080.
202+
* Login as `admin` / `passw0rd` and accept license terms.
203+
* Click the top right settings icon that redirects you to the global settings.
204+
* Make sure that the agent is online.
205+
Rename the agent if required.
206+
* Return to the main page and wait for DBMS to appear - this may take a few minutes.
201207
Once the DBMS is shown in the home page, double-click on the name (initially a generated string) to edit it.
202208
Double-click on the DBMS to see the metrics, status, security panel, logs and upgrade pages for the DBMS.
209+
210+
== Controlling Docker containers
211+
212+
=== Stopping
213+
214+
* To stop the complete NOM environment, press `Ctrl-C` on the Docker compose console and the agent console.
215+
* To stop a single Docker container, issue `docker container stop <CONTAINER_NAME>`.
216+
To list containers use `docker ps`.
217+
218+
[NOTE]
219+
====
220+
Since Docker keeps persisted data in container volumes, restarted containers will keep the previous state.
221+
====
222+
223+
=== Resetting
224+
225+
To start over with an empty Neo4j persistence and empty managed instance, use the following Docker command (use `docker ps -a` to find out actual container names):
226+
227+
[source, shell]
228+
----
229+
docker container rm -v <STORAGE_CONTAINER_NAME> <SERVER_CONTAINER_NAME> <DB_SNGLE_CONTAINER_NAME>
230+
----

modules/ROOT/pages/first-look/linux-first-look.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NOTE: The query log feature is only available for DBMSs with instances that are
99
== Create persistence DBMS
1010

1111
=== Download and extract
12-
Download latest Neo4j Linux/Mac executable from https://neo4j.com/download-center/#ops-manager[here] and extract the package.
12+
Download latest Neo4j Linux/Mac executable from https://neo4j.com/download-center/#current-releases[here] and extract the package.
1313
Extracted directory location is referred to as NEO4J_HOME form now on.
1414

1515
=== Change password

0 commit comments

Comments
 (0)