JAVA deployment
Copy the JDK 8U161-linux-x64.tar. gz to the appropriate location, or go to the Java official website for the version you want, the requirements are 8uxxx, the version must be higher than 161
JAVA official download site
The tar XVF decompression
Copy the decompressed content to the appropriate location, using /usr/lib/jdk in this example
Cp -r jdk1.8.0 _161 /. / usr/lib/JDKCopy the code
Write environment variables
sudo vim /etc/profile
Copy the code
#set java env
export JAVA_HOME=/usr/lib/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Copy the code
Enable environment variables
source /etc/profile
Copy the code
Configure the soft connection, and some software may look for Java in the /usr/bin directory
sudo update-alternatives --install /usr/bin/java java /usr/lib/jdk/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jdk/bin/javac 300
Copy the code
View the Java version to check whether the deployment is successful
java -version
Copy the code
ES deployment
Official deployment documentation
Official source installation and deployment documents
Download the source package
The curl - L - O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.2.tar.gzCopy the code
With curl, the speed is very slow. You are advised to download the url and copy it to the server
Place the source package in the appropriate location, in this case /home
Tar -xvf elasticSearch-6.6.2.tar. gz CD elasticSearch-6.6.2 /config vim elasticSearch.ymlCopy the code
Modifying a Configuration File
The initial configuration file is all commented, be sure to set the bottom two annotated items to be added
Cluster. name: my-application path.data: /home/esdata/data path.logs: /home/esdata/log network.host: 0.0.0.0 http.port: Http.coron. allow-origin: "*"Copy the code
Path. data and path.logs are the locations where ES data falls and can be adjusted. In this example, the above paths are used
vim config/jvm.options
Copy the code
You are advised to set the memory size to half of the vm memory. You can adjust the memory size based on actual conditions. For example, if the service pressure is not high, the CPU pressure will be high
If the service pressure is not high and the machine configuration allows, 1 GB can be written. In this example, 500 MB can be written. If the service pressure is high, adjust it based on the actual CPU pressure
This configuration item should already exist, do not need to add after, if you do not see it to see if it is commented
-Xms500m
-Xmx500m
Copy the code
Example Change the upper limit of file identifier size
vim /etc/sysctl.conf
Copy the code
Add at the end
vm.max_map_count=655360
Copy the code
Make the configuration take effect
sysctl -p
Copy the code
Again, change the file identifier
vim /etc/security/limits.conf
Copy the code
If there is, modify it, if there is not, add “this should have been there”. By default, it may be commented, so the four lines you added must be uncommented
root soft nofile 655370
root hard nofile 655370
* soft nofile 655370
* hard nofile 655370
Copy the code
This configuration file will take effect after modification, but it will not take effect in the current connection, so you need to open a new connection, if xshell is connected to the server, you need to open a new page
If you want to restart the server, reboot the server
ulimit -n
Copy the code
Check whether the configuration of file identifiers takes effect
Create elasticSearch user
adduser elasticsearch
passwd elasticsearch
Copy the code
Enter the password and remember it yourself
Grant permissions to the elasticSearch account ES folder, including the data store folder, and the elasticSearch application folder
Chown -r elasticSearch /home/esdata/ chown -r elasticSearch /home/ elasticSearch -6.6.2Copy the code
Switch to elasticSearch account and start ES
Su elasticSearch CD /home/elasticSearch -6.6.2./bin/ elasticSearch -d -p pidCopy the code
After startup, it will automatically run in the background, and generate a file named PID in the current directory, which records the PID of the ES process
Use this command to see if ES starts normally
curl localhost:9200
Copy the code
{
"name" : "-5ESl62"."cluster_name" : "my-application"."cluster_uuid" : "yxlA4dNJQPeei9KiUlVc9w"."version" : {
"number" : 6.6.2 ""."build_flavor" : "default"."build_type" : "tar"."build_hash" : "3bd3e59"."build_date" : "The 2019-03-06 T15:7. 864148 z"."build_snapshot" : false."lucene_version" : "7.6.0"."minimum_wire_compatibility_version" : "5.6.0"."minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
Copy the code
If this information is displayed, the ES service is started normally
Shut down
You can use this instruction to directly read the process PID in the PID file to close ES
pkill -F pid
Copy the code
Check the running status of the ES service
ps aux | grep elasticsearch
Copy the code
Root 10700 0.0 0.0 63048 460 PTS /1 S Aug11 0:00 su elasticSearch root 11939 0.0 0.1 63048 2484 PTS /4 S Aug11 0:00 su Elasticsearch elastic+ 15632 0.0 0.0 14428 996 PTS /4 S+ 14:52 0:00 grep --color=auto elasticSearchCopy the code
If this is displayed, the ES service has been shut down
If not, you can manually kill -9
Boot from the rev.
Using root permission
Create a elasticSearch. service file in the /etc/systemd/system directory
cd /etc/systemd/system
vim elasticsearch.service
Copy the code
Write the following, where
User is adjusted according to the account you created for ES
ExecStart adjusts itself based on your ES file directory
[Unit] Description=elasticsearch [Service] User=elasticsearch LimitNOFILE=100000 LimitNPROC=100000 ExecStart = / home/elasticsearch 6.6.2 / bin/elasticsearch [Install] WantedBy = multi - user. TargetCopy the code
Enable automatic startup
systemctl enable elasticsearch
Copy the code
You can now start ES as root.
systemctl start elasticsearch
Copy the code
Reference documentation
Java installation and Configuration in Ubuntu 16.04
ES Installation and Deployment
CentOS 7 ElasticSearch Service Starts automatically upon startup
Further reading
Summary – ElasticSearch startup failure cases and solutions