OR博客
使用Docker安装Neo4j
苗锦洲
创建于:2024-11-28 10:22:21
更新于:2024-11-28 11:19:59
上海
1
10
76
0
### 1 安装Docker Windows安装Docker时,需要先开启 `Hyper-V`功能,启用脚本如下,新建一个文本文档,把下面的命令复制进去,把拓展名从 `txt`改为 `bat`,右键以管理员身份执行 ```bat pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL ``` 等待执行完成,执行成功后需要重启电脑,然后安装Docker Desktop [Docker: Accelerated Container Application Development](https://www.docker.com/) 选择合适的版本下载安装即可 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/ccd2039d5944408baea87ebd41fe8ea5.png) ### 2 安装Neo4jDesktop 直接从官网下载安装即可 [Neo4j Desktop Download | Free Graph Database Download](https://neo4j.com/download/) ### 3 运行Neo4j镜像 需要先创建好挂载目录 - `D:\Neo4j\data` - `D:\Neo4j\logs` - `D:\Neo4j\confi` - `D:\Neo4j\import` - `D:\Neo4j\plugins` 然后在powershell中执行如下命令,默认用户名 `neo4j`和密码 `abc123456` ```bat docker run ` --name neo4j ` --restart always ` --publish=7474:7474 --publish=7687:7687 ` --env NEO4J_AUTH=neo4j/abc123456 ` --volume=D:\Neo4j\data:/data ` --volume=D:\Neo4j\logs:/logs ` --volume=D:\Neo4j\conf:/var/lib/neo4j/conf ` --volume=D:\Neo4j\import:/var/lib/neo4j/import ` --volume=D:\Neo4j\plugins:/var/lib/neo4j/plugins ` --env NEO4J_server_default__listen__address=0.0.0.0 ` --env NEO4J_PLUGINS='[\"apoc\", \"apoc-extended\", \"n10s\", \"graph-data-science\"]' ` --env NEO4J_dbms_security_procedures_unrestricted=',jwt.security.*,gds.*,apoc.*' ` neo4j:5.25.1 ``` 执行成功后结果效果所示 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/de10a51b36f6494493c976c9cace3ce3.png) ### 4 使用Neo4jDesktop连接neo4j容器 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/fd862e293f484dba80a1093a1aa9468f.png) ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/1ad974a7d0894312814dccd421c95cad.png) ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/6837a17825834ae682b42b2e729f4731.png) ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/c96fe0d185114c508f127cf82a09ba0b.png) ### 5 导入数据 将要导入的csv文件复制到 `D:\Neo4j\import`目录下 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/a2be6c2e8fa44e058a4396205ec86a0d.png) 然后进入容器内 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/926910b073b240dcbaf9dfdddab5e948.png) 输入 `cypher-shell`回车,然后输入用户名和密码 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/5064e6853cc04f35b5e6dc4fe529704c.png) 复制粘贴执行以下命令 ```bash LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/baojing.csv" AS line MERGE (:Errorid { title: line.title }); CREATE CONSTRAINT FOR (c:Errorid) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/caozuo.csv" AS line MERGE (:Caozuo { title: line.title }); CREATE CONSTRAINT FOR (c:Caozuo) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiang.csv" AS line MERGE (:Xianxiang { title: line.title }); CREATE CONSTRAINT FOR (c:Xianxiang) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/zhuyu.csv" AS line MERGE (:GuzhangBuwei { title: line.title }); CREATE CONSTRAINT FOR (c:GuzhangBuwei) REQUIRE c.title IS UNIQUE;LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/yuanyin2.csv" AS line MERGE (:Yuanyin { title: line.title }); CREATE CONSTRAINT FOR (c:Yuanyin) REQUIRE c.title IS UNIQUE; LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/caozuoxianxaing.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:CX { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiangyuanyin.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XY { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxiangxianxiang.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XX { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxaingbuwei.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XB { type: line.relation }]->(entity2); LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/xianxaingbaojing.csv" AS line MATCH (entity1 {title:line.title1}),(entity2 {title:line.title2}) CREATE (entity1)-[:XJ { type: line.relation }]->(entity2); ``` ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/1989d71488d440338b3f233f3809488f.png) 在GDS中查看导入的数据 ![image.png](https://api.ordinaryroad.tech/upms/file/download/ordinaryroad-blog/2024-11-28/6b4e6b159dc14a238dbe8fe559e73e16.png)
评论