Elasticsearch8.x 与 Kinaba8.x

1.准备工作

下载,创建用户

ES下载最新版本:
https://www.elastic.co/cn/downloads/elasticsearch

ES安装不能用root用户执行,必须创建一个es用户

su root
adduser elk
passed elk

给sudo权限

chmod -v u+w /etc/sudoers
# 新增一行
vim /etc/sudoers
root    ALL=(ALL)       ALL
elk  ALL=(ALL)       ALL  #这个是新增的用户

chmod -v u-w /etc/sudoers

 

2.安装elasticsearch8.3.3

su elk
mkdir -p /home/elk/elk

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.3-linux-x86_64.tar.gz

cd /home/elk/elk
tar -zxvf elasticsearch-8.3.3-linux-x86_64.tar.gz
cd /home/elk/elk/elasticsearch-8.3.3/config

#vim jvm.options
#这里创建了一个文件, 
cd config/jvm.options.d
touch jvm4g.options 
添加2行
-Xms4g
-Xmx4g

 

配置文件说明

https://www.cnblogs.com/xiaochina/p/6855591.html

修改配置文件elasticsearch.yml

cluster.name: es8
node.name: node-1
node.attr.rack: r1
path.data: /home/elk/elk/elasticsearch-8.3.3/data   #索引等存储
path.logs: /home/elk/elk/elasticsearch-8.3.3/logs   # 日志目录
network.host: 192.168.0.111
http.port: 9200
discovery.seed_hosts: ["192.168.0.111"]
cluster.initial_master_nodes: ["node-1"]


xpack.security.enabled: true         # 安全认证,如果无法启动可以暂时不开启,设置为false

xpack.security.enrollment.enabled: true

xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12

ingest.geoip.downloader.enabled: false

启动elasticsearch

cd ./elasticsearch-8.3.3/bin
./elasticsearch

#后台启动
cd /home/elk/elk/elasticsearch-6.3.1/bin nohup ./elasticsearch &

验证是否启动成功

http://192.168.0.111:9200/

 

其他注意事项

报错1

vim /etc/sysctl.conf
添加
vm.max_map_count=262144

保存后,执行:
sysctl -p

 

是否开启安全认证

# 安全认证
xpack.security.enabled: true
# 这个参数也必须同时为true
xpack.security.transport.ssl.enabled:true

 

重置账号密码

# 账号密码
elasticsearch.username: "kibana_system"           # 这个账号kibana认证需要用到,不然连不上。 elastic是超级账号,不能作为kibana认证账号
elasticsearch.password: "+FDasdfCbXXX_XXXX"

#token 重置(这个token配置到kibana无法启动?)
./elasticsearch-create-enrollment-token -s kibana --url "http://192.168.0.111:9200"
./elasticsearch-create-enrollment-token -s kibana

 

 

Kinaba8.3.3安装

还是用elk用户

su elk
cd /home/elk/elk

wget https://artifacts.elastic.co/downloads/kibana/kibana-8.3.3-linux-x86_64.tar.gz
tar -zxvf kibana/kibana-6.3.1-linux-x86_64.tar.gz

 

修改配置:

cd /home/elk/elk/kibana-6.3.1/config
vim kibana.yml

server.port: 5601


server.port: 5601
server.host: "192.168.0.111"
server.publicBaseUrl: "http://192.168.0.111:5601"
elasticsearch.hosts: ["http://192.168.0.111:9200"]
elasticsearch.username: "kibana_system"        #
elasticsearch.password: "+EzFe4i0CXXXXXXX_MTQ" # 有脚本重置

i18n.locale: "zh-CN"  # 控制台中文

 

启动:

cd /home/elk/elk/kibana-6.3.1/bin
nohup ./kibana &

 

PHPclient, elasticsearch-php

github:https://github.com/elastic/elasticsearch-php

 

composer增加配置,执行 composer update

"elasticsearch/elasticsearch": "~8.0"

使用

use Elastic\Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\Exception\ClientResponseException;
use Elastic\Elasticsearch\Exception\ServerResponseException;


$client = ClientBuilder::create()
            ->setHosts(['192.168.0.111:9200'])
            ->build();
        // Info API
        $response = $client->info();
//      echo $response['version']['number']; // 8.0.0
        print_r($response->asArray());

        echo $response->getStatusCode(); // 200
        echo (string) $response->getBody(); // Response body in JSON
        exit;

 

创建索引

$params = [
   'id' => 'weekend_'.$id,
   'index' => '周末遛娃',
   'body'  => [ 'content' => "今天天气不错,适合出去玩!", 'ctime' => date('Y-m-d H:i:s'), 'views' => 103 ]
];

$response = $client->index($params);

查询

$pagesize  = 10;
$offset    = ($page-1)*$pagesize;

$params = [
    'index' =>  '周末遛娃',
    'body'  => [
        'from' => $offset, // Starting offset (default: 0)
        'size' => $pagesize, // Number of hits to return (default: 10)
        'query' => [
            'match' => [
                'content' => $words
            ]
        ]
    ]
];

$response = $client->search($params);

$response = $client->delete([
   'index' => '周末遛娃',
   'id' => 'Xas23xd',
]);

更新

$params = [
  'index' => '周末遛娃',
  'id' => 'weekend_122',
  'body' => [
    'doc' => [
        'views' => 133
    ]
  ]
];

$response = $client->update($params );

 

 

标记

https://www.cnblogs.com/dduo/p/14871203.html

https://www.cnblogs.com/jpfss/p/10757264.html

https://blog.csdn.net/ztx114/article/details/125601336

https://blog.csdn.net/wsyzxss/article/details/121280361