yum安装Elasticsearch7

mtain 2022年06月07日 211次浏览

单节点搭建

1. 添加elasticsearch软件源

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md




2. 安装配置

# 安装
yum install --enablerepo=elasticsearch elasticsearch

# 配置
vim /etc/elasticsearch/elasticsearch.yml

cluster.name: es
node.name: node-1
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/log
network.host: xxx.xxx.xxx.xxx
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

# 创建目录
mkdir /data
chmod 777 /data


# 配置
vi + /etc/security/limits.conf
添加
elasticsearch hard nofile 65536
elasticsearch soft nofile 65536

改完重新登陆用户

错误解决

journalctl -xe
tail -f /data/elasticsearch/elasticsearch.log

3. 启动

# 启动
systemctl start elasticsearch
systemctl enable elasticsearch

# 验证启动
lsof -i:9200

# 访问
https://xxx.xxx.xxx.xxx:9200

systemctl stop elasticsearch
rm -rf /data/elasticsearch/*

systemctl start elasticsearch

4. 集群配置

集群间证书生成

主节点生成证书
# 1. 生成elastic-stack-ca.p12
/usr/share/elasticsearch/bin/elasticsearch-certutil ca

# 2. 生成elastic-certificates.p12
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca  /usr/share/elasticsearch/elastic-stack-c
a.p12

# 3. 将elastic-stack-certificates.p12传到其它节点
/etc/elasticsearch/elastic-certificates.p12

chown root:elasticsearch /etc/elasticsearch/elastic-certificates.p12

添加认证配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
http.cors.allow-credentials: true
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12

所有主机添加

vim /etc/elasticsearch/elasticsearch.yml

node.master: true
node.data: true
node.max_local_storage_nodes: 3

transport.tcp.port: 9300
discovery.seed_hosts: ["192.168.1.101:9300", "192.168.1.102:9300", "192.168.1.103:9300"]
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]


5. 配置密码

所有主机添加

vim + /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
http.cors.allow-credentials: true
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

设置密码

/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive