Modify by lyc at 2020-3-24
博文参考:
elastci中文官网
Elasticsearch7集群搭建
1.服务器基础配置
IP |
角色 |
配置 |
系统 |
192.168.100.161 |
elasticsearch-node-01 |
8C/16G/500G |
CentOS7 |
192.168.100.162 |
elasticsearch-node-02 |
8C/16G/500G |
CentOS7 |
192.168.100.163 |
elasticsearch-node-03 |
8C/16G/500G |
CentOS7 |
配置hosts
1 2 3 4
| $ vim /etc/hosts 192.168.100.161 elasticsearch-node-01 192.168.100.162 elasticsearch-node-02 192.168.100.163 elasticsearch-node-03
|
系统优化
1 2 3 4 5 6 7 8
| $ vim /etc/security/limits.conf * hard nofile 102400 * soft nofile 102400 * soft nproc 102400 * hard nproc 102400
elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited
|
内核参数优化
1 2 3
| $ vim /etc/sysctl.conf vm.swappiness = 1 vm.max_map_count = 655360
|
2.elasticsearch 安装
下载安装
- elasticsearch 7以上版本会自带jdk12的安装包,所以不需要另外安装jdk
- elasticsearch 7以下版本需要另外安装jdk
1 2 3 4 5 6 7 8 9 10
| $ cd /usr/local/src $ wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-x86_64.rpm $ yum localinstall -y elasticsearch-7.5.1-x86_64.rpm
$ mkdir -pv /data/backup/elasticsearch_backup $ mkdir -pv /data/elasticsearch/{elasticsearch_data,elasticsearch_logs} $ chown elasticsearch:elasticsearch /data/backup/elasticsearch_backup $ chown -R elasticsearch:elasticsearch /data/elasticsearch
|
elasticsearch相关文件句柄修改
1 2 3 4 5 6
| $ mkdir -p /etc/systemd/system/elasticsearch.service.d $ vim /etc/systemd/system/elasticsearch.service.d/override.conf [Service] DefaultLimitNOFILE=65536 DefaultLimitNPROC=32000 LimitMEMLOCK=infinity
|
开机自启动
1 2
| $ systemctl daemon-reload $ systemctl enable elasticsearch.service
|
3.配置文件
/etc/elasticsearch/elasticsearch.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| $ vim elasticsearch.yml
cluster.name: inner-es-cluster
node.name: node-100161
path.data: /data/elasticsearch/elasticsearch_data path.logs: /data/elasticsearch/elasticsearch_logs path.repo: ["/data/backup/elasticsearch_backup"]
bootstrap.memory_lock: true
network.host: 192.168.100.161 http.port: 9200 transport.tcp.port: 9300
cluster.initial_master_nodes: ["elasticsearch-node-01", "elasticsearch-node-02", "elasticsearch-node-03"]
discovery.seed_hosts: ["elasticsearch-node-01", "elasticsearch-node-02", "elasticsearch-node-03"] cluster.no_master_block: write
gateway.recover_after_nodes: 2
action.destructive_requires_name: true http.cors.enabled: true http.cors.allow-origin: "*"
|
/etc/elasticsearch/jvm.options
分配服务器一半的内存给JVM
1 2 3 4
| $ vim jvm.options .... -Xms8g -Xmx8g
|
4.验证
pretty
参数标识响应以json格式输出
$domain
修改成负载均衡的域名
如有对es集群配置密码,$password
改成密码
1 2 3 4 5 6 7 8 9 10 11
| $ curl 192.168.100.161:9200
$ curl -XGET -u elastic:$password 'http://$domain/_cat/nodes?pretty'
$ curl -i -XGET -u elastic:$password 'http://$domain/_cluster/health?pretty'
$ curl -XGET -u elastic:$password 'http://$domain/_cat/indices?v'
|
5.使用nginx负载均衡配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| $ cat $domain.conf upstream es_load_balancer { server 192.168.100.161:9200 max_fails=2 fail_timeout=5s; server 192.168.100.162:9200 max_fails=2 fail_timeout=5s; server 192.168.100.163:9200 max_fails=2 fail_timeout=5s; keepalive 60; }
server { listen 80; server_name $domain;
client_max_body_size 100m; client_body_buffer_size 256k;
location / { proxy_pass http://es_load_balancer; proxy_redirect off;
proxy_http_version 1.1; proxy_set_header Connection "Keep-Alive"; proxy_set_header Proxy-Connection "Keep-Alive"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host;
proxy_connect_timeout 90; proxy_read_timeout 90; proxy_send_timeout 90;
proxy_buffer_size 128k; proxy_buffers 32 32k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 128k; } error_log /data/httplogs/$domain-error.log; access_log off; }
|