部署Elasticsearch
从开源网站获取Elasticsearch 8.10.1版本软件包,配置相关文件和SSL证书,创建Elasticsearch用户并启动Elasticsearch。
- 下载Elasticsearch 8.10.1版本。
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.1-linux-aarch64.tar.gz --no-check-certificate
- 将安装包上传到服务器,并解压。假设代码存放于“/path/to/”。
tar -zxvf elasticsearch-8.10.1-linux-aarch64.tar.gz
- 修改elasticsearch.yml配置文件。
- 进入配置文件的目录,打开elasticsearch.yml配置文件。
cd /path/to/elasticsearch-8.10.1/config vim elasticsearch.yml
- 按“i”进入编辑模式,添加以下配置信息。
cluster.initial_master_nodes: ["localhost"] node.name: localhost network.host: 0.0.0.0 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" discovery.seed_hosts: ["localhost"] xpack.security.enabled: false xpack.security.enrollment.enabled: false xpack.security.http.ssl: enabled: true keystore.path: certs/http.p12 xpack.security.transport.ssl: enabled: true verification_mode: certificate keystore.path: certs/elastic-certificates.p12 truststore.path: certs/elastic-certificates.p12
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 进入配置文件的目录,打开elasticsearch.yml配置文件。
- 配置SSL证书。
- 进入Elasticsearch安装目录。
cd /path/to/elasticsearch-8.10.1
- 执行以下命令。
./bin/elasticsearch-certutil http
- 按照下述指导进行配置。
Generate a CSR 选择 N Use an existing CA 选择 N Do you wish to change any of these options 选择 N For how long should your certificate be valid 填 5Y Generate a certificate per node 选择 N Enter all the hostnames that you need, one per line 填入具体的服务器IP地址 IP地址填入具体的服务器IP地址 不需要配置CA密码,直接按回车
- 创建certs文件夹。
mkdir /path/to/elasticsearch-8.10.1/config/certs
- 配置证书可得到elasticsearch-ssl-http.zip压缩包,解压后,在“elasticsearch”文件夹中得到http.p12证书,将证书复制到“/path/to/elasticsearch-8.10.1/config/certs”文件夹中。
unzip elasticsearch-ssl-http.zip cp ./elasticsearch/http.p12 /path/to/elasticsearch-8.10.1/config/certs
- 进入Elasticsearch安装目录。
- 开启认证x-pack_xpack.security.transport.ssl。
- 进入Elasticsearch安装目录下的“bin”目录。
cd /path/to/elasticsearch-8.10.1/bin
- 执行以下命令。
echo 'export PATH=/path/to/elasticsearch-8.10.1/bin:$PATH' >> ~/.bashrc source ~/.bashrc elasticsearch-certutil ca elasticsearch-certutil cert --ca elastic-stack-ca.p12
在出现Please enter the desired output file [elastic-certificates.p12]:后面输入下面的路径。/path/to/elasticsearch-8.10.1/config/certs/elastic-certificates.p12
- 进入Elasticsearch安装目录下的“bin”目录。
- 修改limits.conf配置。
- 打开limits.conf配置文件。
vim /etc/security/limits.conf
- 按“i”进入编辑模式,添加以下四行配置。
* soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 65536
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 打开limits.conf配置文件。
- 修改sysctl.conf配置。
- 打开sysctl.conf配置文件。
vim /etc/sysctl.conf
- 按“i”进入编辑模式,添加以下配置。
vm.max_map_count=655360
- 按“Esc”键,输入:wq!,按“Enter”保存并退出编辑。
- 执行以下命令。
sysctl -p
- 打开sysctl.conf配置文件。
- 新建Elasticsearch用户并赋权。
adduser elasticsearch passwd elasticsearch chown -R elasticsearch:elasticsearch /path/to/elasticsearch-8.10.1
- 切换到Elasticsearch用户。
su - elasticsearch
- 启动Elasticsearch。
- 进入Elasticsearch安装目录。
cd /path/to/elasticsearch-8.10.1
- 以绑16核的方式启动Elasticsearch。
numactl -C 0-15 -m 0 ./bin/elasticsearch -d
- 进入Elasticsearch安装目录。
父主题: 安装配置环境