通过Yum来设置Elasticsearch

备忘录

【操作系统】
本次使用的是CentOS6.6_x86_64版本。详情请参考以下链接。
http://centos.server-manual.com/
预先准备
需要预先设置所需的安装包。请设置以下全部内容。
由于会有系统变更,因此需要管理员权限。请以root用户进行su操作。

【YUM包管理】
yum -y安装yum-plugin-fastestmirror
yum -y更新
yum -y groupinstall “Base” “开发工具” “日文支持”
【添加RPMforge存储库】
rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
【添加EPEL存储库】
rpm –import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
【添加ELRepo存储库】
rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
【添加Remi存储库】
rpm –import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

【禁用SELinux】
getenforce
強制执行 ← SELinux启用
setenforce 0
getenforce
宽容态 ← SELinux禁用
vi /etc/sysconfig/selinux
SELINUX=enforcing
SELINUX=disabled ← 修改(开机禁用)

允许HTTP通过iptables:
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 9200 -j ACCEPT ←添加
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
重新启动Iptables:
service iptables restart

【JAVA】
在CentOS構建時,卸載默認安裝的版本。
yum erase java*
從網上獲取最新版本(rpm版)並安裝。
rpm –ivh jdk-8u45-linux-x64.rpm
版本確認
java –version
java version “1.8.0_45”
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, 混合模式)
■設置JAVA_HOME
vi /etc/profile


export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

【Elasticsearch】
■创建存储库
rpm –import https://packages.elastic.co/GPG-KEY-elasticsearch
vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-1.6]
name=用于1.6.x软件包的Elasticsearch存储库
baseurl=http://packages.elastic.co/elasticsearch/1.6/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
■安装和启动
yum install elasticsearch
service elasticsearch start
chkconfig elasticsearch on
■确认
curl ‘localhost:9200/_cat/health?v’

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign
1436159102 14:05:02  elasticsearch green           1         1      0   0    0    0        0

【kuromoji】
为了使日语能够搜索,您需要安装和设置kuromoji。
最新版本可在https://github.com/elastic/elasticsearch-analysis-kuromoji下载。
执行以下命令:
cd /usr/share/elasticsearch
bin/plugin –install elasticsearch/elasticsearch-analysis-kuromoji/2.6.0

打开/etc/elasticsearch/elasticsearch.yml文件,找到index.analysis.analyzer.default.type这一行,并将其修改为custom。接着找到index.analysis.analyzer.default.tokenizer这一行,并将其修改为kuromoji_tokenizer。

重新启动elasticsearch服务

bannerAds