一.前言
1.1 简介
Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中。它是一个嵌入式的、基于磁盘的、具备完全的事务特性的Java持久化引擎,但是它将结构化数据存储在网络(从数学角度叫做图)上而不是表中。Neo4j也可以被看作是一个高性能的图引擎,该引擎具有成熟数据库的所有特性。程序员工作在一个面向对象的、灵活的网络结构下而不是严格、静态的表中——但是他们可以享受到具备完全的事务特性、企业级的数据库的所有好处。
二.安装配置
2.1 部署master节点
master使用sts部署
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: neo4j-core
namespace: neo4j
labels:
app: neo4j-core
spec:
replicas: 2
selector:
matchLabels:
app: neo4j-core
serviceName: neo4j-core
template:
metadata:
labels:
app: neo4j-core
spec:
containers:
- name: neo4j-core
image: neo4j:3.5.5-enterprise # 官方镜像,3.5.5企业版
imagePullPolicy: IfNotPresent
env: # 这里通过env,配置镜像环境参数,这是因为此镜像是通过这样来进行配置参数的
- name: NEO4J_ACCEPT_LICENSE_AGREEMENT # 接受证书协议,必须的
value: "yes"
- name: NEO4J_dbms_connectors_default__advertised__address # 指定自身pod的ip地址,默认为localhost,在集群中必须注明自身地址,这里直接用ip
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: NEO4J_dbms_mode # 节点的模式,选择CORE,就是核心节点
value: "CORE"
- name: NEO4J_AUTH # 一定要自定义初始验证的用户名/密码
value: "neo4j/*******"
- name: NEO4J_causal__clustering_minimum__core__cluster__size__at__formation
value: "2"
- name: NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime
value: "2"
- name: NEO4J_causal__clustering_discovery__type # 默认集群发现方式为LIST,这里写不写都行
value: "LIST"
- name: NEO4J_causal__clustering_initial__discovery__members # 手动写明集群中所有成员的ip:port,5000端口为集群发现端口
value: "neo4j-core-0.neo4j.svc.cluster.local:5000,neo4j-core-1.neo4j.svc.cluster.local:5000"
- name: NEO4J_causal__clustering_discovery__advertised__address # 下面这三个必须定义,为节点自身的ip:port,相当于节点自身的名称,因为默认是会用自身hostname,但是在k8s中,无法单单通过hostname解析到ip地址,这样定义的自身地址会无法识别
value: $(NEO4J_dbms_connectors_default__advertised__address):5000
- name: NEO4J_causalClustering_transactionAdvertisedAddress
value: $(NEO4J_dbms_connectors_default__advertised__address):6000
- name: NEO4J_causalClustering_raftAdvertisedAddress
value: $(NEO4J_dbms_connectors_default__advertised__address):7000
volumeMounts:
- name: neo4j-core
mountPath: /data/neo4j
volumeClaimTemplates:
- metadata:
creationTimestamp: null
name: neo4j-core
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: ceph-storageclass
volumeMode: Filesystem
master节点svc
apiVersion: v1
kind: Service
metadata:
name: neo4j-core
namespace: neo4j
spec:
selector:
app: neo4j-core
type: NodePort
ports:
- protocol: TCP
name: http
port: 7474
nodePort: 31474
targetPort: 7474
- protocol: TCP
name: blot
port: 7687
nodePort: 31687
targetPort: 7687
2.2 部署slave节点
slave使用deploy部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: neorj-read-replica
namespace: neo4j
labels:
app: neorj-read-replica
spec:
replicas: 2
selector:
matchLabels:
app: neorj-read-replica
template:
metadata:
labels:
app: neorj-read-replica
spec:
containers:
- name: neorj-read-replica
image: neo4j:3.5.5-enterprise
imagePullPolicy: IfNotPresent
env:
- name: NEO4J_ACCEPT_LICENSE_AGREEMENT
value: "yes"
- name: NEO4J_dbms_connectors_default__advertised__address
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: NEO4J_dbms_mode # 指定模式为只读节点模式
value: "READ_REPLICA"
- name: NEO4J_AUTH
value: "neo4j/*******"
- name: NEO4J_causal__clustering_discovery__type
value: "LIST"
- name: NEO4J_causal__clustering_initial__discovery__members
value: "neo4j-core-0.neo4j.svc.cluster.local:5000,neo4j-core-1.neo4j.svc.cluster.local:5000"
slave svc
apiVersion: v1
kind: Service
metadata:
name: neorj-read-replica
namespace: neo4j
spec:
selector:
app: neorj-read-replica
ports:
- protocol: TCP
port: 7687
targetPort: 7687
创建namespace并部署
kubectl create ns neo4j
kubectl apply -f .