Skip to content

Commit b286594

Browse files
committed
🚧 Elasticsearch
1 parent 70f7640 commit b286594

1 file changed

Lines changed: 76 additions & 8 deletions

File tree

markdown-file/Elasticsearch-Base.md

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ services:
2424

2525
-------------------------------------------------------------------
2626

27-
## 环境
2827

29-
- CentOS 7.3
28+
## Elasticsearch 6.5.x 安装(适配与 5.5.x)
29+
30+
#### 环境
31+
32+
- CentOS 7.x
33+
- 至少需要 2G 内存
3034
- root 用户
3135
- JDK 版本:1.8(最低要求),主推:JDK 1.8.0_121 以上
3236
- 关闭 firewall
3337
- `systemctl stop firewalld.service` #停止firewall
3438
- `systemctl disable firewalld.service` #禁止firewall开机启动
3539

36-
## Elasticsearch 6.5.x 安装(适配与 5.5.x)
37-
38-
### 先配置部分系统变量
40+
#### 先配置部分系统变量
3941

4042
- 更多系统层面的配置可以看官网:<https://www.elastic.co/guide/en/elasticsearch/reference/current/system-config.html>
4143
- 配置系统最大打开文件描述符数:`vim /etc/sysctl.conf`
@@ -54,7 +56,7 @@ elasticsearch hard memlock unlimited
5456
* hard nofile 262144
5557
```
5658

57-
### 开始安装
59+
#### 开始安装
5860

5961
- 官网 RPM 安装流程(重要,以下资料都是对官网的总结):<https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html>
6062
- 导入 KEY:`rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch`
@@ -72,17 +74,20 @@ autorefresh=1
7274
type=rpm-md
7375
```
7476

75-
- 开始安装:`yum install -y elasticsearch`,国内网络安装会很慢,慢慢等
77+
- 开始安装:`yum install -y elasticsearch`,预计文件有 108M 左右,国内网络安装可能会很慢,慢慢等
78+
- 安装完后会多了一个:elasticsearch 用户和组
79+
- 设置 java 软链接:`ln -s /usr/local/jdk1.8.0_181/jre/bin/java /usr/local/sbin/java`
7680
- 启动和停止软件(默认是不启动的):
7781
- 启动:`systemctl start elasticsearch.service`
7882
- 状态:`systemctl status elasticsearch.service`
7983
- 停止:`systemctl stop elasticsearch.service`
84+
- 重新启动:`systemctl restart elasticsearch.service`
8085
- 安装完成后,增加系统自启动:
8186
- `/bin/systemctl daemon-reload`
8287
- `/bin/systemctl enable elasticsearch.service`
8388
- 检查:`curl -X GET "localhost:9200/"`
8489

85-
### RPM 安装后的一些配置位置说明
90+
#### RPM 安装后的一些配置位置说明
8691

8792
- 更多说明可以看官网:<https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html#rpm-configuring>
8893
- 更加详细的配置可以看:<https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html>
@@ -95,6 +100,69 @@ type=rpm-md
95100
- 插件位置:`/usr/share/elasticsearch/plugins`
96101
- 脚本文件位置:`/etc/elasticsearch/scripts`
97102

103+
#### 配置
104+
105+
- 编辑配置文件:`vim /etc/elasticsearch/elasticsearch.yml`
106+
- 默认只能 localhost 访问,修改成支持外网访问
107+
108+
```
109+
打开这个注释:#network.host: 192.168.0.1
110+
改为:network.host: 0.0.0.0
111+
```
112+
113+
#### 安装 X-Pack(6.5.x 默认带了 x-pack)
114+
115+
- `cd /usr/share/elasticsearch && bin/elasticsearch-plugin install x-pack`
116+
117+
#### 安装 Chrome 扩展的 Head
118+
119+
- 下载地址:<https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm/>
120+
121+
#### 其他细节
122+
123+
- 如果就单个节点测试,新建索引的时候副本数记得填 0。
124+
125+
#### 批量增加 / 删除测试数据
126+
127+
- 官网文档:<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html>
128+
- 批量增加,接口地址:`POST /_bulk`
129+
130+
```
131+
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100001" } }
132+
{ "post_date" : "2018-12-01 10:00:00", "request_num" : 1 }
133+
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100002" } }
134+
{ "post_date" : "2018-12-01 10:00:05", "request_num" : 2 }
135+
```
136+
137+
- cURL 格式:
138+
139+
```
140+
curl -X POST "http://127.0.0.1:9200/_bulk" -H 'Content-Type: application/json' -d'
141+
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100001" } }
142+
{ "post_date" : "2018-12-01 10:00:00", "request_num" : 1 }
143+
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100002" } }
144+
{ "post_date" : "2018-12-01 10:00:05", "request_num" : 2 }
145+
'
146+
```
147+
148+
- 批量删除,接口地址:`POST /_bulk`
149+
150+
```
151+
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100001" } }
152+
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100002" } }
153+
```
154+
155+
- cURL 格式:
156+
157+
```
158+
curl -X POST "http://127.0.0.1:9200/_bulk" -H 'Content-Type: application/json' -d'
159+
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100001" } }
160+
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100002" } }
161+
'
162+
```
163+
164+
165+
98166

99167
-------------------------------------------------------------------------------------------------------------------
100168

0 commit comments

Comments
 (0)