In this article, we still do some basic learning on how to perform CRUD in Elasticsearch.
环境:CentOS 7.2 JDK 1.8.0_74
##1. Install the first ElasticSearch (master node)
1. Create an es user. You cannot use the root user to start es.useradd es passwd es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node2
vi elasticsearch-node2/config/elasticsearch.yml
cluster.name: my-application 各节点此名称必须一致node.name: node-2 节点名称,不能与其他节点相同 network.host: ***.***.***.*** 自己的服务器IPhttp.port: **** 访问端口transport.tcp.port: **** 集群各节点间的通讯端口 discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]
http.cors.enabled: truehttp.cors.allow-origin: "*"
sh elasticsearch-node2/bin/elasticsearch
[2018-01-24T15:36:41,990][INFO ][o.e.n.Node ] [KMyyO-3] started [2018-01-24T15:36:41,997][INFO ][o.e.g.GatewayService ] [KMyyO-3] recovered [0] indices into cluster_state
IP:access port## in the browser #The webpage displays the following content, indicating that the deployment is successful
{ "name" : "node-2", "cluster_name" : "my-application", "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww", "version" : { "number" : "6.1.2", "build_hash" : "5b1fea5", "build_date" : "2018-01-10T02:35:59.208Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"}
6, error reporting and its handling
[Type 1]Caused by: java.lang.RuntimeException: can not run elasticsearch as root
chown -R es:es elasticsearch-node2/su - es sh elasticsearch-node2/bin/elasticsearch
[Type 2]
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
Solution, change back to root user and modify the configuration file
vi /etc/security/limits.conf#在最后面追加下面内容es hard nofile 65536es soft nofile 65536
[Type 3]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Solution, change back to the root user and modify the configuration file
vi /etc/sysctl.conf #在最后面追加下面内容vm.max_map_count=655360#执行命令:sysctl -p
The installation method is the same as the first The two are consistent, pay attention to modifying the configuration fileroot user enters the /home/es directory
1. Unzip and change the name
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node3
2. Modify the configuration file
vi elasticsearch-node3/config/elasticsearch.yml
Modify The content is as follows:
cluster.name: my-application 各节点此名称必须一致node.name: node-3 节点名称,不能与其他节点相同network.host: ***.***.***.*** 自己的服务器IPhttp.port: **** 访问端口(注意不要与第一个端口重复) transport.tcp.port: **** 集群各节点间的通讯端口(注意不要与第一个端口重复)discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]
Also append the following code at the end of the file
http.cors.enabled: truehttp.cors.allow-origin: "*"
3. Start the
sh elasticsearch-node3/bin/elasticsearch
browser and enter
IP:access portin the browser The webpage displays the following content, indicating that the second deployment is successful
{ "name" : "node-3", "cluster_name" : "my-application", "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww", "version" : { "number" : "6.1.2", "build_hash" : "5b1fea5", "build_date" : "2018-01-10T02:35:59.208Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"}
1. You need to install node.js before installing the head plug-in
curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install -y nodejs
[root@host]# node -vv8.12.0[root@host]# npm -v6.4.1
2. Get the head plug-in from git
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
3. Unzip the installation package (you can rename it for easy operation)
unzip master.zip mv elasticsearch-head-master/ head
4. Modify the configuration file
vi head/Gruntfile.js
Change the head port number
connect: { server: { options: { port: ****, 改为head访问端口 base: '.', keepalive: true } } }
vi head/_site/app.js
Change the head link address
init: function(parent) { this._super(); this.prefs = services.Preferences.instance(); this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://主节点IP:访问端口";
5. Start the head
nohup npm run start > ../head.log 2>&1 &
6. Browser login head
URL input server IP: head access port
7. Common errors in installing head
[Type 1] Started successfully, but the webpage cannot be accessed
Solution
Turn off the server firewall
service iptables stop
http.cors.enabled: truehttp.cors.allow-origin: "*"
Related recommendations:
The above is the detailed content of How to understand Elasticsearch single-machine two-node cluster deployment. For more information, please follow other related articles on the PHP Chinese website!