建个文件夹,把该脚本和elasticsearch-6.3.1.tar.gz放在文件下
运行脚本即可
#!/bin/bash
ELASTICSEARCH_HOME=/opt/elastechsearch
elasticsearch_tar=elasticsearch-6.3.1.tar.gz
es_instal_home=$ELASTICSEARCH_HOME/elasticsearch-6.3.1
echo "Installing Elasticsearch"
# setp1 为es 创建用户
mkdir - $ELASTICSEARCH_HOME
echo " "
read -p "Enter your userName for elastechsearch > " es_userName
echo "hello $es_userName"
read -p "Enter your group for $es_userName > " es_userGroup
useradd $es_userName
echo "set passwd for $es_userName"
#passwd $es_userName
groupadd $es_userGroup
usermod -G $es_userGroup $es_userName
tar xzvf $elasticsearch_tar -C $ELASTICSEARCH_HOME
# rm -rf $elasticsearch_tar
cd $es_instal_home
mkdir logs data
#为es用户添加elasticsearch-6.3.1权限
chown -R $es_userName:$es_userGroup $ELASTICSEARCH_HOME/elasticsearch-6.3.1/*
sed -i "s|#path.logs: /path/to/logs|path.logs: $es_instal_home/logs|" $es_instal_home/config/elasticsearch.yml
# 配置elastech的host 使外网能够访问
sed -i "s|#network.host: 192.168.0.1|network.host: 0.0.0.0|" $es_instal_home/config/elasticsearch.yml
# 这里追加不好,要改
echo "vm.max_map_count=855360" >> /etc/sysctl.conf
# sed -i "s|vm.max_map_count=.*|vm.max_map_count=855360|" /etc/sysctl.conf
# 这里追加不好,要改
echo "* hard nofile 65536" >>/etc/security/limits.conf
# 这里追加不好,要改
echo "* soft nofile 65536" >>/etc/security/limits.conf
为了保险起见,重新启动一下服务器;
然后
切换为es用户
su $es_userName
cd $es_instal_home/bin
后台启动
./elasticsearch -d
$ ./bin/elastechsearch -d
校验是否开启成功
[esadmin@cdh01 elasticsearch-6.3.1]$ curl http://127.0.0.1:9200
{
"name" : "qe6GyBJ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "zCagCj49SpeFKKP3duAMhQ",
"version" : {
"number" : "6.3.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "eb782d0",
"build_date" : "2018-06-29T21:59:26.107521Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[esadmin@cdh01 elasticsearch-6.3.1]$