[Super Connection: Linux+Solr+Zookeeper Series - Chapter 1]
This article mainly explains how to build Solr service on Linux server and make it a Service service.
The Solr service built in this paper is non-clustered (non-SolrCloud mode), and is only used for Solr's single service use.
1. environment
- Ubuntu 16.04 LTS
- jdk1.8.0_161
- solr-6.6.0
2. Install JDK and configure environment variables
Install JDK:
//Decompression package
tar -zxvf jdk-8u161-linux-x64.tar.gz
//Copy the jdk directory to / user/local / directory
sudo cp -r jdk1.8.0_161 /usr/local/
Modify environment variables:
//Install vim command
sudo apt install vim
//Editing System Configuration
sudo vim /etc/profile
Add the following configuration at the end of / etc/profile:
JAVA_HOME=/usr/local/jdk1.8.0_161
JRE_HOME=/usr/local/jdk1.8.0_161/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
Make configuration effective:
//View the current configuration
hanchao@hanchao-virtual-machine:/etc$ echo $PATH
/home/hanchao/bin:/home/hanchao/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
//Take effect
hanchao@hanchao-virtual-machine:/etc$ source /etc/profile
//Look at the current configuration again
hanchao@hanchao-virtual-machine:/etc$ echo $PATH
/home/hanchao/bin:/home/hanchao/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/jdk1.8.0_161/bin:/usr/local/jdk1.8.0_161/jre/bin
View the JDK version
hanchao@hanchao-virtual-machine:/etc$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
3. Download, install and start Solr
Old version of solr download address:
Download solr-6.6.0.tgz
Install Solr:
//decompression
tar -zxvf solr-6.6.0.tgz
//Store the decompressed directory in the specified directory
mv /home/hanchao/solr-6.6.0/ /usr/local/
Start up service:
hanchao@hanchao-virtual-machine:~$ /usr/local/solr-6.6.0/bin/solr start
Waiting up to 180 seconds to see Solr running on port 8983 [\]
Started Solr server on port 8983 (pid=2404). Happy searching!
Test services:
Enter in the browser: http://localhost:8983/solr/ If you can successfully enter the Solr Admin background, the service starts successfully.
Shut down service:
hanchao@hanchao-virtual-machine:~$ /usr/local/solr-6.6.0/bin/solr stop
4.Solr is registered as Service Service Service
Copy installation packages to bin directory:
//Copy solr-6.6.0.tgzto solr/bin Directory
hanchao@hanchao-virtual-machine:~/download $ cp solr-6.6.0.tgz /usr/local/solr-6.6.0/bin/
hanchao@hanchao-virtual-machine:~/download $ cd /usr/local/solr-6.6.0/bin/
hanchao@hanchao-virtual-machine:/usr/local/solr-6.6.0/bin$ ls
init.d install_solr_service.sh oom_solr.sh post solr solr-6.6.0.tgz solr.cmd solr.in.cmd solr.in.sh
Registration services:
//Register the service through the install_solr_service.sh script
hanchao@hanchao-virtual-machine:/usr/local/solr-6.6.0/bin$ ./install_solr_service.sh solr-6.6.0.tgz
ERROR: This script must be run as root
//This script can only be executed under the root user, switching users
hanchao@hanchao-virtual-machine:/usr/local/solr-6.6.0/bin$ su
//Password:
//Register the service again through the install_solr_service.sh script
root@hanchao-virtual-machine:/usr/local/solr-6.6.0/bin# ./install_solr_service.sh solr-6.6.0.tgz
id: "solr": no such user
Creating new user: solr
//Adding System Users"solr" (UID 121)...
//Adding a new group"solr" (GID 129)...
//New users are on the way"solr" (UID 121)Add to group"solr"...
//Create a home directory"/var/solr"...
Extracting solr-6.6.0.tgz to /opt
Installing symlink /opt/solr -> /opt/solr-6.6.0 ...
Installing /etc/init.d/solr script ...
Installing /etc/default/solr.in.sh ...
Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
● solr.service - LSB: Controls Apache Solr as a Service
Loaded: loaded (/etc/init.d/solr; bad; vendor preset: enabled)
Active: active (exited) since day 2018-04-08 11:09:57 CST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 6210 ExecStart=/etc/init.d/solr start (code=exited, status=0/SUCCESS)
4month 08 11:09:45 hanchao-virtual-machine systemd[1]: Starting LSB: Controls Apache Solr as a Service...
4month 08 11:09:45 hanchao-virtual-machine su[6212]: Successful su for solr by root
4month 08 11:09:45 hanchao-virtual-machine su[6212]: + ??? root:solr
4month 08 11:09:45 hanchao-virtual-machine su[6212]: pam_unix(su:session): session opened for user solr by (uid=0)
4month 08 11:09:57 hanchao-virtual-machine solr[6210]: [190B blob data]
4month 08 11:09:57 hanchao-virtual-machine solr[6210]: Started Solr server on port 8983 (pid=6290). Happy searching!
4month 08 11:09:57 hanchao-virtual-machine solr[6210]: [8B blob data]
4month 08 11:09:57 hanchao-virtual-machine systemd[1]: Started LSB: Controls Apache Solr as a Service.
Operating Solr services through service:
//Startup service
sudo service solr start
//Out of Service
sudo service solr stop
//Restart service
sudo service solr restart
//View the running status
sudo service solr status