在A主机CentOS 7上安装Elasticsearch 2.4.6,供B主机访问使用Elasticsearch

  • 欢迎 游客 您的光临,下载之前请先阅读 积分规则(暂行) 。任何技术问题请在论坛提问,本站定制插件、模板主题售前、售后问题请联系QQ:5916171

sniper756

CNXFans
UID
6
注册
2017/09/10
消息
12
反馈评分
3
黄金
615.2G
    Windows 7 Chrome 71.0.3578.98
  • #1
事前准备 卸载自带java

1.检查一下系统中的jdk版本


代码:
java -version

java version "1.7.0_"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

2.检测JDK安装包

代码:
rpm -qa | grep java

下面版本号各异
avapackages-tools-3.4.1-6.el7_0.noarch
tzdata-java-2014i-1.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
python-javapackages-3.4.1-6.el7_0.noarch

3.卸载OpenJDK

下面版本号各异
代码:
rpm -e --nodeps tzdata-java-2014i-1.el7.noarch
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64

nodeps 后边的版本根据上边输出的信息复制粘贴过来

还有一些其他的命令:

代码:
rpm -qa | grep gcj
rpm -qa | grep jdk

如果出现找不到openjdk source的话,那么还可以这样卸载

代码:
yum -y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
yum -y remove java java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

一、安装配置jdk1.8

1、去官网下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

注意:要先进入以上网址,同意条款后,点击jdk-8u151-linux-x64.rpm下载,取得真实下载地址,再用wget下载到服务器
代码:
cd /
mkdir aaa
cd aaa
wget http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm?AuthParam=1511629557_d36ca0347a53775abacda19ad792f191

重命名为jdk-8u151-linux-x64.rpm

2.安装JDK

代码:
rpm -ivh jdk-8u151-linux-x64.rpm

3.检查jdk

java -version

代码:
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

二、在CentOS 7上安装Elasticsearch 2.4.6

1、我这里用的是2.4.6版如需其它版本请查看官网根据自己服务器内存和网站需求

下载


代码:
cd /aaa
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.4.6/elasticsearch-2.4.6.rpm

2、安装rpm包

代码:
rpm -ivh elasticsearch-2.4.6.rpm

随着系统运行Elasticsearch,运行下面的命令:

代码:
sudo systemctl daemon-reload
代码:
sudo systemctl enable elasticsearch.service

3、启动Elasticsearch

代码:
sudo systemctl start elasticsearch.service

4、测试Elasticsearch

代码:
curl -XGET 'http://localhost:9200'

5、停止

代码:
sudo systemctl stop elasticsearch.service

6、配置ES文件

创建/var/bbb备用
代码:
cd /var
mkdir bbb
chmod -R 777 bbb

代码:
/etc/elasticsearch/elasticsearch.yml

elasticsearch.yml配置如下

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: ccc
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# node.name: node-1
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/elasticsearch
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.memory_lock: true
#
# Make sure that the ES_HEAP_SIZE environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

7、启动Elasticsearch

代码:
sudo systemctl start elasticsearch.service

8、安装分词插件

分词插件介绍:https://github.com/medcl/elasticsearch-analysis-ik

安装方法:进入cd /usr/share/elasticsearch/bin

代码:
./plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v1.10.6/elasticsearch-analysis-ik-1.10.6.zip

---------------------------------------------

重启Elasticsearch

代码:
sudo systemctl stop elasticsearch.service
代码:
sudo systemctl start elasticsearch.service

9、CentOS 7上卸载 elsticsearch

代码:
yum remove elasticsearch

10.在es所在服务器进行防火墙设置(以及阿里云安全组端口设置),限制只能由web服务器ip才能访问es端口。
 

sniper756

CNXFans
UID
6
注册
2017/09/10
消息
12
反馈评分
3
黄金
615.2G
    Windows 7 Chrome 71.0.3578.98
  • #2
要想IK起作用还需要进行以下修改

1.编辑elasticsearch.yml移到文件最下面,粘贴以下内容:

index.analysis.analyzer.default.type: custom
index.analysis.analyzer.default.tokenizer: ik_max_word


2.需要简单修改一下XFES的代码,使用XFES在创建索引时使用IK分词,而不是使用default.
找到文件:
src\addons\XFES\Service\Analyzer.php
查找

PHP:
'tokenizer' => 'standard',

更改为

PHP:
'tokenizer' => 'ik_max_word',

src\addons\XFES\Service\Analyzer.php文件中查找:

PHP:
if ($default['type'] != 'custom' || $default['tokenizer'] != 'standard')

替换为

PHP:
if ($default['type'] != 'custom' || $default['tokenizer'] != 'ik_max_word')
 
  • 支持
反馈: 死了算了