In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to deploy java projects under Linux", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "How to deploy java projects under Linux"!
1. Prepare VMware2. Install Linux system (Fedora version installed by myself) 3. Install jdk
Fedora actually comes with OpenJDK. Version information can be viewed using java -version. Here are the steps to download jdk from the official website.
Click here to download x86 for 32-bit computers and x64 for 64-bit computers. Note the two Linux versions marked with arrows to download.
Use xshell and xftp tools to transfer files to Linux virtual machines, tools download links
Refer to Fedora's documentation and replace jdk with the one you downloaded online. Create a folder:
sudo mkdir -p /usr/local/java
Move the archive to this folder and extract it:
sudo cp -r jdk-8u40-linux-x64.tar.gz /usr/local/javasudo tar xvzf jdk-8u45-linux-x64.tar.gz
Configure environment variables:
sudo nano /etc/profile//Add JAVA_HOME=/usr/local/java/jdk1.8.0_45PATH=$PATH:$HOME/bin:$JAVA_HOME/binexport JAVA_HOMEexport PATH at the end of the file
Settings tell the system that a new Oracle Java version is available:
sudo update-alternatives --install" / usr / bin / java"" java"" /usr/local/java/jdk1.8.0_45/bin/java"sudo update-alternatives --install" / usr / bin / javac"" javac"" /usr/local/java/jdk1.8.0_45/bin/javac" 1sudo update-alternatives --install" /usr/bin/javaws.itweb"" javaws.itweb"" /usr/local/java/jdk1.8.0_45/bin/javaws.itweb" 1
Set Oracle Java JDK to default values:
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/javasudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javacsudo update-alternatives --set javaws.itweb /usr/local/java/jdk1.8.0_45/bin/javaws.itweb
Reload configuration file:
source /etc/profile
Restart the system:
reboot
View Java version:
java -version4, install tomcat to the official website Download tomcat Linux version of the compressed package through xshell and xftp tools transferred to the linux system also create a folder to accept storage compressed package decompression compressed package, enter tomcat bin directory, start./ startup.sh You can see the tomcat startup interface by typing ip+:8080 in your browser on the host computer. 5. Install MySQL
I installed it directly with yum, but the latest download is not mysql but mariaDB, a database similar to mysql. yum install -y mysql-server mysql mysql-devel can automatically install mysql, but after installation, I started mysql and the following problems occurred:
[root@localhost ~]# systemctl start mysql.serviceFailed to start mysql.service: Unit mysql.service not found.
The solution is as follows:
# yum install mariadb-server -y //if installed can omit # systemctl start mariadb.service //startup service # systemctl enable mariadb.service //startup service # mysql -u root -p //login mysql
For security purposes, we're also going to do a database hardening:
[root@~ localhost]#mysql_secure_installation #Database Security Hardening NOTE: RUNNING ALL PARTS OF THIS Script IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the currentpassword for the root user. If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): #Default password is empty, so just press Enter! OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] Y New password:Re-enter new password:Password updated successfully! #Password set successfully Reloading privilege tables... Success! By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] Y #Remove anonymous users... Success! Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] Y #Do not allow root remote logins... Success! By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] n #Remove test database and disable access to... skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] Y #Overload permission table... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!
After completion, you can start MySQL service for login, database creation and table creation operations. You can export the SQL script in the local machine and send it to the virtual machine to import it by using the source+ path. For example: source/etc/local/SQLfile/javaweb.sql I have another method here, which is to enable the MariaDB remote service, so that we can connect to the MariaDB service in the virtual machine with the Navicat of the local machine. Start by creating a user and granting him all permissions:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
Here is to create a root user, his password is 123456, enjoy various privileges, this is used to log in on the local Navicat. Don't forget to refresh your permissions afterwards:
FLUSH PRIVILEGES;
Then you can connect to Navicat:
Java project packaging
If you are a springboot project, you can package it directly into a jar package, put it anywhere in the virtual machine, and use java -jar ProjectName to run it. Method 1: How to package jar package:
First modify the pom file this place, change to jar bring up the maven window on the right, click clean and install in turn will appear in the project a target directory, in this directory you can see the packaged files.
Method 2:
If it is a normal maven project, it needs to be packaged as a war package and placed in tomcat's webapps directory. The method of packaging war packages is similar to that of packaging jars, except that the jar part above needs to be changed to war.
the problems encountered
xshell connection does not connect to virtual machine
Solution: Fedora does not have ssh enabled, use the command
# service sshd start
Fedora cannot switch to root
Solution: This is because there is no root generated by default when installing. Here we need to initialize a root by using the following command:
# sudo su# passwd root//Enter the password twice, note that the password number cannot be less than 8 digits
Set up ssh service boot to start automatically
Since the virtual machine needs to restart the ssh service after each boot, we simply add it to the boot entry and allow it to boot itself. Setting method:
Set up automatic boot # systemctl enable sshd Close automatic boot # systemctl disable sshd After setting up, restart the computer # reboot to this point, I believe everyone has a deeper understanding of "how to deploy java projects under Linux," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.