wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.1-linux-x86_64.tar.gz wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.1-linux-x86_64.tar.gz.sha512 shasum -a 512 -c elasticsearch-7.12.1-linux-x86_64.tar.gz.sha512 tar -xzf elasticsearch-7.12.1-linux-x86_64.tar.gz cd elasticsearch-7.12.1/
启动
1
./bin/elasticsearch
启动异常1:
1 2 3 4 5 6 7 8 9 10 11 12 13
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.12.1.jar:7.12.1] at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.12.1.jar:7.12.1] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397) ~[elasticsearch-7.12.1.jar:7.12.1] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.12.1.jar:7.12.1]
因为elasticsearch不能使用root账户启动,因此我们需要创建个账户进行启动:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 添加elastic用户,并将文件放到elastic用户目录下 useradd elastic mv elasticsearch-7.12.1 /home/elastic cd /home/elastic
# 授权目录权限给elastic用户 su root chown -R elastic:elastic elasticsearch-7.12.1
# 切换为elastic用户再次启动 su elastic cd elasticsearch-7.12.1/
./bin/elasticsearch
启动异常2:
1
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
PUT http://localhost:9200/db_test/user/1 { "first_name":"John", "last_name":"Smith", "age":25, "about":"i love to go rock climbing", "interests":["sports","music"] }
PUT http://localhost:9200/db_test/user/2 { "first_name":"Jane", "last_name":"Smith", "age":32, "about":"i like to collect rock albums", "interests":["music"] } PUT http://localhost:9200/db_test/user/3 { "first_name":"Douglas", "last_name":"Fir", "age":35, "about":"i like to build cabinets", "interests":["forestry"] }
{ "took": 83, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 1.4167401, "hits": [ { "_index": "db_test", "_type": "user", "_id": "1", "_score": 1.4167401, "_source": { "first_name": "John", "last_name": "Smith", "age": 25, "about": "i love to go rock climbing", "interests": [ "sports", "music" ] }, "highlight": { "about": [ "i love to go <em>rock</em> <em>climbing</em>" ] } } ] } }
覆盖更新索引
1 2 3 4 5 6 7 8 9 10
PUT http://v11:9200/db_test/user/2 { "first_name": "Jane", "last_name": "Smith", "age": 18, "about": "i like to collect rock albums", "interests": [ "music" ] }