### 下载地址及基本配置
#下载地址wget https://artifacts.elastic.co/downloads
#此版本选择:elasticsearch-7.17.7-linux-x86_64.tar.gz
#关闭 selinux、开放防火墙端口
#部署 java 运行环境(Java11及以上)
#修改/etc/hosts配置文件
vim /etc/hosts
192.168.73.112 node1
#创建 elastic普通用户 (root用户不能启动)
useradd esuser
#解压缩及配置文件
tar -xvf elasticsearch-7.17.7-linux-x86_64.tar.gz -C /usr/local/
#创建数据目录
mkdir -p /usr/local/elasticsearch/data/
mkdir -p /usr/local/elasticsearch/logs/
chown -R esuser:esuser /usr/local/elasticsearch/data/
chown -R esuser:esuser /usr/local/elasticsearch/logs/
chown -R esuser:esuser /usr/local/elasticsearch-7.17.7/
#修改系统参数修改:
vim /etc/sysctl.conf
vm.max_map_count=262144
#执行sysctl -p生效
vim /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
esuser soft nproc 4096
esuser hard nproc 4096
vim /etc/security/limits.d/20-nproc.conf
* soft nproc 4096
root soft nproc unlimited
---------------------------------------------------------------------------
#修改elasticsearch.yml配置文件
vim /usr/local/elasticsearch-7.17.7/config/elasticsearch.yml
#集群名称
cluster.name: aubin-cluster
#节点名称
node.name: node1
#指定该节点是否有资格被选举成为master节点,默认是true,
node.master: true
#允许该节点存储数据(默认开启)
node.data: true
#数据的默认存放路径
path.data: /usr/local/elasticsearch/data/
#日志的默认存放路径
path.logs: /usr/local/elasticsearch/logs/
#bind IP地址
network.host: 192.168.73.112
#服务端口
http.port: 9200
ingest.geoip.downloader.enabled: false
#集群模式开启一下配置
#集群列表
#discovery.seed_hosts: ["192.168.73.112", "192.168.91.5", "192.168.91.6"]
#启动的时候使用一个master节点
#cluster.initial_master_nodes: ["node1"]
#非集群模式
discovery.type: single-node
#配置ca认证策略则开启此配置:
#xpack的配置
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
#xpack.security.transport.ssl.verification_mode: certificate
#xpack.security.transport.ssl.client_authentication: required
#xpack.security.transport.ssl.keystore.path: /web/soft/elasticsearch-7.17.7/config/elastic-certificates.p12
#xpack.security.transport.ssl.truststore.path: /web/soft/elasticsearch-7.17.7/config/elastic-certificates.p12
---------------------------------------------------------------------------
#修改jvm.options文件(服务器内存的一半)
#注意前边不能有空格
-Xms512m
-Xmx512m
#指定jdk环境变量
vim /usr/local/elasticsearch-7.17.7/bin/elasticsearch-env
ES_CLASSPATH=,在此配置后边加入一下参数:
#USE ELASTICSEARCH JDK
ES_JAVA_HOME="/usr/local/elasticsearch-7.17.7/jdk/"
#启动命令及查看启动是否正常
#这里又执行了一下更改数组数组操作,防止启动因为权限出现问题
chown -R esuser:esuser /usr/local/elasticsearch/data/
chown -R esuser:esuser /usr/local/elasticsearch/logs/
chown -R esuser:esuser /usr/local/elasticsearch-7.17.7/
#二进制直接启动命令:注意不可以是root用户 ,-d表示放在后台
/usr/local/elasticsearch-7.17.7/bin/elasticsearch -d
---------------------------------------------------------------------------
#systemd 启动
#创建文件vim /usr/lib/systemd/system/elasticsearch.service,内容如下
[Unit]
Description=ElasticSearch
Requires=network.service
After=network.service
[Service]
User=esuser
Group=esuser
LimitNOFILE=65536
LimitMEMLOCK=infinity
Environment=JAVA_HOME=/usr/local/elasticsearch-7.17.7/jdk/
ExecStart=/usr/local/elasticsearch-7.17.7/bin/elasticsearch
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
---------------------------------------------------------------------------
#启动命令
systemctl daemon-reload
systemctl start elasticsearch
#停止命令
systemctl stop elasticsearch
#或者
ps -ef | grep elasticsearch
kill 进程号
#查看单节点是否正常
curl http://192.168.73.112:9200/_cat/nodes?pretty
#查看集群是否正常
#curl http://192.168.73.112:9200/_cluster/health?pretty
配置CA认证:首先修改配置文件把需要的配置注释打开
一、生成证书:我们这里设置了密码,后边需要做更新keystore两步操作
输入./bin/elasticsearch-certutil ca
碰到第一个直接回车,不用管
碰到第二个输入密码,例如123456
完成后会生成一个文件:elastic-stack-ca.p12
#生成密钥:
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
#第一次输入密码回车后,在回车,然后再输入密码,会生成一个elastic-certificates.p12文件
mv elastic-certificates.p12 /usr/local/elasticsearch-7.17.7/config/
#复制到另外两台机器上:
#scp root@192.168.73.110:/usr/local/elasticsearch-7.17.7/config/elastic-certificates.p12 /usr/local/elasticsearch-7.17.7/config/
#如果生成CA期间设置了密码,需要更新keystore
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
#重启服务
#设置密码:
./bin/elasticsearch-setup-passwords interactive
# 下面会要输入很多密码,都要自己能记住,以后要用
# 需要设置 elastic,apm_system,kibana,kibana_system,logstash_system,beats_system
#linux终端curl测试:
[esuser@node1 elasticsearch-7.17.7]$
curl -u elastic:123456 "http://192.168.73.112:9200/_cat/nodes?pretty"
192.168.73.112 17 95 0 0.02 0.07 0.26 cdfhilmrstw * node1
curl -XGET --user elastic:Wnit2019! http://127.0.0.1:9200
#隐藏密码curl测试:
[esuser@node1 ~]$ vim ~/.netrc 此文件需要在用户家目录而且是隐藏文件
machine 192.168.73.112
login elastic
password 123456
[esuser@node1 ~]$ curl --netrc http://192.168.73.112:9200/_cat/nodes?pretty
192.168.73.112 47 96 1 0.10 0.06 0.11 cdfhilmrstw * node1
以下是systemd配置的解释: