ElasticSearch 5.2.2 之 elasticsearch

1.安装elasticsearch,CentOS7.2

# 更改计算机名
hostnamectl set-hostname elasticsearch

systemctl stop firewalld.service    #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

 2.安装java环境,elasticsearch需要java 1.8.0_73以上版本

yum list java*
yum install java-1.8.0-openjdk -y
java -version

 3.修改内核参数

# limits.conf
echo -e "* soft nproc unlimited" >> /etc/security/limits.conf
echo -e "* hard nproc unlimited" >> /etc/security/limits.conf
echo -e "* soft nofile 655350" >> /etc/security/limits.conf
echo -e "* hard nofile 655350" >> /etc/security/limits.conf

# /etc/proflie
echo -e "ulimit -SHn 655350" >> /etc/profile
echo -e "ulimit -SHu unlimited" >> /etc/profile
echo -e "ulimit -SHd unlimited" >> /etc/profile
echo -e "ulimit -SHm unlimited" >> /etc/profile
echo -e "ulimit -SHs unlimited" >> /etc/profile
echo -e "ulimit -SHt unlimited" >> /etc/profile
echo -e "ulimit -SHv unlimited" >> /etc/profile

# /etc/sysctl.conf 
echo -e "vm.max_map_count=262144" >> /etc/sysctl.conf
source /etc/profile
sysctl -p

# 开启内存锁定
echo -e "elasticsearch soft memlock unlimited" >> /etc/security/limits.conf
echo -e "elasticsearch hard memlock unlimited" >> /etc/security/limits.conf

 4.下载安装elasticsearch

useradd elasticsearch

cd /usr/local/src/
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz
tar -zxvf elasticsearch-5.2.2.tar.gz -C /usr/local/
ln -sv /usr/local/elasticsearch-5.2.2/ /usr/local/elasticsearch
mkdir /usr/local/elasticsearch/data
chown -R elasticsearch.elasticsearch /usr/local/elasticsearch-5.2.2/

# 编辑elasticsearch配置
vim /usr/local/elasticsearch/config/elasticsearch.yml

grep -Ev "^#" /usr/local/elasticsearch/config/elasticsearch.yml
cluster.name: pinhui-cluster
node.name: pinhui-node1
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.1.20:9300", "192.168.1.21:9300"]

# 如果内存太小,需要修改参数
vim /usr/local/elasticsearch/config/jvm.options
-Xms512m   # 修改为512m
-Xmx512m   # 修改为512m

# 启动elasticsearchf服务
su elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch -d"

5.测试elasticsearch服务

[root@elasticsearch02 ~]# curl -i -XGET '192.168.1.22:9200/'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 330

{
  "name" : "ph-node01",
  "cluster_name" : "pinhui-cluster",
  "cluster_uuid" : "Q36wfBSESZWFY8mXHcLg-w",
  "version" : {
    "number" : "5.2.2",
    "build_hash" : "f9d9b74",
    "build_date" : "2017-02-24T17:26:45.835Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}

6. 安装elasticsearch-head插件

# 安装npm依赖
curl -sL -o /etc/yum.repos.d/khara-nodejs.repo https://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo
yum install -y nodejs nodejs-npm
node -v
npm -v

# 安装elasticsearch
cd /usr/local
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
npm install -g grunt-cli --registry=https://registry.npm.taobao.org
npm install -g grunt --registry=https://registry.npm.taobao.org
npm install                  # 这步记得运行,运行慢就运行下一步
npm install -gd express --registry=http://registry.npm.taobao.org

# elasticsearch增加,避免跨域问题
vim /usr/local/elasticsearch/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"

# 启动elasticsearch-head
cd /usr/local/elasticsearch-head/node_modules/grunt/bin
./grunt server

 

 

参考文档: http://www.cnblogs.com/saneri/p/6912593.html

posted @ 2017-06-27 19:36  sunmmi  阅读(347)  评论(0)    收藏  举报