宝塔
快来分享你的内容吧~
后端部署(通用)
# 放行端口 + 3306 MySQL + 6379 Redis + 15672 RabbitMQ web 面板 + 5672 RabbitMQ + 22 端口 SSH + 443 HTTPS + 80 HTTP + 8848 Nacos + 9848 Nacos + 9849 Nacos <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/FaW4PipzwPg6MoQn.webp" alt="image-20241013000655616" width="100%" /> 还有服务器防火墙 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/9XtjJm5nD286omDD.webp" alt="image-20241015134440576" width="100%" /> # 宝塔 ## 安装 Java 环境 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/0rLxc7zaGna5R8rq.webp" alt="image-20240828111024249" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/laxjRzACMwkYzUhi.webp" alt="image-20240828111206797" width="100%" /> > 安装需要的 JDK ,这个项目安装 1.8.0_371 就可以 ## 安装 MySQL 1、安装 MySQL <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/7lIthNJCBvg6Ojz8.webp" alt="image-20241012235554319" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/Q2jqjByVoAPRXXSM.webp" alt="image-20241012235637421" width="642px" /> 2、放行端口 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/FaW4PipzwPg6MoQn.webp" alt="image-20241013000655616" width="100%" /> 还有服务器防火墙 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/9XtjJm5nD286omDD.webp" alt="image-20241015134440576" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/Q046nbyb4ViepjT4.webp" alt="image-20241013000847033" width="100%" /> 4、创建数据库 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/FSxW07u1x45lqUHx.webp" alt="image-20241014202256613" width="100%" /> 5、允许远程连接 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/mgX1ZFJjRYJ3YNPp.webp" alt="image-20241014202039444" width="560px" /> 6、使用测试工具进行连接 (以 IDEA 自带的为例) <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/GMXdN4WDru8gll4W.webp" alt="image-20241015134629453" width="674px" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/niDCp52hr31rkvnC.webp" alt="image.png" width="100%" /> 连接失败怎么办? 1、检查服务器端口是否放开 2、检查创建数据库的时候选择的 `访问权限` 是否是 `所有人` 3、检查`用户名`和`密码` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/Mwxd24vRKqmLhc7G.webp" alt="image-20241015135401548" width="516px" /> ## 安装 Redis 1、安装 Redis <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/0RSqs8pcK4cMHXjZ.webp" alt="image-20241015132439667" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/pGzyhZpRmZ9Xx0Wk.webp" alt="image-20241015132518917" width="622px" /> 4、修改设置文件 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/yvLwv3S1dWL0y3aX.webp" alt="image-20241015133641986" width="100%" /> 修改 bind 变成 `0.0.0.0` 然后设置 `requirepass` 这个就是密码 然后重载配置 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/7dAHetsUEkiiHMxG.webp" alt="image-20241015135039666" width="718px" /> 5、放行端口 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/BrkQRe1qx5a9XveY.webp" alt="image-20241015134115134" width="100%" /> 还有服务器防火墙 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/SAJD8nTPnAwO0kSa.webp" alt="image-20241015134440576" width="100%" /> 6、尝试连接 (以 IDEA 自带的为例) <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/vcRMI7DDwocnLHNy.webp" alt="image-20241015134209097" width="665px" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/DVlVV22gqZllQWVT.webp" alt="image.png" width="100%" /> 不需要填写用户名 密码填写之际之前在服务器`requirepass` 7、连接成功 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/I1LbHlUkWX5QEDHo.webp" alt="image.png" width="520px" /> ## 运行后端 上传 jar 包到服务器任意文件夹 比如 /www <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/CP0lgBU5XnHriQLl.webp" alt="image-20240814234039321" width="100%" /> 一定要注意,如果自己的使用的配置是 `application-prod.yml` 一定要在启动命令后面加上 `--spring.profiles.active=prod` ! <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/tZnJvWJ9SSgetu7c.webp" alt="image.png" width="679px" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/XVkBUPEtgcXh6Suu.webp" alt="image-20240814234444592" width="100%" /> # Docker 前期准备 + CentOS 安装 Docker [教程](https://www.runoob.com/docker/centos-docker-install.html) + Ubuntu 安装 Docker [教程](https://www.runoob.com/docker/ubuntu-docker-install.html) + JAR 文件 1、切换到工作目录 ``` cd ~ ``` 创建一个单独的目录,存放部署相关的文件 ``` mkdir project && cd project ``` 2、创建 Dockerfile 文件 + 上传 jar 包 创建 Dockerfile 文件 ``` touch Dockerfile ``` 创建完成之后,使用 rz 命令、或者 WinScp 上传,上传到和 Dockerfile 同级目录下 3、创建 Dockerfile 文件 1)FROM docker 运行的环境 openjdk:8 指的是在 java8 环境下运行镜像 + openjdk:8 + openjdk:17 2)WORKDIR 工作目录 3)COPY 复制 Linux 系统文件到容器之中 4)CMD 运行 Jar 包的命令,配置文件生效的是 `application-prod.yml` 当然可以修改 `--spring.profiles.active=prod` 后面的 active=xxx 如果想要 `application-test.yml` 生效那么直接写 `--spring.profiles.active=test` ``` FROM openjdk:8 WORKDIR /app # COPY ./user-center-backend-0.0.1-SNAPSHOT.jar ./app/application.jar COPY ./本地 jar 包的名称 ./app/application.jar CMD ["java","-jar","./app/application.jar","--spring.profiles.active=prod"] ``` 2、执行 docker build ``` docker build -t myapp:v1.0 . ``` + **`-t`**:`--tag` 的缩写,用于指定镜像名称和标签。比如 usercenter:v1.0 + **`.`**:表示当前目录是构建上下文,Docker 会从当前目录读取 `Dockerfile`,并将该目录中的文件打包到镜像中 + `myapp` 是镜像名称。 + `v1.0` 是镜像标签(版本),你也可以用 `latest ` 或其他标签。 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/Cp3dPlbzN9zJHBk9.webp" alt="image-20240827232904491" width="100%" /> 3、运行 docker 镜像 + **`-p 8080:8080`**:将主机的端口 8080 映射到容器的端口 8080。 + **`-t`**:分配一个伪终端(TTY),通常和交互模式一起使用,但这里是后台运行。 + **`-d`**:让容器以 **后台模式**(detached)运行。 + **`myapp:v1.0`**:指定要运行的 Docker 镜像名称和版本。 ``` docker run -p 8080:8080 -t -d myapp:v1.0 ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/NE8yhmQLN55Nlwnk.png" alt="image-20240827233047875" width="100%" /> 4、查看运行是否成功 ``` docker ps ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/HKrujmmKYJeCeu3Z.png" alt="image-20240827233159530" width="100%" /> 5、查看 log ``` docker logs -f CONTAINER ID 比如 docker logs -f 493820321e ``` CONTAINER ID 具体看 `docker ps` 里显示的 CONTAINER ID ## RabbitMQ Docker 安装就**相对简单**很多了! 1、下载 rabbitmq ``` docker pull rabbitmq:3.12.13-management ``` 2、运行 rabbitmq ``` docker run -d --name=rabbitmq -p 15672:15672 -p 5672:5672 rabbitmq:3.12.13-management ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/kgvBVOWkktvxJ49A.png" alt="image-20241009213651818" width="100%" /> 3、登录 web 管理界面 地址: `http://服务器IP:15672` 账号、密码默认 `guest` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/tzUoWYBWoa2TqiuB.png" alt="image-20241009214146062" width="100%" /> 4、看上面关于 创建用户&禁用默认用户远程访问 章节 ## Nacos > 如果速度比较慢的话可以设置一下 register [教程](https://gist.github.com/y0ngb1n/7e8f16af3242c7815e7ca2f0833d3ea6) 1、下载镜像 ```dockerfile docker pull nacos/nacos-server:v2.2.0 ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/cDV6eSsGzTGtxzF6.webp" alt="image-20241105000313361" width="100%" /> 2、查看 image ```dockerfile docker images ``` 3、初始化数据库 可以找到本地 `nacos/conf/mysql-schema.sql` 先创建数据,在使用数据库进行创建 sql ``` CREATE DATABASE nacos_config CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/YbXbhKGWwx6H9Fd8.webp" alt="image-20241105004509708" width="325px" /> 4、启动 `Nacos` ```dockerfile docker run \ --name nacos \ -d \ -p 8848:8848 \ -p 9848:9848 \ -p 9849:9849 \ --restart=always \ -e MYSQL_SERVICE_USER=root \ -e MYSQL_SERVICE_PASSWORD=密码 \ -e MYSQL_SERVICE_HOST=127.0.0.1 \ -e MYSQL_SERVICE_DB_NAME=nacos_config \ -e MODE=standalone \ nacos/nacos-server:v2.2.0 ``` 启动成功! <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/B0bUxUVyxHNH6wWG.webp" alt="image-20241105010150373" width="100%" /> ## Elasticsearch 1、拉取 Docker 镜像 任意目录执行 ``` docker pull elasticsearch:{version} ``` 比如: ``` docker pull elasticsearch:7.17.9 ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/9WgRnE2amZxCEoTQ.webp" alt="image-20241113224600007" width="100%" /> 2、创建一个 network 方便后期 Elasticsearch 和 Kibana 通信 ``` docker network create elastic ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/9F1c7tXuJbxiQPZn.png" alt="image-20241113225558492" width="745px" /> 3、运行 ``` docker run \ --name elasticsearch \ --net elastic \ -p 9200:9200 \ -e discovery.type=single-node \ -e ES_JAVA_OPTS="-Xms1g -Xmx1g"\ -e xpack.security.enabled=true \ -it \ -d \ elasticsearch:{version} ``` 比如 ```dock docker run \ --name elasticsearch \ --net elastic \ -p 9200:9200 \ -e discovery.type=single-node \ -e ES_JAVA_OPTS="-Xms1g -Xmx1g"\ -e xpack.security.enabled=true \ -it \ -d \ elasticsearch:7.17.9 ``` 4、修改账号密码 首先找到 `elasticsearch` 运行的 `container id` ``` docker ps ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/eWc2MkAPi7SqZCWN.png" alt="image-20241114000841762" width="100%" /> 进入到容器之中 ``` docker exec -it CONTAINER ID /bin/bash ``` > 这个 CONTAINER ID 就看 docker ps 的 CONTAIONER ID 比如 ``` docker exec -it 7c6be20a14e5 /bin/bash ``` --- 如果需要退出的话,直接输入 `exit` ``` exit ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/9RNb65BeM9A6Jxlb.webp" alt="Snipaste_2024-11-13_23-42-18" width="522px" /> --- 默认进入就是这个目录 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/QgRzNWAryxgAWcQx.png" alt="image-20241113234752668" width="100%" /> 执行下面的命令 ``` bin/elasticsearch-setup-passwords interactive ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/vegEQDAV2lks33Uv.webp" alt="image-20241113235048970" width="100%" /> 4、安装分词器 进入到容器之中 ``` docker exec -it CONTAINER ID /bin/bash ``` > 这个 CONTAINER ID 就看 docker ps 的 CONTAIONER ID 比如: ``` docker exec -it 7c6be20a14e5 /bin/bash ``` 下载地址:https://release.infinilabs.com/analysis-ik/stable ``` bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/{version}/{version}.zip ``` > 这个 version 具体看自己安装的版本 比如: ```` bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.9/elasticsearch-analysis-ik-7.17.9.zip ```` 如果速度非常慢可以先本地下载下来然后使用 docker cp ``` docker cp 文件 container_id:/usr/share/elasticsearch/plugins/elasticsearch-analysis-ik-7.17.9.zip ``` 找到对应目录,进入对应目录 `/usr/share/elasticsearch/plugins` ``` rm -rf /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik-7.17.9.zip ``` ``` unzip elasticsearch-analysis-ik-7.17.9.zip -d ik ``` 最后别忘了删除 `/usr/share/elasticsearch/plugins/elasticsearch-analysis-ik-7.17.9.zip` ``` cd /usr/share/elasticsearch/plugins ``` 查看是否安装成功 ``` bin/elasticsearch-plugin list ``` 5、最后重启使得配置生效 ``` docker restart elasticsearch ``` # Liunx 服务器直接安装 ## RabbitMQ ### 安装 DNF 1、 ``` yum install epel-release ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/G9Ea0ciRuO8uv6id.webp" alt="image-20241009203545454" width="100%" /> 2、 ``` yum install dnf ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/OhWVJYadSZ1Trwbn.webp" alt="image-20241009203632789" width="100%" /> 安装成功 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/LZVgOmSTuzp2scBv.webp" alt="image-20241009203651254" width="100%" /> ### 安装 RabbitMQ 1、指定仓库 ``` sudo dnf install -y https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm ``` 2、安装 `rabbitmq` 默认会安装 `erlang` ``` sudo dnf install -y rabbitmq-server-3.3.5-34.el7 ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/DXpGARdf3DP09VY9.webp" alt="image-20241009211123061" width="100%" /> 3、开启 web 管理页面 ``` sudo rabbitmq-plugins enable rabbitmq_management ``` 4、启动 RabbitMQ ``` sudo systemctl start rabbitmq-server ``` 5、查看运行状态 ``` systemctl status rabbitmq-server ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/EK9Mdk13KDzIsw1k.webp" alt="image-20241009212252468" width="100%" /> 6、设置开机自启动 ``` sudo systemctl enable rabbitmq-server ``` ### 登录 web 管理界面 http://服务器IP:15672 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/kC6o14lhMaSnwUMW.png" alt="image-20241009214139890" width="100%" /> 默认账号、密码都是 `guest` 要是报错就自己再仔细看看是不是输入错误了 ### 创建用户&禁用默认用户远程访问 + 创建用户 + 允许远程连接 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/Oay9MYagUe056HnW.webp" alt="image-20241009200510767" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/eXQkhu6jl3ohnn8M.webp" alt="image-20241009200822956" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/ta1IB8L2LhSosHR7.webp" alt="image-20241009200851259" width="100%" /> --- **重要** 关闭允许 `guest` 用户远程访问,为了安全 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/WEK3UPRgpsmeomsb.webp" alt="image-20241009201040420" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/hPAUn57pYcAz5eAr.webp" alt="image-20241009201140735" width="100%" /> ## Nacos ### 安装依赖环境 Ubuntu > 设置[Ubuntu阿里镜像](https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11cBkIsz) 1)更新系统软件包 ``` sudo apt-get update ``` 2)安装对应的依赖 `wget` `unzip` `Java` ``` sudo apt-get install wget unzip openjdk-8-jdk ``` --- CentOS > 设置[CentOS阿里镜像](https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11cBkIsz) 1)更新系统软件包 ``` sudo yum update -y ``` 2)安装对应的依赖 `wget` `unzip` `Java` ``` sudo yum install -y wget unzip java-1.8.0-openjdk ``` ### 下载 Nacos 1、下载文件 1)进入工作目录 ``` cd ~ ``` 2)创建目录 ``` mkdir nacos ``` 3)进入目录,并且下载 zip 文件 ``` wget https://github.com/alibaba/nacos/releases/download/2.2.0/nacos-server-2.2.0.zip ``` > 这个速度可能会比较慢,可以本地下载好的上传到服务器上 2、解压文件 ``` unzip nacos-server-2.2.0.zip ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/sYUlUUVhm4AIIi5Y.webp" alt="image-20241103170938289" width="100%" /> 3、设置数据库 先创建一个数据库 ```mysql CREATE DATABASE nacos_config CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ``` 然后在对应数据库下执行 `nacos/conf/mysql-schema.sql` 建表语句 然后修改 `nacos/conf/application.properties` 的内容 > 下面是源文件内容 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/lLcxYlrzcN4LTALe.webp" alt="image-20241103225328866" width="100%" /> 修改成 ```properties ### If use MySQL as datasource: # spring.datasource.platform=mysql ### Count of DB: # db.num=1 ### Connect URL of DB: db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user.0=nacos # mysql 用户名 db.password.0=nacos # mysql 密码 ``` 4、进入 bin 目录启动 ``` cd nacos/bin ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/cWtHxaQMn2l1wjbC.webp" alt="image-20241103171138299" width="492px" /> ``` sudo bash startup.sh -m standalone ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/nv5QWkGRyoPEfObq.webp" alt="image-20241103171102914" width="100%" /> > 这里如果是 Ubuntu 的话一定要用 **bash** startup.sh -m standalone 如果是 sh 会报错 Caused by: java.net.UnknownHostException: jmenv.tbsite.net > at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) 5、访问 web 管理页面 首先要把服务器的 `8848` 打开,如果有宝塔 `8848` http://服务器IP:8848/nacos/index.html 6、关闭 Nacos ``` sudo bash shutdown.sh ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/kYklzgeLQdwu2ZWE.png" alt="image-20241103214451131" width="531px" /> ## 安装 Elasticsearch 1、更新安装包和下载依赖 Ubuntu > 设置[Ubuntu阿里镜像](https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11cBkIsz) 1)更新系统软件包 ``` sudo apt-get update ``` 2)安装对应的依赖 `wget` `unzip` ``` sudo apt-get install wget tar unzip rpm openjdk-8-jdk ``` --- CentOS > 设置[CentOS阿里镜像](https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11cBkIsz) 1)更新系统软件包 ``` sudo yum update -y ``` 2)安装对应的依赖 `wget` `unzip` ``` sudo yum install -y wget tar unzip rpm openjdk-8-jdk ``` 2、下载 elasticsearch **7.x 版本** ``` wget https://artifacts.elastic.co/downloads/elasticsearch/{version}-amd64.deb ``` 比如: ``` wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.9-amd64.deb ``` 3、下载完成后,继续安装包 ```yml sudo dpkg -i elasticsearch-{version}-amd64.deb ``` 比如: ``` sudo dpkg -i elasticsearch-7.17.9-amd64.deb ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/t98Z1U5IYajz7cS8.webp" alt="image-20241113002329216" width="100%" /> 4、enable elasticsearch service 和 启动 elasticsearch service ``` sudo systemctl enable elasticsearch.service sudo systemctl start elasticsearch.service ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/sCBH4AbDItyMtf6W.webp" alt="image-20241113002517242" width="100%" /> 5、修改 Ubuntu 配置文件 1)修改 network 把 `127.0.0.1` 改成 `0.0.0.0` 2)修改,如果没有的话就添加 `discovery.type` 写成 `single-node` ``` vi /etc/elasticsearch/elasticsearch.yml ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/lZrHtPYCdYjJNIdJ.webp" alt="image-20241113003300120" width="100%" /> <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/WJVVvUY5C4jf4nEB.webp" alt="image-20241113104450525" width="100%" /> 6、重启配置 ``` sudo systemctl restart elasticsearch.service ``` 7、测试是否运行成功 ``` curl -X GET "localhost:9200/?pretty" ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/DKf2vg7N9mZKgy94.webp" alt="image-20241113004728562" width="100%" /> 8、添加安装分词器 ``` ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/{version}/{version}.zip ``` 比如: ```` ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.9/elasticsearch-analysis-ik-7.17.9.zip ```` 速度很慢的话,就本地下载好,上传到 `/usr/share/elasticsearch` ``` cd /usr/share/elasticsearch/plugins ``` 上传到对应目录之后,进行解压 ``` unzip elasticsearch-analysis-ik-7.17.9.zip -d ik ``` 解压完成之后需要删除 `elasticsearch-analysis-ik-7.17.9.zip` ``` rm -f elasticsearch-analysis-ik-7.17.9.zip ``` 查看是否安装成功 ``` ./elasticsearch-plugin list ``` 启用需要重新启动 ``` sudo systemctl restart elasticsearch.service ``` ### 添加用户 1. [官方文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/users-command.html) 2. 扩展 REST 添加用户[链接](https://opster.com/guides/elasticsearch/operations/creating-managing-users-elasticsearch/) 3. 确保 `elasticsearch` 是运行状态 1、修改 `/etc/elasticsearch/elasticsearch.yml` 文件 在里面添加 ` xpack.security.enabled: true` ``` vi /etc/elasticsearch/elasticsearch.yml ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/u9MhJb4yyxhriSvL.webp" alt="image-20241113200522639" width="727px" /> 2、设置用户名密码 进入 `/usr/share/elasticsearch/bin` ``` cd /usr/share/elasticsearch/bin ``` ``` ./elasticsearch-setup-passwords interactive ``` 设置 elastic, kibana, logstash_system,beats_system 这几个用户的密码 <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/DN4oiUUW9BNXEWXN.webp" alt="image-20241113203336673" width="100%" /> 如果想要修改这个 `elastic` 密码 ``` curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "修改后的密码" }' ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/b8xxmfHjMQNps3zU.png" alt="image-20241113203923421" width="100%" /> 2、在服务器本执行 ``` curl -X POST "http://localhost:9200/_security/user/leikooo" -H "Content-Type: application/json" -u "elastic:leikooo" -d ' { "password" : "123456", "roles" : [ "admin"], "full_name" : "leikooo", "enabled": true }' ``` <img src="https://pic.code-nav.cn/post_picture/1608460212774109186/JJmqVHmGQKiBEb5d.webp" alt="image-20241113204225770" width="100%" />
