您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Linux下怎么部署java項目”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“Linux下怎么部署java項目”吧!
其實Fedora本身就自帶的有OpenJDK??梢允褂胘ava -version查看版本信息。這里介紹去官網(wǎng)自己下載jdk的步驟。
在官網(wǎng)下載jdk 下載點擊這里 32位的電腦就下載x86,如果是64位就下載x64。注意要下載Linux版本用箭頭標(biāo)注的兩個。
使用 xshell 和 xftp 工具將文件傳輸?shù)絃inux虛擬機中,工具下載鏈接
參照Fedora的文檔進行操作,將jdk替換為自己在網(wǎng)上下載的。 創(chuàng)建一個文件夾:
sudo mkdir -p /usr/local/java
將壓縮包移動到該文件夾并進行解壓:
sudo cp -r jdk-8u40-linux-x64.tar.gz /usr/local/java sudo tar xvzf jdk-8u45-linux-x64.tar.gz
配置環(huán)境變量:
sudo nano /etc/profile // 在文件末尾添加 JAVA_HOME=/usr/local/java/jdk1.8.0_45 PATH=$PATH:$HOME/bin:$JAVA_HOME/binexport JAVA_HOMEexport PATH
設(shè)置告訴系統(tǒng)新的Oracle Java版本可用:
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” 1 sudo update-alternatives --install“ /usr/bin/javaws.itweb”“ javaws.itweb”“ /usr/local/java/jdk1.8.0_45/bin/javaws.itweb” 1
將Oracle Java JDK設(shè)置為默認(rèn)值:
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/java sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javac sudo update-alternatives --set javaws.itweb /usr/local/java/jdk1.8.0_45/bin/javaws.itweb
重新加載配置文件:
source /etc/profile
重啟系統(tǒng):
reboot
查看java版本:
java -version
我是直接用yum進行安裝,不過最新下載下來的不是mysql而是和mysql差不多的數(shù)據(jù)庫mariaDB。 yum install -y mysql-server mysql mysql-devel 可以自動安裝好mysql 不過安裝好之后我啟動mysql之后出現(xiàn)了如下問題:
[root@localhost ~]# systemctl start mysql.serviceFailed to start mysql.service: Unit mysql.service not found.
解決方法如下:
# yum install mariadb-server -y //如果已安裝可以省略# systemctl start mariadb.service //啟動服務(wù)# systemctl enable mariadb.service //開機啟動服務(wù)# mysql -u root -p //登錄mysql
為了安全,我們還要進行一次數(shù)據(jù)庫加固:
[root@~ localhost]#mysql_secure_installation #數(shù)據(jù)庫安全加固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 current password for the root user. If you've just installed MariaDB, and you 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): #默認(rèn)密碼為空,故只按回車鍵!密碼為空不安全,需要首先設(shè)置 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y #是否設(shè)置root的登錄密碼:Y需要設(shè)置 New password: Re-enter new password: Password updated successfully! #密碼已設(shè)置成功 Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y #是否移除anonymous用戶 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y #是否不允許root的遠(yuǎn)程登錄 ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] n #是否移除test數(shù)據(jù)庫,并禁止訪問 ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y #是否重載權(quán)限表 ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
完成之后,就可以啟動MySQL服務(wù)進行登錄,建庫和建表操作。可以將本機中的sql腳本導(dǎo)出然后發(fā)送到虛擬機中使用 source+路徑的方式進行導(dǎo)入 例如:source /etc/local/SQLfile/javaweb.sql 我這里還有另外一種方法,就是開啟MariaDB的遠(yuǎn)程服務(wù),讓我們用本機的Navicat即可連接到虛擬機中的MariaDB服務(wù)。開啟方法: 首先創(chuàng)建一個用戶,并賦予他所有的權(quán)限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
這里就是創(chuàng)建了一個root用戶,他的密碼是123456,享受各種權(quán)限,這個用來在本機的Navicat上進行登錄。之后不要忘記刷新權(quán)限:
FLUSH PRIVILEGES;
之后就可以在Navicat上進行連接了:
這里還要區(qū)分一下,如果你是springboot項目,那么就可以直接打包成為jar包,放在虛擬機任意位置,使用java -jar ProjectName 即可運行。 方法一:打包jar包的方法:
方法二:
如果是普通的maven項目,需要打包成為war包,然后放在tomcat的webapps目錄中。 打包war包的方法與打包jar類似,只有一個步驟不一樣,那就是上邊jar部分需要改成war。
xshell連接不上虛擬機
解決:Fedora中沒有開啟ssh服務(wù),使用命令
# service sshd start
Fedora不能切換到root用戶
解決: 這個是因為安裝的時候沒有默認(rèn)生成root,這里需要我們初始化一個root,使用如下命令:
# sudo su# passwd root// 之后輸入兩次密碼即可,注意密碼位數(shù)不能小于8位
設(shè)置ssh服務(wù)開機自啟動
由于虛擬機每次啟動之后都要重新開啟一下ssh服務(wù),所以這里我們索性直接將它加入到開機啟動項中,允許其開機自啟。設(shè)置方法:
設(shè)置開機自動啟動# systemctl enable sshd關(guān)閉開機自動啟動# systemctl disable sshd設(shè)置好之后重啟電腦即可# reboot
到此,相信大家對“Linux下怎么部署java項目”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。