Centos安装OpenSearch

news2024/9/30 13:26:06

Centos安装OpenSearch

  • 下载并安装OpenSearch
    • 下载OpenSearch RPM包
    • 导入公共GNU Privacy Guard(GPG)密钥。此密钥验证您的OpenSearch实例是否已签名
    • 安装RPM包
    • 安装完设置开机自启动OpenSearch
    • 启动OpenSearch
    • 验证OpenSearch是否正确启动
  • 测试OpenSearch
    • 向服务器发送请求以验证OpenSearch是否正在运行
      • 向端口9200发送请求
      • 查询插件端点
  • 设置OpenSearch可远程连接
    • 将OpenSearch绑定到主机上的IP或网络接口
      • 打开opensearch.yml
      • 添加以下行
      • 保存更改并关闭文件
    • 设置初始和最大JVM堆大小
    • 配置TLS
      • 导航到将存储证书的目录
      • 删除演示证书
      • 生成根证书,这将用于签署其他证书
      • 创建管理员证书,此证书用于获得执行与安全插件相关的管理任务的提升权限
      • 为正在配置的节点创建证书
      • 删除不再需要的临时文件
      • 确保其余证书归opensearch用户所有
      • 按照生成证书中的说明将这些证书添加到opensearch.yml,推荐选择使用脚本进行设置
        • 新建shell脚本文件 append-setting.sh
        • 执行append-setting.sh
      • 为自签名根证书添加信任(可选)
    • 配置用户
      • 导航到安全插件工具目录
      • 运行hash.sh生成新密码
      • 打开internal_users.yml
      • 删除除admin之外的所有演示用户,并将哈希替换为上一步中hash.sh提供的输出。
    • 应用更改
      • 必须运行OpenSearch,securityadmin.sh才能应用更改,如果您对opensearch.yml进行了更改,请重新启动opensearch
      • 打开与主机的单独终端会话,并导航到包含securityadmin.sh的目录
      • 调用securityadmin.sh脚本
    • 验证服务是否正在运行
  • 总结

下载并安装OpenSearch

下载OpenSearch RPM包

X64系统

wget https://artifacts.opensearch.org/releases/bundle/opensearch/2.16.0/opensearch-2.16.0-linux-x64.rpm

ARM64系统

wget https://artifacts.opensearch.org/releases/bundle/opensearch/2.16.0/opensearch-2.16.0-linux-arm64.rpm

导入公共GNU Privacy Guard(GPG)密钥。此密钥验证您的OpenSearch实例是否已签名

sudo rpm --import https://artifacts.opensearch.org/publickeys/opensearch.pgp

安装RPM包

## Install the x64 package using rpm.
sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> rpm -ivh opensearch-2.16.0-linux-x64.rpm
## Install the arm64 package using rpm.
sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> rpm -ivh opensearch-2.16.0-linux-arm64.rpm

安装完设置开机自启动OpenSearch

sudo systemctl enable opensearch

启动OpenSearch

sudo systemctl start opensearch

验证OpenSearch是否正确启动

sudo systemctl status opensearch

测试OpenSearch

向服务器发送请求以验证OpenSearch是否正在运行

向端口9200发送请求

curl -X GET https://localhost:9200 -u 'admin:<custom-admin-password>' --insecure

响应:

{
    "name":"hostname",
    "cluster_name":"opensearch",
    "cluster_uuid":"QqgpHCbnSRKcPAizqjvoOw",
    "version":{
       "distribution":"opensearch",
       "number":<version>,
       "build_type":<build-type>,
       "build_hash":<build-hash>,
       "build_date":<build-date>,
       "build_snapshot":false,
       "lucene_version":<lucene-version>,
       "minimum_wire_compatibility_version":"7.10.0",
       "minimum_index_compatibility_version":"7.0.0"
    },
    "tagline":"The OpenSearch Project: https://opensearch.org/"
 }

查询插件端点

curl -X GET https://localhost:9200/_cat/plugins?v -u 'admin:<custom-admin-password>' --insecure

响应:

name          component                            version
 hostname      opensearch-alerting                  2.15.0
 hostname      opensearch-anomaly-detection         2.15.0
 hostname      opensearch-asynchronous-search       2.15.0
 hostname      opensearch-cross-cluster-replication 2.15.0
 hostname      opensearch-geospatial                2.15.0
 hostname      opensearch-index-management          2.15.0
 hostname      opensearch-job-scheduler             2.15.0
 hostname      opensearch-knn                       2.15.0
 hostname      opensearch-ml                        2.15.0
 hostname      opensearch-neural-search             2.15.0
 hostname      opensearch-notifications             2.15.0
 hostname      opensearch-notifications-core        2.15.0
 hostname      opensearch-observability             2.15.0
 hostname      opensearch-performance-analyzer      2.15.0
 hostname      opensearch-reports-scheduler         2.15.0
 hostname      opensearch-security                  2.15.0
 hostname      opensearch-security-analytics        2.15.0
 hostname      opensearch-sql                       2.15.0

设置OpenSearch可远程连接

默认情况下,OpenSearch不绑定到网络接口,外部主机无法访问。此外,安全设置由默认用户名和密码填充。以下建议将使用户能够将OpenSearch绑定到网络接口,创建和签署TLS证书,以及配置基本身份验证

将OpenSearch绑定到主机上的IP或网络接口

打开opensearch.yml

sudo vi /etc/opensearch/opensearch.yml

添加以下行

# Bind OpenSearch to the correct network interface. Use 0.0.0.0
# to include all available interfaces or specify an IP address
# assigned to a specific interface.
network.host: 0.0.0.0

# Unless you have already configured a cluster, you should set
# discovery.type to single-node, or the bootstrap checks will
# fail when you try to start the service.
discovery.type: single-node

# If you previously disabled the Security plugin in opensearch.yml,
# be sure to re-enable it. Otherwise you can skip this setting.
plugins.security.disabled: false

保存更改并关闭文件

:wq

设置初始和最大JVM堆大小

vi /etc/opensearch/jvm.options

修改初始堆大小和最大堆大小的值。作为起点,您应该将这些值设置为可用系统内存的一半。对于专用主机,可以根据您的工作流程要求增加此值。
例如,如果主机有8GB的内存,那么您可能希望将初始堆大小和最大堆大小设置为4GB:

-Xms4g
-Xmx4g

配置TLS

导航到将存储证书的目录

cd /etc/opensearch

删除演示证书

sudo rm -f *pem

生成根证书,这将用于签署其他证书

# Create a private key for the root certificate
sudo openssl genrsa -out root-ca-key.pem 2048
   
# Use the private key to create a self-signed root certificate. Be sure to
# replace the arguments passed to -subj so they reflect your specific host.
sudo openssl req -new -x509 -sha256 -key root-ca-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=ROOT" -out root-ca.pem -days 730

创建管理员证书,此证书用于获得执行与安全插件相关的管理任务的提升权限

# Create a private key for the admin certificate.
sudo openssl genrsa -out admin-key-temp.pem 2048

# Convert the private key to PKCS#8.
sudo openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
   
# Create the certficiate signing request (CSR). A common name (CN) of "A" is acceptable because this certificate is
# used for authenticating elevated access and is not tied to a host.
sudo openssl req -new -key admin-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=A" -out admin.csr
   
# Sign the admin certificate with the root certificate and private key you created earlier.
sudo openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 730

为正在配置的节点创建证书

# Create a private key for the node certificate.
sudo openssl genrsa -out node1-key-temp.pem 2048
   
# Convert the private key to PKCS#8.
sudo openssl pkcs8 -inform PEM -outform PEM -in node1-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node1-key.pem
   
# Create the CSR and replace the arguments passed to -subj so they reflect your specific host.
# The CN should match a DNS A record for the host-do not use the hostname.
sudo openssl req -new -key node1-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node1.dns.a-record" -out node1.csr
   
# Create an extension file that defines a SAN DNS name for the host. This
# should match the DNS A record of the host.
sudo sh -c 'echo subjectAltName=DNS:node1.dns.a-record > node1.ext'

# Sign the node certificate with the root certificate and private key that you created earlier.
sudo openssl x509 -req -in node1.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node1.pem -days 730 -extfile node1.ext

删除不再需要的临时文件

sudo rm -f *temp.pem *csr *ext

确保其余证书归opensearch用户所有

sudo chown opensearch:opensearch admin-key.pem admin.pem node1-key.pem node1.pem root-ca-key.pem root-ca.pem root-ca.srl

按照生成证书中的说明将这些证书添加到opensearch.yml,推荐选择使用脚本进行设置

新建shell脚本文件 append-setting.sh
vi aplpend-seeting.sh

#! /bin/bash

# Before running this script, make sure to replace the CN in the 
# node's distinguished name with a real DNS A record.

echo "plugins.security.ssl.transport.pemcert_filepath: /etc/opensearch/node1.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.transport.pemkey_filepath: /etc/opensearch/node1-key.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.transport.pemtrustedcas_filepath: /etc/opensearch/root-ca.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.http.enabled: true" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.http.pemcert_filepath: /etc/opensearch/node1.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.http.pemkey_filepath: /etc/opensearch/node1-key.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.ssl.http.pemtrustedcas_filepath: /etc/opensearch/root-ca.pem" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.allow_default_init_securityindex: true" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.authcz.admin_dn:" | sudo tee -a /etc/opensearch/opensearch.yml
echo "  - 'CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.nodes_dn:" | sudo tee -a /etc/opensearch/opensearch.yml
echo "  - 'CN=node1.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.audit.type: internal_opensearch" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.enable_snapshot_restore_privilege: true" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.check_snapshot_restore_write_privileges: true" | sudo tee -a /etc/opensearch/opensearch.yml
echo "plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]" | sudo tee -a /etc/opensearch/opensearch.yml
执行append-setting.sh
sh append-setting.sh

为自签名根证书添加信任(可选)

# Copy the root certificate to the correct directory
sudo cp /etc/opensearch/root-ca.pem /etc/pki/ca-trust/source/anchors/

# Add trust
sudo update-ca-trust

配置用户

导航到安全插件工具目录

cd /usr/share/opensearch/plugins/opensearch-security/tools

运行hash.sh生成新密码

如果未定义JDK的路径,则hash.sh脚本将失败。

# Example output if a JDK isn't found...
 $ ./hash.sh
 **************************************************************************
 ** This tool will be deprecated in the next major release of OpenSearch **
 ** https://github.com/opensearch-project/security/issues/1755           **
 **************************************************************************
 which: no java in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin)
 WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use 
 ./hash.sh: line 35: java: command not found

在这里插入图片描述
在调用脚本时声明环境变量以避免问题

OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk ./hash.sh

在提示下输入所需的密码,并记下输出哈希值。
在这里插入图片描述

打开internal_users.yml

sudo vi /etc/opensearch/opensearch-security/internal_users.yml

删除除admin之外的所有演示用户,并将哈希替换为上一步中hash.sh提供的输出。

该文件应类似于以下示例:

---
# This is the internal user database
# The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh

_meta:
   type: "internalusers"
   config_version: 2

# Define your internal users here

admin:
   hash: "$2y$1EXAMPLEQqwS8TUcoEXAMPLEeZ3lEHvkEXAMPLERqjyh1icEXAMPLE."
   reserved: true
   backend_roles:
   - "admin"
   description: "Admin user"

在这里插入图片描述

应用更改

现在安装了TLS证书,并删除了演示用户或为其分配了新密码,最后一步是应用配置更改。最后一个配置步骤需要在主机上运行OpenSearch时调用securityadmin.sh

必须运行OpenSearch,securityadmin.sh才能应用更改,如果您对opensearch.yml进行了更改,请重新启动opensearch

sudo systemctl restart opensearch

打开与主机的单独终端会话,并导航到包含securityadmin.sh的目录

# Change to the correct directory
cd /usr/share/opensearch/plugins/opensearch-security/tools

调用securityadmin.sh脚本

# You can omit the environment variable if you declared this in your $PATH.
OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk ./securityadmin.sh -cd /etc/opensearch/opensearch-security/ -cacert /etc/opensearch/root-ca.pem -cert /etc/opensearch/admin.pem -key /etc/opensearch/admin-key.pem -icl -nhnv

在这里插入图片描述

验证服务是否正在运行

$ curl https://your.host.address:9200 -u admin:yournewpassword -k
{
  "name" : "hostname-here",
  "cluster_name" : "opensearch",
  "cluster_uuid" : "efC0ANNMQlGQ5TbhNflVPg",
  "version" : {
    "distribution" : "opensearch",
    "number" : <version>,
    "build_type" : <build-type>,
    "build_hash" : <build-hash>,
    "build_date" : <build-date>,
    "build_snapshot" : false,
    "lucene_version" : <lucene-version>,
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}

在这里插入图片描述

总结

至此OpenSearch安装完成并配置可远程连接
Ubuntu安装OpenSearch请参考Ubuntu安装OpenSearch

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1991518.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【lvs】超干货,包含理论+实验(详细步骤)

lvs理论部分 LVS&#xff08;Linux Virtual Server&#xff09;是Linux虚拟服务器的简称&#xff0c;是一个基于Linux操作系统的虚拟服务器集群系统。LVS主要用于实现负载均衡和高可用性&#xff0c;通过将客户端的请求分发到多台后端服务器上&#xff0c;从而提高整体服务的处…

JSON + AJAX + ThreadLocal

JSON数据交换 规则 JSON对象和字符串转换 <script type"text/javascript">var jsonPerson {"name": "jack","age": 20}console.log(jsonPerson);var strPerson JSON.stringify(jsonPerson);//对jsonPerson没有影响console.lo…

文件系统 --- 软硬链接

序言 经过上一篇的学习 在磁盘中的文件&#xff0c;我们大致了解了磁盘的物理结构&#xff0c;逻辑抽象结构以及文件在磁盘上的存储方式。在这篇文章中&#xff0c;我们会基于上一篇文章的部分知识点来介绍软链接&#xff0c;硬链接。 1. 软链接 1.1 软链接的概念 软链接是一个…

vue3+vite+ts 颜色选择器组件支持颜色吸取,透明度

ciw-color-picker-vue&#xff1a; vue3 vite ts 颜色选择器,支持颜色吸取,透明度&#xff0c;与浏览器原生颜色选择器相似,与饿了么颜色选择器相似 使用了ciw-color-picker-vue npm i ciw-color-picker-vue 安装 npm i ciw-color-picker-vue 全局引入方式 main.ts 或 m…

光伏检测室外气象站的重要性

在光伏产业的快速发展中&#xff0c;光伏检测室外气象站的重要性日益凸显。它不仅是光伏电站运维管理的“眼睛”&#xff0c;更是确保电站高效、稳定运行的关键因素。 首先&#xff0c;光伏检测室外气象站能够实时、准确地监测多种关键气象要素&#xff0c;如太阳辐射、风速、风…

【中间件】Redis从入门到精通-黑马点评综合实战

文章目录 一&#xff1a;Redis基础1.Redis是什么2.初识Redis3.Redis的数据结构A.通用命令B.String类型C.Key的层级格式D.Hash类型E.List类型F.Set类型G.SortedSet类型 二&#xff1a;Redis的Java客户端1.JedisA.引入依赖B.建立连接C.测试JedisD.释放资源 2.Jedis连接池3.Spring…

MM 13 -采购- 退货

思维导图 说明 情形1 直接冲销物料凭证 102 情形2 返货部分交货 情形3 退货PR贷项凭证 情形1 适用于已收货未开票&#xff0c;或者发票还可冲销的当月&#xff0c;冲销物料凭证所有数量 情形2 适用于跟情形1 一样&#xff0c;只是可以修改退货数量 情形3 如果已经跨越…

html+css+js网页设计字节跳动11个页面带js 效果很多

htmlcssjs网页设计字节跳动11个页面带js 效果很多 ui还原度100% 网页作品代码简单&#xff0c;可使用任意HTML编辑软件&#xff08;如&#xff1a;Dreamweaver、HBuilder、Vscode 、Sublime 、Webstorm、Text 、Notepad 等任意html编辑软件进行运行及修改编辑等操作&#xff0…

笔试练习day3

目录 BC149 简写单词题目解析代码 dd爱框框题目解析解析代码方法一暴力解法方法二同向双指针(滑动窗口) 除2!题目解析解法模拟贪心堆 感谢各位大佬对我的支持,如果我的文章对你有用,欢迎点击以下链接 &#x1f412;&#x1f412;&#x1f412; 个人主页 &#x1f978;&#x1…

【网络安全】玲珑安全第四期

鉴于玲珑安全漏洞挖掘前三期课程取得的优异成绩和获得的强烈反响,我们决定启动玲珑安全第四期漏洞挖掘培训计划。 文章目录 往期学员收获基础学员报喜(部分)课程反馈第四期课程课程内容免费课程往期学员收获 第一期课程总结及学员收获:->点我查看第一期学员收获<- …

leetcode 图论专题——(dfs+bfs+并查集 回顾)

DFS、BFS 回顾&#xff08;C语言代码&#xff09; map[i][j]里记录的是i点和j点的连接关系 基本DFS&#xff1a; int vis[101],n,map[101][101]; void dfs(int t) {int i;vis[t]1;for(i0;i<n;i)//找对t点所有有关联的点——“找路”{if(vis[i]!0&&map[t][i]1)//有…

怎么将jar注册为windows系统服务详细操作

将spring boot项目编译成jar,注册为windows系统服务 在网上了解到,winsw这个开源项目,去github看了下,作者常年维护更新,文档齐全,拥有不少,自己写了个小demo体验了下还不错,然后又运行了一个晚上,没啥问题,遂决定采用它 开源地址 源库地址 https://github.com/winsw/winsw R…

string类简单的底层实现,了解string底层以及string的补充知识

string类的简单实现 头文件 #define _CRT_SECURE_NO_WARNINGS 1 #pragma once #include<iostream> #include<assert.h> using namespace std; namespace exprience {class string {public:typedef char* iterator;iterator begin(){return _str;}iterator end()…

IPython使用技巧详解:提高Python编程效率的利器

目录 一、IPython基础设置与启动 1.1 安装IPython 1.2 IPython的配置 二、IPython交互式编程体验 2.1 魔术命令(Magic Commands) 2.2 变量自动补全与文档查看 2.3 历史命令与快速访问 三、IPython高级功能 3.1 列表推导式与生成器表达式 3.2 枚举与压缩函数 3.3 L…

Java NIO(Non-blocking I/O)简单理解

Java NIO是Java平台中用于高效输入/输出&#xff08;I/O&#xff09;操作的一套新的API&#xff0c;与标准的Java I/O&#xff08;基于流的阻塞I/O&#xff09;不同&#xff0c;Java NIO提供了非阻塞式的I/O操作。 Java NIO 的核心组件 Java NIO主要由以下几个核心部分组成&a…

服务器网络不通排查方案

服务器网络不通排查方案 最近遇到了服务器上服务已经启动&#xff0c;但是在浏览器上无法访问的问题&#xff0c;记录一下排查流程 文章目录 服务器网络不通排查方案netstart排查网络连接信息netstat 命令netstat -aptn 命令 iptables总结 netstart排查网络连接信息 netstat …

【Linux进程篇】进程终章:POSIX信号量线程池线程安全的单例模式自旋锁读者写者问题

W...Y的主页 &#x1f60a; 代码仓库分享 &#x1f495; 前言&#xff1a;在之前的进程间通信时我们就讲到过信号量&#xff0c;他的本质就是一个计数器&#xff0c;用来描述临界资源的一个计数器。我们当时使用电影院的例子来说明信号量。电影院的座位被我们称为临界资源&a…

LVS集群实现四层负载均衡详解(以nat,dr模式为例)

目录 一、LVS集群的介绍 1、LVS 相关术语&#xff1a; 2、lvs工作原理 3、相关名词概念 4、lvs集群的类型 二、lvs的nat模式 1、介绍&#xff1a; 2、数据逻辑&#xff1a; 3、nat实验部署 环境搭建&#xff1a; 1、lvs中要去打开内核路由功能&#xff0c;实现网络互联…

关于区块链的公共医疗应用开发

区块链的养老保险平台应用开发 任务一:环境准备 1.编译区块链网络 目录:/root/xuperchain/ 在区块链网络目录下执行make命令,编译网络,编译成功后输出compile done! 启动区块链网络 2.创建钱包账户 创建普通钱包账户userTest,命令如下 bin/xchain-cli account newke…

6.2 Python 标准库简介:编程世界的百宝箱

欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;欢迎订阅相关专栏&#xff1a; 工&#x1f497;重&#x1f497;hao&#x1f497;&#xff1a;野老杂谈 ⭐️ 全网最全IT互联网公司面试宝典&#xff1a;收集整理全网各大IT互联网公司技术、项目、HR面试真题.…