【软件工具安装-Linux】ElasticSearch单节点搭建
程序员文章站
2022-03-26 18:23:23
...
创建es普通用户
[aaa@qq.com ~]# groupadd elasticsearch
[aaa@qq.com ~]# useradd es
[aaa@qq.com ~]# passwd es
更改用户 es 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[aaa@qq.com ~]# usermod -G elasticsearch es
[aaa@qq.com ~]# vi /etc/sudoers
root ALL=(ALL) ALL
#添加es用户
es ALL=(ALL) ALL
[aaa@qq.com ~]# su es
[aaa@qq.com root]$
安装并配置es
[aaa@qq.com local]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz
[aaa@qq.com local]$ sudo tar -zxvf elasticsearch-6.3.2.tar.gz
[aaa@qq.com local]# sudo chown -R es:elasticsearch elasticsearch-6.3.2
[aaa@qq.com local]# ll
总用量 92260
drwxr-xr-x 8 es elasticsearch 4096 7月 20 2018 elasticsearch-6.3.2
[aaa@qq.com elasticsearch-6.3.2]# vi config/elasticsearch.yml
//下面这四个位置找到对应的地方放开
cluster.name: elasticsearch
node.name: node-1
network.host: 172.16.11.248
http.port: 9200
//#head插件想访问es,则es需要配置跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
[aaa@qq.com elasticsearch-6.3.2]# vi /etc/sysctl.conf
//在文件末尾追加以下信息
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.max_map_count = 262144
[aaa@qq.com elasticsearch-6.3.2]# sysctl -p
[aaa@qq.com ~]# vi /etc/security/limits.conf
//在文档末尾追加以下内容
# End of file
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
[aaa@qq.com bin]$ ./elasticsearch
键入配置文件中的ip与port在地址栏访问es服务器,出现如下信息,es服务安装成功。
设置elasticsearch开机启动
[aaa@qq.com ~]# cd /etc/init.d/
[aaa@qq.com init.d]# touch elasticsearch
//设置elastic search执行脚本
[aaa@qq.com init.d]# vi elasticsearch
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
#export JAVA_HOME=/usr/java/jdk1.8.0_112
#export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
#export PATH=$PATH:$JAVA_HOME/bin
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#export JAVA_HOME JAVA_BIN PATH CLASSPATH
#set java environment
export JAVA_HOME=/usr/lib/jvm/java
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
case "$1" in
start)
su lyt<<!
cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su lyt<<!
cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
//赋予文件可执行权限
[aaa@qq.com init.d]# chmod +x elasticsearch
//添加到开机启动任务
[aaa@qq.com init.d]# chkconfig --add elasticsearch
//重启虚拟机验证elastic search自启动设置是否成功
[aaa@qq.com ~]# reboot
[aaa@qq.com ~]# systemctl status elasticsearch
● elasticsearch.service - SYSV: elasticsearch
Loaded: loaded (/etc/rc.d/init.d/elasticsearch; bad; vendor preset: disabled)
Active: active (exited) since 五 2019-09-27 14:29:19 CST; 1min 52s ago
Docs: man:systemd-sysv-generator(8)
Process: 8917 ExecStart=/etc/rc.d/init.d/elasticsearch start (code=exited, status=0/SUCCESS)
安装head插件
1.安装node js
head插件实质上还是node.js的工程,因此需要安装node,使用npm来安装依赖的包。
[aaa@qq.com local]# mkdir elk
[aaa@qq.com elk]# wget https://npm.taobao.org/mirrors/node/latest-v10.x/node-v10.1.0-linux-x64.tar.gz
[aaa@qq.com elk]# tar -zxvf node-v10.1.0-linux-x64.tar.gz
[aaa@qq.com elk]# vi /etc/profile
#node_home
export NODE_HOME=/usr/local/elk/node-v10.1.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules
[aaa@qq.com elk]# source /etc/profile
[aaa@qq.com elk]# node -v
v10.1.0
[aaa@qq.com elk]# npm -v
5.6.0
2.安装grunt
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动,故需先安装grunt;
进入nodejs的根目录下,进行安装grunt。
[aaa@qq.com elk]# cd node-v10.1.0-linux-x64
[aaa@qq.com node-v10.1.0-linux-x64]# npm install -g cnpm --registry=https://registry.npm.taobao.org
[aaa@qq.com node-v10.1.0-linux-x64]# npm install -g grunt
[aaa@qq.com node-v10.1.0-linux-x64]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
3.安装head插件
//进入新创建的head目录,切记不要装在elasticsearch原有的plugins文件夹下
[aaa@qq.com node-v10.1.0-linux-x64]# cd /usr/local/elasticsearch-6.3.2/head
[aaa@qq.com head]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[aaa@qq.com head]# yum -y install unzip
[aaa@qq.com head]# unzip master.zip
[aaa@qq.com head]# cd elasticsearch-head-master/
[aaa@qq.com elasticsearch-head-master]# npm install aaa@qq.com --ignore-scripts
[aaa@qq.com elasticsearch-head-master]# npm install
[aaa@qq.com elasticsearch-head-master]# vi Gruntfile.js
//找到server 修改hostname
connect: {
server: {
options: {
hostname:'172.16.11.248',
port: 9100,
base: '.',
keepalive: true
}
}
}
[aaa@qq.com elasticsearch-head-master]# grunt server
(node:9550) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://172.16.11.248:9100
设置head插件开机自启动
[aaa@qq.com init.d]# vi elasticsearch-head
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch-head
# nodejs 安装的路径
#export NODE_PATH=/usr/local/node-js
#export PATH=$PATH:$NODE_PATH/bin
#node_home
export NODE_HOME=/usr/local/elk/node-v10.1.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules
# elasticsearch-head 的路径
cd /usr/local/elasticsearch-6.3.2/plugins/elasticsearch-head-master
nohup npm run start >/usr/local/elasticsearch-6.3.2/plugins/elasticsearch-head-master/nohup.out 2>&1 &
[aaa@qq.com init.d]# chmod +x elasticsearch-head
[aaa@qq.com init.d]# chkconfig --add elasticsearch-head
创建索引后集群状态为黄色,修改分片数使集群达到健康状态
curl -H "Content-Type: application/json" -XPUT http://172.16.11.248:9200/_settings -d '
{
"index":{
"number_of_replicas":0
}
}'
{"acknowledged":true}