elasticsearch7.16.2生产环境搭建

本文基于centos7进行搭建,集群为两个节点,数据目录位于/data

第一台机器配置

  1. 创建es用户和组
    后续使用es用户进行操作
groupadd es
useradd es -g es
# 设置es密码
passwd es
  1. 下载源码
cd /data
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.2-linux-x86_64.tar.gz
tar -xzf elasticsearch-7.16.2-linux-x86_64.tar.gz
  1. 创建数据目录esdata和日志目录logs


    目录结构
  2. 生成CA证书,放到config/certs目录
# 1. 生成CA证书 
bin/elasticsearch-certutil ca
# 2、使用CA证书生成p12秘钥
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
# 3. 移动上面生成的p12文件到config/certs
  1. 编辑config/elasticsearch.yml
cluster.name: "prodes-cluster"
node.name: node-001
path.data: /data/esdata
path.logs: /data/logs
#启动的时候锁定内存
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["10.128.63.110", "10.128.63.111"]
cluster.initial_master_nodes: ["node-001","node-002"]
#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: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12

6.jvm相关配置

cd config/jvm.options.d
vi jvm.options

修改日志路径

-XX:ErrorFile=/data/logs/hs_err_pid%p.log
8:-Xloggc:/data/logs/gc.log
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=/data/logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

堆内存官方推荐使用默认的。如果要自己设置,不要设置超过总内存的50%

By default, Elasticsearch automatically sets the JVM heap size based on a node’s roles and total memory. Using the default sizing is recommended for most production environments.

我这里的机器是16gb内存的,不设置堆大小,有自动分配了大概8gb的内存


es进程
  1. 系统参数修改
  • vm.max_map_count,虚拟内存,最少为262144
    es默认使用mmapfs目录存储索引
    设置mmap数量
grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
sysctl -w vm.max_map_count=262144

可通过命令sysctl vm.max_map_count验证

  • ulimit
sudo su  
ulimit -n 65535 
# /etc/security/limits.conf
# nofile文件描述符数(最少65536),nproc线程数(最少4096),
* hard nofile 65536
* soft nproc 204800
* hard nproc 204800
es soft memlock unlimited
es hard memlock unlimited
  • 禁用交换区
    可通过配置实现
bootstrap.memory_lock: true
  1. 启动es
bin/elasticsearch -d

如果需要停止,ps -ef,找出进程号,kill进程可停止节点

  1. 安全设置
  • 生成密码
./bin/elasticsearch-setup-passwords auto
  1. 可通过curl验证集群
curl --user kibana_system:密码 -XGET http://10.128.63.110:9200

第二台机器

将第一台的整个目录结构,生成的证书都复制过去

  1. 在config/elasticsearch.yml中,把node.name改为node-002
  2. 不需要重新生成CA证书

k8s部署kibana.yml

其中需要注意的是变量名的配置,有一定的规则
比如:i18n.locale-> I18N_LOCALE

---
apiVersion: v1
kind: Service
metadata:
  name: prodes-kibana
  namespace: es-prod
  labels:
    app: prodes-kibana
spec:
  type: NodePort
  ports:
    - port: 5601
      name: http
      targetPort: 5601
      nodePort: 30561
  selector:
    app: prodes-kibana
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: prodes-kibana
  namespace: es-prod
  labels:
    app: prodes-kibana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prodes-kibana
  template:
    metadata:
      name: prodes-kibana
      labels:
        app: prodes-kibana
    spec:
      containers:
        - name: prodes-kibana
          image: 'docker.elastic.co/kibana/kibana:7.16.2'
          ports:
            - containerPort: 5601
              protocol: TCP
          env:
            - name: ELASTICSEARCH_HOSTS
              value: '["http://10.128.63.114:9200","http://10.128.63.213:9200"]'
            - name: ELASTICSEARCH_USERNAME
              value: kibana_system
            - name: ELASTICSEARCH_PASSWORD
              value: #实际的密码
            - name: I18N_LOCALE
              value: zh-CN

你可能感兴趣的:(elasticsearch7.16.2生产环境搭建)