安装 elasticsearch
1、安装
# vim instll-es.sh
mkdir /opt/es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz -P /opt/es cd /opt/es
tar xf elasticsearch-7.9.2-linux-x86_64.tar.gz ln -s /opt/es/elasticsearch-7.9.2 /opt/es/elasticsearch
2、系统优化
# echo "* soft nofile 65535 * hard nofile 65535 * soft nproc 65535 * hard nproc 65535" >> /etc/security/limits.conf
# echo "vm.max_map_count=655360" >>/etc/sysctl.conf
# sysctl -p
# vim /etc/profile
export JAVA_HOME=/opt/es/elasticsearch/jdk
export ES_HOME=/opt/es/elasticsearch
export PATH=$ES_HOME/bin:$ES_HOME/jdk/bin:$PATH
# source /etc/profile
3、启动
# useradd es # chown -R es /opt/es/elasticsearch # su - es $ /opt/es/elasticsearch/bin/elasticsearch -d
4、rpm安装
# yum instll https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.3-x86_64.rpm
5、elasticsearch配置密码
1、修改配置文件
# vim elasticsearch.yml
node.name: node-1
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]
http.port: 9200
transport.tcp.port: 9300 http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization xpack.security.enabled: true xpack.security.transport.ssl.enabled: true 2、配置密码 # elasticsearch-setup-passwords interactive 3、修改密码 # curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }' 4、验证 # curl -XGET --user elastic:123456 'http://127.0.0.1:9200'
6、配置文件解析
cluster.name: gwrmt #集群名,唯一 node.name: gwrmt02-console #节点名,唯一 node.master: true #是否是主节点 node.data: true #是否存储数据 path.data: /mnt/data/es/data #数据路径,可多个,逗号分隔 path.logs: /mnt/data/logs/es/log #日志路径 bootstrap.memory_lock: false #锁内存,是否用swap bootstrap.system_call_filter: false #是否使用系统调用seccomp network.host: 192.168.1.36 #绑定ip http.port: 9200 #端口 transport.port: 9300 #集群通信端口
discovery.seed_hosts: ["192.168.1.38","192.168.1.36"] #集群节点列表,ip+端口,不写默认9300 cluster.initial_master_nodes: ["192.168.1.38","192.168.1.36"] #启动服务并初始化,选举主节点列表 xpack.security.enabled: true #开启xpack认证 xpack.license.self_generated.type: basic #启用基本xpack功能的许可证 xpack.security.transport.ssl.enabled: true #开启集群内,ssl安全认证 xpack.security.transport.ssl.verification_mode: certificate #ssl证书模式 xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 #ca证书路径 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12 #ca密钥路径 http.cors.enabled: true #开启跨域 http.cors.allow-origin: "*" #支持所有域名 http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type #允许跨域的头部信息
7、依赖
##升级glibc # wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz # tar -xvf glibc-2.17.tar.gz # cd glibc-2.17 # mkdir build; cd build # ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin # make -j 8 # make install
8、docker安装
"registry-mirrors": ["https://rjaaoail.mirror.aliyuncs.com"]
1)编写dockerfile
FROM docker.io/elasticsearch:7.16.1 LABEL description="2022-11" ADD elasticsearch.yml config/elasticsearch.yml COPY Shanghai /etc/localtime RUN echo 'Asia/Shanghai' > /etc/timezone
2)构建镜像并启动
# docker build -t es:v1 -f /opt/es/Dockerfile # docker run -d --name 'es' -p 19200:9200 -p 19300:9300 es:v1
3)设置密码
# docker exec -it 26c bash @26c elasticsearch-setup-passwords interactive # curl -XGET --user elastic:123456 'http://127.0.0.1:19200'
9、插件安装
1)在线安装 # elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip 2)离线安装 # cd plugins # mkdir ik && cd ik # wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip # unzip elasticsearch-analysis-ik-7.12.1.zip # mv elasticsearch-analysis-ik-7.12.1.zip /opt/es/ 3)其他 # elasticsearch-plugin list # elasticsearch-plugin remove
需要重启服务才生效
QQ:328864113 微信:wuhg2008