<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title><![CDATA[Chenxi]]></title> 
<atom:link href="http://chenxitag.com/rss.php" rel="self" type="application/rss+xml" />
<description><![CDATA[博客学习网站]]></description>
<link>http://chenxitag.com/</link>
<language>zh-cn</language>
<generator>www.emlog.net</generator>
<item>
    <title>Elasticsearch框架基础概念</title>
    <link>http://chenxitag.com/?post=33</link>
    <description><![CDATA[<p>Elasticsearch（ES）是一个基于Lucene构建开源分布式搜索引擎并提供Restful接口。</p>
<p>Es是一个分布式文档数据库（JSON数据格式存储，类似MongoDB），JSON中的每个字段数据都可作为搜索条件，并且能够扩展至数以百计的服务器存储以及处理PB（PetaByte）级的数据。可在短时间内存储、搜索和分析大量的数据。</p>
<p>PB级级别： 拍字节（Petabytes），计算机存储容量单位，也常用PB来表示。1PB=1024TB==2^50字节。<br />
Es优势：<br />
横向可扩展性：<br />
          只需增加服务器，修改配置后启动Es就可并入集群<br />
分片机制提供更好的分布性：<br />
          同一个索引分成多个分片（sharding），这点类似于HDFS的块机智，分别治理可提升处理效率<br />
高可用：<br />
          提供复制（replica）机制，一个分片可以设置多个复制，使得某台服务器在宏碁的情况下，集群仍旧可以照常运行，并会把服务器宏碁丢失的数据信息复制恢复到其他可用节点上<br />
Elasticsearch应用场景：<br />
大型分布式日志分析系统ELK（elasticsearch（存储日志）+ logstash（收集日志）+ kibana（展示数据））。<br />
Es存储结构：</p>
<p>Es是文件存储，面向文档型数据库，类似于MongoDB，用JSON作为文档序列化的格式</p>
<p>Es与数据库区别：</p>
<p>关系数据库 =&gt; 数据库(Database) =&gt; 表(Table) =&gt; 行(Row) =&gt; 列(columns) Elasticsearch=&gt; 索引(index) =&gt; 类型(Type) =&gt; 文档 (Documents) =&gt; 字段(Fields)  </p>
<h1>注意：从ES 7.0.0开始，移除Type（类型）这个概念，Type 字段那里变为固定值 _doc Elasticsearch=&gt; 索引(index) =&gt; _doc =&gt; 文档 (Documents) =&gt; 字段(Fields)</h1>
<p>Es版本控制：</p>
<p>1.为什么要进行版本控制<br />
为了保证数据在多线程操作下的准确性<br />
2.内部版本控制和外部版本控制<br />
内部版本控制： _version自增长，修改数据后，_version会自动+1<br />
外部版本控制：为了保持_version与外部版本控制的数值一致，使用version_type=external检查数据当前的version值是否小于请求中的version值<br />
3.悲观锁和乐观锁<br />
悲观锁：每次获取据时都会上锁，会造成线程阻塞<br />
底层实现：开启事务，启用锁机制<br />
乐观锁：更新数据时候会判断在此期间是否有人更新过。<br />
底层实现：1.使用版本号 2.使用时间戳<br />
9200和9300端口的区别：<br />
9200端口： ES节点和外部通讯使用，暴露ES Restful接口端口号<br />
9300端口： ES节点之间通讯使用，TCP协议、ES集群之间通讯端口号<br />
倒排索引：<br />
    把文档ID对应到关键词的映射转换为关键词到文档ID的映射，每个关键词都对应着一系列的文档，这些文档中都出现这个关键词。根据关键词查找文档ID迅速找出相关文档<br />
ES如何解决高并发：<br />
ES是一个分布式全文检索框架，隐藏了复杂的处理机制，内部使用分片机制、集群发现、分片负载均衡请求路由<br />
Shards分片：代表索引分片，ES可以把一个完整的索引分成多个分片，好处是可以把一个大的索引拆分成多个，分布到不同节点上。构成分布式搜索。分片的数量只能在索引创建前指定，并且索引创建后不能更改。<br />
Replicas副本：代表索引副本，ES可以设置多个索引的副本。<br />
副本的作用：<br />
1.提高系统的容错性，某个节点某个分片损坏或丢失时，可以从副本中恢复<br />
2.提高ES查询效率，ES会自动对搜索请求进行负载均衡<br />
ES集群核心原理分析：<br />
          1.每个索引会被分成多个分片shards进行存储，默认创建索引是分配5个分片进行存储，每个分片都会分布式在不同的节点上进行部署，该分片成为Primary shards主分片。<br />
          注意：索引主分片数量定后，不能被修改<br />
          路由算法： shard = hash(routing) % number_of_primary_shards<br />
          如果number_of_primary_shards在查询的时候取余发生变化，无法获取到该数据<br />
          2.每一个主分片为了实现高可用，都会有自己对应的副本，主分片对应的副本不能存放在同一台服务器上，主分片可以和其他副本存放在同一个Node节点上</p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/41d01719720472.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/41d01719720472.png" alt="" /></a></p>
<p>如果此时Node-1节点是leader，Node-1节点down掉，此时会从（Node-2、Node-3）中选举一个节点作为一个Leader，不管某个节点挂掉，都能保证数据不丢失。除非所有节点全部down机</p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/857b1719720478.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/857b1719720478.png" alt="" /></a></p>
<p>ES单机环境搭建：<a href="http://chenxitag.es.single.com">http://chenxitag.es.single.com</a><br />
ES集群搭建：<a href="http://chenxitag.es.cluster.com">http://chenxitag.es.cluster.com</a></p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:07:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=33</guid>
</item>
<item>
    <title>Centos安装Elasticsearch环境</title>
    <link>http://chenxitag.com/?post=32</link>
    <description><![CDATA[<p>由于Es是Java写的，安装ES的前提先安装好JDK。</p>
<p>Es环境搭建：<br />
1.下载ES包上传到服务器，下载地址：<br />
<a href="https://www.elastic.co/cn/downloads/elasticsearch">https://www.elastic.co/cn/downloads/elasticsearch</a><br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/095f1719720411.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/095f1719720411.png" alt="" /></a></p>
<p>2.解压下载的Tar包</p>
<p>[root@chenxi software]# tar -zxvf elasticsearch-7.6.0-linux-x86_64.tar.gz</p>
<p>3.重命名文件夹名称</p>
<p>[root@chenxi software]# mv elasticsearch-7.6.0 elasticsearch</p>
<p>4.进入elasticsearch目录下</p>
<p>[root@chenxi software]# cd elasticsearch</p>
<p>5.根据自身条件调整JVM大小</p>
<p>[root@chenxi elasticsearch]# vim config/jvm.options</p>
<h1>Xms 表示总堆空间的初始大小 --默认1G</h1>
<h1>Xmx 表示总堆空间的最大大小 --默认1G</h1>
<p>-Xms1g</p>
<p>-Xmx1g</p>
<p>5.修改elasticsearch.yml配置</p>
<p>[root@chenxi elasticsearch]# vim config/elasticsearch.yml</p>
<h1>------------------------------------ Node ------------------------------------</h1>
<p>#</p>
<h1>Use a descriptive name for the node:</h1>
<h1>打开注释，节点名称可自己定义，如果是集群部署，则节点名称必须不相同</h1>
<p>node.name: node-1</p>
<h1>Set the bind address to a specific IP (IPv4 or IPv6):</h1>
<h1>取消注释，服务器IP地址</h1>
<p>network.host: 192.168.0.1<br />
#</p>
<h1>Set a custom port for HTTP:</h1>
<h1>取消注释，Restful 对外接口提供的端口</h1>
<p>http.port: 9200<br />
#</p>
<h1>For more information, consult the network module documentation.</h1>
<p>#</p>
<h1>Bootstrap the cluster using an initial set of master-eligible nodes:</h1>
<h1>取消注释，目前单台机器部署，只需保留node-1节点即可</h1>
<p>cluster.initial_master_nodes: [&quot;node-1&quot;]</p>
<p>6.由于elasticsearch安全性问题不能使用root启动，新建用户，并赋予文件夹权限或者启动命令后追加 –allow-root<br />
[root@chenxi elasticsearch]# groupadd esgroup # &quot;eschenxi&quot; (组名)<br />
[root@chenxi elasticsearch]# useradd esuser # &quot;eschenxi&quot; (用户名)</p>
<p>[root@chenxi elasticsearch]# chown -R eschenxi:esgroup /chenxi/software/elasticsearch #&quot;/chenxi/software/elasticsearch&quot; 为安装目录</p>
<p>7.切换用户</p>
<p>[root@chenxi elasticsearch]# su esuser</p>
<p>8.启动ES</p>
<p>[esuser@chenxi elasticsearch]# bin/elasticsearch</p>
<h1>保持后台运行增加-d即可</h1>
<p>[esuser@chenxi elasticsearch]# bin/elasticsearch -d</p>
<h1>查看es日志</h1>
<p>[esuser@chenxi elasticsearch]# tail -f  logs/elasticsearch.log</p>
<h2>注意防火墙开启9200端口</h2>
<p>测试Es启动是否正常：</p>
<p><a href="http://IP:9092">http://IP:9092</a></p>
<p>{<br />
     &quot;name&quot; : &quot;chenxi&quot;,<br />
     &quot;cluster_name&quot; : &quot;elasticsearch&quot;,<br />
     &quot;cluster_uuid&quot; : &quot;<em>na</em>&quot;,<br />
     &quot;version&quot; : {<br />
               &quot;number&quot; : &quot;7.6.0&quot;,<br />
                &quot;build_flavor&quot; : &quot;default&quot;,<br />
                &quot;build_type&quot; : &quot;tar&quot;,<br />
                &quot;build_hash&quot; : &quot;7f634e9f44834fbc12724506cc1da681b0c3b1e3&quot;,<br />
                &quot;build_date&quot; : &quot;2020-02-06T00:09:00.449973Z&quot;,<br />
                &quot;build_snapshot&quot; : false, &quot;lucene_version&quot; : &quot;8.4.0&quot;,                                          &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,                                            &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;<br />
     },<br />
     &quot;tagline&quot; : &quot;You Know, for Search&quot;</p>
<p>}</p>
<p>Es启动常见问题：<a href="http://chenxitag.es.problem.com">http://chenxitag.es.problem.com</a><br />
ES集群搭建：<a href="http://chenxitag.es.cluster.com">http://chenxitag.es.cluster.com</a></p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:06:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=32</guid>
</item>
<item>
    <title>Elasticsearch启动常见问题</title>
    <link>http://chenxitag.com/?post=31</link>
    <description><![CDATA[<p>错误信息：<br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/940c1719720374.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/940c1719720374.png" alt="" /></a>解决办法：<br />
文件夹赋予用户权限</p>
<p>[root@chenxi elasticsearch]# chown -R eschenxi:esgroup /chenxi/software/elasticsearch #&quot;/chenxi/software/elasticsearch&quot; 为安装目录</p>
<p>错误信息：max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]<br />
ERROR: [1] bootstrap checks failed<br />
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]<br />
ERROR: Elasticsearch did not exit normally - check the logs at /chenxi/software/elasticsearch/logs/elasticsearch.log</p>
<p>解决办法：<br />
[root@chenxi elasticsearch]# vim /etc/sysctl.conf<br />
在文件末尾追加：vm.max_map_count=655360<br />
保存后执行</p>
<p>[root@chenxi elasticsearch]# sysctl -p</p>
<p>错误信息： [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]<br />
ERROR: [5] bootstrap checks failed<br />
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]<br />
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]<br />
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]<br />
[4]:  failed to install; check the logs and fix your configuration or disable system call filters at your own risk<br />
[5]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured</p>
<p>解决办法：</p>
<p>[root@chenxi elasticsearch]# vim /etc/security/limits.conf</p>
<h2>65535修改为65536</h2>
<ul>
<li>
<p>soft nofile 65536</p>
</li>
<li>
<p>hard nofile 65536</p>
</li>
</ul>
<h2>文件末尾追加</h2>
<ul>
<li>
<p>soft nproc 4096</p>
</li>
<li>
<p>hard nproc 4096</p>
</li>
</ul>
<p>修改文件后保存并“关闭会话，重新登陆服务器”</p>
<p>错误信息：system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk<br />
ERROR: [2] bootstrap checks failed<br />
[1]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk<br />
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured</p>
<p>解决办法：</p>
<h2>在elasticsearch.yml修改并添加配置项</h2>
<p>[root@chenxi elasticsearch]# vim config/elasticsearch.yml</p>
<h1>----------------------------------- Memory -----------------------------------</h1>
<p>#</p>
<h1>Lock the memory on startup:</h1>
<h1>取消注释并设置值为false</h1>
<p>bootstrap.memory_lock: false</p>
<h1>追加配置项</h1>
<p>bootstrap.system_call_filter: false</p>
<p>错误信息： the default discovery settings are unsuitable for production use; at least one of<br />
ERROR: [1] bootstrap checks failed<br />
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured</p>
<p>解决办法：</p>
<h2>在elasticsearch.yml添加配置项</h2>
<p>[root@chenxi elasticsearch]# vim config/elasticsearch.yml</p>
<h1>--------------------------------- Discovery ----------------------------------</h1>
<p>#</p>
<h1>Pass an initial list of hosts to perform discovery when this node is started:</h1>
<h1>The default list of hosts is [&quot;127.0.0.1&quot;, &quot;[::1]&quot;]</h1>
<p>#</p>
<h1>discovery.seed_hosts: [&quot;host1&quot;, &quot;host2&quot;]</h1>
<p>#</p>
<h1>Bootstrap the cluster using an initial set of master-eligible nodes:</h1>
<h1>取消注释，并保留一个节点</h1>
<p>cluster.initial_master_nodes: [&quot;node-1&quot;]</p>
<p>测试Es启动是否正常：</p>
<p><a href="http://IP:9092">http://IP:9092</a></p>
<p>{<br />
     &quot;name&quot; : &quot;chenxi&quot;,<br />
     &quot;cluster_name&quot; : &quot;elasticsearch&quot;,<br />
     &quot;cluster_uuid&quot; : &quot;<em>na</em>&quot;,<br />
     &quot;version&quot; : {<br />
               &quot;number&quot; : &quot;7.6.0&quot;,<br />
                &quot;build_flavor&quot; : &quot;default&quot;,<br />
                &quot;build_type&quot; : &quot;tar&quot;,<br />
                &quot;build_hash&quot; : &quot;7f634e9f44834fbc12724506cc1da681b0c3b1e3&quot;,<br />
                &quot;build_date&quot; : &quot;2020-02-06T00:09:00.449973Z&quot;,<br />
                &quot;build_snapshot&quot; : false, &quot;lucene_version&quot; : &quot;8.4.0&quot;,                                          &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,                                            &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;<br />
     },<br />
     &quot;tagline&quot; : &quot;You Know, for Search&quot;</p>
<p>}</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:06:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=31</guid>
</item>
<item>
    <title>Elasticsearch集群环境搭建</title>
    <link>http://chenxitag.com/?post=30</link>
    <description><![CDATA[<p>Es集群搭建核心思想<br />
   1.配置相同集群名称<br />
   2.配置不同的节点ID</p>
<p>   3.修改X台服务器elasticsearch.yml配置</p>
<p>服务器环境-&gt;准备三台服务器集群</p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/2bcb1719720334.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/2bcb1719720334.png" alt="" /></a></p>
<p>服务器集群配置：</p>
<h2>修改elasticsearch.yml文件</h2>
<p>[root@chenxi elasticsearch]# vim elasticsearch.yml</p>
<h1>---------------------------------- Cluster -----------------------------------</h1>
<p>#</p>
<h1>Use a descriptive name for your cluster:</h1>
<h1>取消注释，修改节点集群名称，保证三台服务器节点集群名称相同</h1>
<p>cluster.name: chenxi</p>
<h1>------------------------------------ Node ------------------------------------</h1>
<p>#</p>
<h1>Use a descriptive name for the node:</h1>
<h1>取消注释，每个节点名称不一样，其他两台为node-2, node-3</h1>
<p>node.name: node-1</p>
<h1>---------------------------------- Network -----------------------------------</h1>
<p>#</p>
<h1>Set the bind address to a specific IP (IPv4 or IPv6):</h1>
<h1>取消注释，服务器IP地址</h1>
<p>network.host: 192.168.0.1</p>
<h1>--------------------------------- Discovery ----------------------------------</h1>
<p>#</p>
<h1>Pass an initial list of hosts to perform discovery when new node is started:</h1>
<h1>The default list of hosts is [&quot;127.0.0.1&quot;, &quot;[::1]&quot;]</h1>
<h1>取消注释，多个服务器集群IP</h1>
<p>discovery.zen.ping.unicast.hosts: [&quot;192.168.0.1&quot;,&quot;192.168.0.2&quot;,&quot;192.168.0.3&quot;]<br />
#</p>
<h1>Prevent the &quot;split brain&quot; by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):</h1>
<h1>取消注释，设置最小主节点为1</h1>
<p>discovery.zen.minimum_master_nodes: 1</p>
<h3>关闭防火墙</h3>
<p>注意克隆data文件会导致数据不同步<br />
启动错误信息：<br />
        某台集群服务器报错 failed to send join request to master 时<br />
解决办法：<br />
        清除每台服务器data文件</p>
<p>集群验证地址：<br />
<a href="http://192.168.0.1:9200/_cat/nodes?pretty">http://192.168.0.1:9200/_cat/nodes?pretty</a></p>
<p>如成功显示如下：<br />
192.168.0.1 18 93 1 0.00 0.00 0.00 mdi * node-1<br />
192.168.0.2 20 96 2 0.00 0.03 0.11 mdi - node-2<br />
192.168.0.3 20 96 2 0.00 0.05 0.11 mdi - node-3</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:05:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=30</guid>
</item>
<item>
    <title>Centos环境Kibana可视化平台搭建</title>
    <link>http://chenxitag.com/?post=29</link>
    <description><![CDATA[<p>Kibana环境搭建：</p>
<p>1.下载kibana包上传到服务器，下载地址：<a href="https://www.elastic.co/cn/downloads/kibana">https://www.elastic.co/cn/downloads/kibana</a></p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/c6391719720297.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/c6391719720297.png" alt="" /></a></p>
<p>2.解压下载的Tar包（过程比较久、大概30秒左右）</p>
<p>[root@chenxi software]# tar -zxvf kibana-7.6.0-linux-x86_64.tar.gz</p>
<p>3.重命名文件夹名称<br />
[root@chenxi software]# mv kibana-7.6.0-linux-x86_64 kibana</p>
<p>4.进入kibana目录下<br />
[root@chenxi software]# cd kibana</p>
<p>5.修改kibana.yml配置<br />
[root@chenxi kibana]# vim config/kibana.yml</p>
<h1>Kibana is served by a back end server. This setting specifies the port to use.</h1>
<h1>取消注释，开放端口</h1>
<p>server.port: 5601</p>
<h1>Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.</h1>
<h1>The default is 'localhost', which usually means remote machines will not be able to connect.</h1>
<h1>To allow connections from remote users, set this parameter to a non-loopback address.</h1>
<h1>取消注释，配置服务器IP地址</h1>
<p>server.host: &quot;192.168.0.1&quot;</p>
<h1>The URLs of the Elasticsearch instances to use for all your queries.</h1>
<h1>取消注释，配置ES环境IP地址以及端口</h1>
<p>elasticsearch.url: &quot;<a href="http://192.168.0.1:9200">http://192.168.0.1:9200</a>&quot;</p>
<p>6.由于kibana安全性问题不能使用root启动，新建用户，并赋予文件夹权限或者启动命令后追加 –allow-root<br />
[root@chenxi kibana]# groupadd kgroup # &quot;kgroup&quot; (组名)<br />
[root@chenxi kibana]# useradd kuser # &quot;kuser&quot; (用户名)<br />
[root@chenxi kibana]# chown -R kuser:kgroup /chenxi/software/kibana</p>
<h1>&quot;/chenxi/software/kibana&quot; 为安装目录</h1>
<p>7.切换用户<br />
[root@chenxi kibana]# su kuser</p>
<p>8.启动Kibana<br />
[kuser@chenxi kibana]# bin/kibana</p>
<h2>注意防火墙开启5601端口和9200端口</h2>
<h2>注意Kibana与Es版本号兼容问题</h2>
<h2>注意低版本的Kibana不包含x-pack插件</h2>
<p>控制台输出：<br />
log [07:00:18.179] [info][listening] Server running at <a href="http://192.168.0.1:5601">http://192.168.0.1:5601</a></p>
<p>访问地址：<a href="http://IP:5601">http://IP:5601</a><br />
用户名：amin/123456<a href="http://emlog.chenxitag.com/content/uploadfile/202406/b4131719720307.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/b4131719720307.png" alt="" /></a></p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:04:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=29</guid>
</item>
<item>
    <title>SpringBoot整合Elasticsearch框架</title>
    <link>http://chenxitag.com/?post=28</link>
    <description><![CDATA[<p>新建SpringBoot项目：</p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/fc5d1719720259.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/fc5d1719720259.png" alt="" /></a></p>
<p>修改pom.xml文件，引入spring-boot-data-elasticsearch Jar 包：</p>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
   <version>2.2.2.RELEASE</version>
</dependency>
<p>修改application.yml文件，引入elasticsearch配置：</p>
<p>spring:<br />
data:<br />
elasticsearch:</p>
<h2>集群名称，elasticsearch.yml的cluster.name: chenxi配置</h2>
<pre><code>  ##详情见 http://chenxitag.elasticsearch.cluster.com
  cluster-name: chenxi
  ##集群地址逗号分隔，注意此地方用的端口为9300，Es集群TCP协议端口
  cluster-nodes: 192.168.0.1:9300,192.168.0.2:9300</code></pre>
<p>新建测试Entity：</p>
<p>import lombok.Data;<br />
import org.springframework.data.annotation.Id;<br />
import org.springframework.data.elasticsearch.annotations.Document;</p>
<p>@Document(indexName = &quot;chenxi&quot;, type = &quot;user&quot;/<em>shards = 1, replicas = 2 ##可指定分片数和副本数</em>/)<br />
@Data<br />
public class UserEntity {<br />
@Id<br />
private Integer id;<br />
private String name;<br />
private Integer age;<br />
}</p>
<p>新建测试Dao：</p>
<p>import com.es.entity.UserEntity;<br />
import org.springframework.data.repository.CrudRepository;</p>
<p>public interface UserDao extends CrudRepository&lt;UserEntity, Integer&gt; {<br />
}</p>
<p>新建Test类测试：</p>
<p>import com.es.dao.UserDao;<br />
import com.es.entity.UserEntity;<br />
import com.google.gson.Gson;<br />
import lombok.extern.slf4j.Slf4j;<br />
import org.junit.jupiter.api.Test;<br />
import org.springframework.beans.factory.annotation.Autowired;<br />
import org.springframework.boot.test.context.SpringBootTest;<br />
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;</p>
<p>@SpringBootTest<br />
@Slf4j<br />
class EsTestApplicationTests {</p>
<p>@Test<br />
void contextLoads() {<br />
}</p>
<p>@Autowired<br />
private UserDao userDao;</p>
<p>@Autowired<br />
private ElasticsearchTemplate esTemplate;</p>
<p>@Test<br />
void esSave(){</p>
<pre><code>  UserEntity esEntity = new UserEntity();
  esEntity.setId(1);
  esEntity.setName("chenxi");
  esEntity.setAge(22);

  userDao.save(esEntity);</code></pre>
<p>}</p>
<p>@Test<br />
void esFind(){<br />
log.info(new Gson().toJson(userDao.findById(1)));<br />
//info out &quot;{&quot;value&quot;:{&quot;id&quot;:1,&quot;name&quot;:&quot;chenxi&quot;,&quot;age&quot;:22}}&quot;<br />
}</p>
<p>@Test<br />
void esTemplate(){<br />
log.info(String.valueOf(esTemplate.createIndex(&quot;template_index&quot;)));<br />
//info out &quot;true&quot;<br />
}</p>
<p>错误信息：NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{P20ipqqfSNCzjirh0puSTQ}{192.168.0.1}{192.168.0.1:9300}, {#transport#-2}{I4slCrNuTbmVTOSZ3DG7hA}{192.168.0.2}{192.168.0.2:9300}]</p>
<p>请检查Es是否启动，以及Es环境elasticsearch.yml集群配置项：</p>
<h1>———————————- Cluster ———————————–</h1>
<p>#</p>
<h1>Use a descriptive name for your cluster:</h1>
<h1>节点集群名称，保证三台服务器节点集群名称相同</h1>
<p>cluster.name: chenxi</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 12:04:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=28</guid>
</item>
<item>
    <title>Centos Firewalld防火墙设置</title>
    <link>http://chenxitag.com/?post=26</link>
    <description><![CDATA[<p>Centos7及以上默认安装了firewalld，如果没有安装的话，可以使用<br />
yum install firewalld firewalld-config进行安装。<br />
1.启动防火墙<br />
systemctl start firewalld<br />
2.禁用防火墙<br />
systemctl stop firewalld<br />
3.设置开机启动<br />
systemctl enable firewalld<br />
4.停止并禁用开机启动<br />
sytemctl disable firewalld<br />
5.重启防火墙<br />
firewall-cmd --reload<br />
6.查看状态<br />
systemctl status firewalld 或者 firewall-cmd --state<br />
7.查看版本<br />
firewall-cmd --version<br />
8.查看帮助<br />
firewall-cmd --help<br />
9.查看区域信息<br />
firewall-cmd --get-active-zones<br />
10.查看指定接口所属区域信息<br />
firewall-cmd --get-zone-of-interface=eth0<br />
11.拒绝所有包<br />
firewall-cmd --panic-on<br />
12.取消拒绝状态<br />
firewall-cmd --panic-off<br />
13.查看是否拒绝<br />
firewall-cmd --query-panic<br />
14.将接口添加到区域(默认接口都在public)<br />
firewall-cmd --zone=public --add-interface=eth0(永久生效再加上 --permanent然后reload(重启)防火墙)<br />
15.设置默认接口区域<br />
firewall-cmd --set-default-zone=public(立即生效，无需重启)<br />
16.更新防火墙规则<br />
firewall-cmd --reload：无需断开连接，就是firewalld特性之一动态 添加规则<br />
firewall-cmd --complete-reload：需要断开连接，类似重启服务<br />
17.查看指定区域所有打开的端口<br />
firewall-cmd --zone=public --list-ports<br />
18.在指定区域打开端口（记得重启防火墙）<br />
firewall-cmd --zone=public --add-port=80/tcp(永久生效再加上 --permanent)</p>
<p>防火墙文件设置目录：/etc/firewalld/zone/public.xml（重启永久生效）</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 11:59:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=26</guid>
</item>
<item>
    <title>Centos安装禅道</title>
    <link>http://chenxitag.com/?post=25</link>
    <description><![CDATA[<p>1.安装包下载</p>
<p>根据系统内核版本选择合适的安装包：<a href="https://www.zentao.net/dynamic/80201.html">https://www.zentao.net/dynamic/80201.html</a></p>
<p>查看服务器版本：<br />
[root@chenxi opt]# cat /etc/redhat-release<br />
[root@chenxi opt]# cat /proc/version</p>
<p>注意：linux一键安装包只能安装在/opt目录下，如果需要安装到其他目录。可以自己搭建环境后使用源码包安装，参考文档：<a href="http://www.zentao.net/book/zentaopmshelp/101.html">http://www.zentao.net/book/zentaopmshelp/101.html</a></p>
<p>2.上传至安装目录：</p>
<p>sftp:/opt&gt; put F:\下载\ZenTaoPMS.biz3.6.1.zbox_64.tar.gz</p>
<p>2.解压到/opt/module目录下</p>
<p>[root@chenxi opt]# tar -zxvf ZenTaoPMS.9.0.1.zbox_64.tar.gz -C /opt/</p>
<p>3.修改禅道自带apache(80)和 mysql(3306)端口</p>
<p>为了不占用服务器端口，根据自己情况可不修改</p>
<p>        ①修改禅道自带apache端口：</p>
<p>[root@chenxi opt]# /opt/zbox/zbox -ap 9000</p>
<p>       ② 修改禅道自带mysql端口：</p>
<p>[root@chenxi opt]#  /opt/zbox/zbox -mp 9001</p>
<p>4.重启禅道服务</p>
<p>[root@chenxi opt]# /opt/zbox/zbox restart</p>
<p>    显示  Apache is running    Mysql is running   则启动成功</p>
<p>相关命令：</p>
<p>/opt/zbox/zbox start ：开启Apache和Mysql<br />
/opt/zbox/zbox stop ：停止Apache和Mysql<br />
/opt/zbox/zbox restart ：重启Apache和Mysql<br />
5.创建数据库账号<br />
    [root@chenxi opt]# /opt/zbox/auth/adduser.sh</p>
<p>输入账号 和 密码 mysql数据库：/opt/zbox/bin/mysql -u root -P 9001 -p</p>
<p>6.配置Firewall防火墙规则，允许端口访问<br />
    开启9000端口：<br />
    [root@chenxi opt]# firewall-cmd --zone=public --add-port=9000/tcp<br />
    开启9001端口：</p>
<p>[root@chenxi opt]# firewall-cmd --zone=public --add-port=9001/tcp</p>
<p>7.重启防火墙，使规则生效：</p>
<p>[root@chenxi opt]# systemctl restart firewalld.service</p>
<p>8.浏览器访问 <br />
    <a href="http://IP:9000/zentao/user-login-L3plbnRhby8=.html">http://IP:9000/zentao/user-login-L3plbnRhby8=.html</a><br />
    默认账号密码：admin/123456</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 11:59:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=25</guid>
</item>
<item>
    <title>Kafka进阶之幂等性以及分区分配策略</title>
    <link>http://chenxitag.com/?post=24</link>
    <description><![CDATA[<p>Exactly Once语义：<br />
将服务器的ACK级别设置为-1，可以保证Producer到Server之间不会丢失数据，即At Least Once 语义。相对的，将服务器ACK级别设置为0，可以保证生产者每条消息只会被发送一次，即At Most Once语义。</p>
<pre><code>At Least Once可以保证数据不丢失，但是不能保证数据不重复；相对的， At Least Once可以保证数据不重复，但是不能保证数据不丢失。 </code></pre>
<p>对于一些非常重要的信息，比如交易数据，下游数据消费者要求数据既不重复也不丢失，在 0.11 版本以前的 Kafka，对此是无能为力的，只能保证数据不丢失，再在下游消费者对数据做全局去重。对于多个下游应用的情况，每个都需要单独做全局去重，这就对性能造成了很大影响。</p>
<pre><code>0.11 版本的 Kafka，引入了一项重大特性：幂等性。幂等性就是指Producer不论向Broker发送多少次重复数据，Broker都只会持久化一条。幂等性结合At Least Once语义，就构成了Kafka的Exactly Once语义。

            At Least Once + 幂等性 = Exactly Once</code></pre>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/3aeb1719719787.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/3aeb1719719787.png" alt="" /></a></p>
<pre><code>要启用幂等性，只需要将Producer的参数中enable.idompotence设置为true(设置为true时，ACK默认设置为-1)。
Kafka的幂等性实现是将原来下游需要做的去重放在了数据上游。开启幂等性的Producer在初始化的时候会被分配一个PID，发往同一Partition的消息会附带Sequence Number。而Broker端会对&lt;PID, Partition, SeqNumber&gt;做缓存，当具有相同主键的消息提交时，Broker只会持久化一条。

PID重启就会变化，同时不同的Partition也具有不同主键，所以幂等性无法保证跨分区跨会话的Exactly Once。 </code></pre>
<p>Kafka消费者：<br />
    consumer 采用 pull（拉） 模式从 broker 中读取数据。</p>
<pre><code> push（推）模式很难适应消费速率不同的消费者，因为消息发送速率是由 broker 决定的。它的目标是尽可能以最快速度传递消息，但是这样很容易造成consumer来不及处理消息，而pull模式则可以根据consumer的消费能力以适当的速率消费消息。

pull模式不足之处是，如果kafka没有数据，消费者可能会陷入循环中，一直返回空数据。针对这一点，Kafka的消费者在消费数据时会传入一个时长参数 timeout，如果当前没有数据可供消费，consumer会等待一段时间之后再返回</code></pre>
<p>分区分配策略 ：<br />
一个consumer group中有多个consumer，一个topic有多个partition，所以会涉及到partition的分配问题，如何确定哪个partition由哪个consumer来消费？</p>
<p>Kafka有两种分配策略：RoundRobin（轮循）和 Range（范围）。</p>
<p>Kafka默认使用的是Range分配策略。<br />
可设置partition.assignment.strategy的值进行自由调整（RoundRobin、Range）。<br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/fd961719719920.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/fd961719719920.png" alt="" /></a><br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/163f1719719816.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/163f1719719816.png" alt="" /></a></p>
<p>RoundRobin（轮循）：根据消费者组来进行轮循划分，把消费者组看成一个整体来进行轮循。（需要保证同一个消费者组下的消费者订阅同一个topic）</p>
<p><a href="http://emlog.chenxitag.com/content/uploadfile/202406/13521719719837.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/13521719719837.png" alt="" /></a><br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/24f51719719851.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/24f51719719851.png" alt="" /></a></p>
<p>Range（范围）：根据（分区数量 / 消费者组数量 = 范围）划分。</p>
<p>假设有2个消费者(cA,cB)和2个topic分别有3个partition<br />
(topic-A{a-p-0,a-p-1,a-p-2}), topic-B{b-p-0,b-p-1,b-p-2}) </p>
<p>分配后的结果是：<br />
M = 3/2<br />
cA = a-p-0,a-p-1,b-p-0,b-p-1<br />
cB = a-p-2,b-p-2<br />
<a href="http://emlog.chenxitag.com/content/uploadfile/202406/525c1719719860.png"><img src="http://emlog.chenxitag.com/content/uploadfile/202406/525c1719719860.png" alt="" /></a></p>
<p>导致前M个分配不均匀，消费者负载。</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 11:56:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=24</guid>
</item>
<item>
    <title>Zookeeper搭建集群问题</title>
    <link>http://chenxitag.com/?post=23</link>
    <description><![CDATA[<p>错误日志：ZooKeeper JMX enabled by default<br />
Using config: /opt/module/zookeeper-3.4.14/bin/../conf/zoo.cfg<br />
Error contacting service. It is probably not running.</p>
<p>解决方案：</p>
<p>1.注意myid文件内容是否对应zk集群配置的server.id<br />
2.注意Server的防火墙是否开放zk端口</p>
<p>错误日志：<br />
2020-02-18 14:36:53,275 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:FastLeaderElection@847] - Notification time out: 12800<br />
2020-02-18 14:37:06,076 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (1, 0)<br />
2020-02-18 14:37:06,077 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (2, 0)<br />
2020-02-18 14:37:06,077 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:FastLeaderElection@847] - Notification time out: 25600<br />
2020-02-18 14:37:31,678 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (1, 0)<br />
2020-02-18 14:37:31,679 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (2, 0)<br />
2020-02-18 14:37:31,680 [myid:0] - INFO [QuorumPeer[myid=0]/0.0.0.0:2181:FastLeaderElection@847] - Notification time out: 51200</p>
<p>解决方案:  保持这台有问题zk的现状, 按myid从小到大依次重启其他的zk机器;</p>
<p>原因:  zk是需要集群中所有机器两两建立连接的, 其中配置中的3555端口是用来进行选举时机器直接建立通讯的端口, 大id的server才会去连接小id的server，避免连接浪费.如果是最后重启myid最小的实例,该实例将不能加入到集群中, 因为不能和其他集群建立连接</p>]]></description>
    <pubDate>Sun, 30 Jun 2024 11:56:00 +0800</pubDate>
    <dc:creator>晨曦</dc:creator>
    <guid>http://chenxitag.com/?post=23</guid>
</item></channel>
</rss>