Elasticsearch(后面简称ES)是一个分布式、高扩展、高实时的搜索与数据分析引擎,基于Lucene搜索服务器,它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口
1.非root账号
也许是处于安全考虑,ElasticSearch默认是禁止使用root启动的,所以我们这里新建一个账户来管理ES
useradd -m elastic
echo elastic:12345 | chpasswd
顺便给它设置免密sudo
echo "elastic ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/elastic
chomd 0440 /etc/sudoers.d/elastic
2.安装软件
下载解压
mkdir /data/softs/
cd /data/softs/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar. gz
mkdir /data/server/ -p
tar -xf elasticsearch-7.3.2-linux-x86_64.tar.gz -C /data/server/
cd /data/server/
ln -s elasticsearch-7.3.2/ elasticsearch
配置环境变量
新建 /etc/profile.d/elastic.sh,输入以下代码export ELASTIC_HOME=/data/server/elasticsearch
export PATH=$ELASTIC_HOME/bin:$PATH
使生效
su elastic
source /etc/profile.d/elastic.sh
chmod +x /etc/profile.d/elastic.sh
3.配置ES
打开ES解压包里的配置文件进行如下配置
vim elasticsearch/config/elasticsearch.yml
cluster.name: elastic.mysite.com
node.name: master.mysite.com
node.master: true
node.data: true
path.data: /data/server/elasticsearch/data
path.logs: /data/server/elasticsearch/logs
network.host: 192.168.203.151
http.port: 9200
discovery.seed_hosts: ["master.mysite.com","node.mysite.com"]
cluster.initial_master_nodes: ["master.mysite.com"]
http.cors.enabled: true
http.cors.allow-origin: "*"
以上的主服务器的配置, 从服务器 的其他配置一样,但节点不能跟主服务器一样
node.name: node.mysite.com
node.master: false
network.host: 192.168.203.152
其他配置
echo 'vm.max_map_count=262144' > /etc/sysctl.d/elastic.conf
sysctl -p /etc/sysctl.d/elastic.conf
echo 'elastic - nofile 65536' > /etc/security/limits.d/elastic.conf
mkdir /data/server/elasticsearch/{data,logs} -p
chown -R elastic:elastic /data/server/elasticsearch
chown -R elastic:elastic /data/server/elasticsearch-7.3.2/
4.启动ES
我们使用elastic账户启动
elasticsearch
或
elasticsearch -d
查看是否启动
netstat -tnulp | grep 9200 curl 192.168.203.151:9200
5.简单操作
5.1 查看状态和节点
curl 192.168.203.151:9200/_cat/health?v
curl 192.168.203.151:9200/_cat/nodes
5.2 索引操作(创建、查看、删除)
创建和查看索引
curl -XPUT 192.168.203.151:9200/index_test
curl 192.168.203.151:9200/_cat/indices
curl 192.168.203.151:9200/index_test?pretty
删除索引
curl -XDELETE 192.168.203.151:9200/index_test
curl 192.168.203.151:9200/_cat/indices
配置切片属性
curl -X PUT 192.168.203.151:9200/index_test -H 'Content-Type:application/json' -d '{"settings": {"number_of_shards": 3,"number_of_replicas": 1}}'
curl 192.168.203.151:9200/_cat/indices
curl 192.168.203.151:9200/index_test?pretty