elasticsearch单节点部署-ubuntu

单节点无认证es搭建

1. 部署jdk,不建议使用openjdk

下载jdk1.8.0_102.tgz文件
官方下载地址:https://www.oracle.com/cn/java/technologies/javase/javase-jdk8-downloads.html
创建java家目录
mkdir -p /App/java/
tar -zxvf jdk1.8.0_102.tgz -C /App/java


#set for java
export JAVA_HOME=/App/java/jdk1.8.0_102
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

source /etc/profile

2. 下载并安装es,本次使用deb包进行部署

下载:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.0-amd64.deb
安装并启动
dpkg -i elasticsearch-7.5.0-amd64.deb
systemctl enable elasticsearch.service
systemctl start elasticsearch.service

3. 优化es配置文件

jvm优化:
vi /etc/elasticsearch/jvm.options
#根据服务器配置堆内存大小,最大配置到32G
-Xms4g
-Xmx4g


配置文件优化:
vi /etc/elasticsearch/elasticsearch.yml
#集群名称
cluster.name: es-cluster

#节点名称
node.name: es-master-1

#是否是master节点,master节点存元数据
node.master: true
#是否是data数据节点,data数据节点存数据
node.data: true
#是否是ingest节点,ingest节点可以在数据真正进入index前,通过配置pipline拦截器对数据ETL
node.ingest: false

#数据目录,可挂载多个盘
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs

#http host和port
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
#设置是否压缩tcp上交互传输的数据
transport.tcp.compress: true
#bootstrap.memory_lock: true

#设置集群中的Master节点的初始列表,可以通过这些节点来自动发现其他新加入集群的节点
discovery.zen.ping.unicast.hosts: [es-master-1]

#指定集群初始节点
cluster.initial_master_nodes: es-master-1

#防止脑裂配置,注意在多master时,这个值应该等于 Math.floor(master候选节点数/2)+1,#意思是master候选节点的数目最少达到多少个,才去选举master
discovery.zen.minimum_master_nodes: 2

# 设置跨域问题,方便使用elasticsearch-head来检测集群状态
http.cors.enabled: true
http.cors.allow-origin: /.*/

#xpack.license.self_generated.type: basic
xpack.watcher.enabled: true
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: true

 

4. 重新启动es

ystemctl restart elasticsearch
查看端口是否启动
netstat -nptl|grep 9200

以上单节点不带认证的ES搭建完毕
 

 

 

单节点启用认证es搭建

1. 完成上述配置以后只需要调整配置文件即可启用认证

修改配置文件启用认证
vi /etc/elasticsearch/elasticsearch.yml
xpack.license.self_generated.type: basic
xpack.watcher.enabled: true
xpack.security.enabled: true      #表示启用认证
xpack.security.transport.ssl.enabled: true

2. 创建用户名和密码

执行创建命令,会创建elastic, kibana, logstash_system,beats_system四个用户
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

3. 修改上述创建的用户名和密码

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

 

 

三、es常用命令

1.创建test-es索引
curl -XPUT 127.0.0.1:9200/test-es?pretty                        #不带用户名密码
curl http://127.0.0.1:9200/test-es?pretty  -u elk:gakFg1a       #带用户名密码
或
curl http://elastic:[email protected]:9200/test-es?pretty       #带用户名密码

2.查看所有索引信息
curl -X GET 'http://127.0.0.1:9200/_cat/indices?v'

3.查看集群分片数量,健康状态
curl http://127.0.0.1:9200/_cat/health?v

4.查看是否有主机坏掉
curl http://127.0.0.1:9200/_cat/nodes?v

5.创建索引的时候指定分片和副本
curl -XPUT '127.0.0.1:9200/index2?pretty' -H 'content-Type:application/json' -d '
{
       "settings" : {
       "number_of_shards" : 2,
       "number_of_replicas" : 2
 }
}'
索引创建后不可以更改分片数量,但是可以更改副本数

6.调整索引的副本数量 
curl -XPUT '127.0.0.1:9200/test-es/_settings?pretty'  -H 'content-Type:application/json' -d  '{
    "settings": {
       "number_of_replicas": "1"
    }
}'

 

你可能感兴趣的:(ELK全套,elasticsearch,es)