centos7.5安裝java JDK、tomcat、mysql


參考資料:

https://www.cnblogs.com/sxdcgaq8080/p/7492426.html

https://blog.csdn.net/ds986619036/article/details/80885917

https://blog.csdn.net/ds986619036/article/details/80885917

https://blog.csdn.net/Rain_xiaolong/article/details/80569972

騰訊雲服務器配置環境前請先設置安全組

 

 

jdk安裝

1.先檢查原服務器上是否已經安裝了java jdk,如果已安裝可以先卸載

 

 

 2.下載jdk:jdk-8u212-linux-x64.tar.gz

3.將jdk復制到/usr/local/src/下(可以使用xftp傳輸)

4.解壓:先定位到當前目錄

執行解壓命令:tar  -zxvf  jdk-8u212-linux-x64.tar.gz

5.配置環境變量

5.1執行:vim /etc/profile   打開文件

5.2移動光標到末尾

5.3在末尾追加:

#java environment
export JAVA_HOME=/usr/local/src/jdk1.8.0_212
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

 

 

 執行:esc

執行::wq!

 

 

5.4刷新配置文件,驗證JDK是否配置成功:

先定為到 /etc目錄,然后執行

source /etc/profile

java -version

 

 

tomcat安裝

1.下載:https://tomcat.apache.org/download-90.cgi

 

2.將jtomcat復制到/usr/local/src/下(可以使用xftp傳輸)

3.解壓:tar -axvf   apache-tomcat-9.0.29.tar.gz

4.配置環境變量

 vim /etc/profile

做如下配置:

 

 

 刷新配置:

 

 

 5.修改端口及域名指向

將/usr/local/src/apache-tomcat-9.0.29/conf下的server.xml下載到自己電腦上

端口號修改為80

    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

綁定網站

 <Host name="java.xxx.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
               
               
               
    <Context path="/" docBase="web_ssm.war" debug="0" previledge="true" reloadable="true"/>

      </Host>

 如需要綁定多個域名,可以增加多個Host節點

********如上配置運行網站時報錯如下:************************

Tomcat Manager App--403 Access Denied You are not authorized to view this page

解決方案是:

修改webapps/manager/META-INF//META-INF/context.xml

將value標簽注釋掉

 

 **************再次運行網站報錯如下:*******************

404 Not found

The page you tried to access (/manager/index) does not exist.

The Manager application has been re-structured for Tomcat 7 onwards and some of URLs have changed. All URLs used to access the Manager application should now start with one of the following options:

  • /manager/html for the HTML GUI
  • /manager/text for the text interface
  • /manager/jmxproxy for the JMX proxy
  • /manager/status for the status pages

Note that the URL for the text interface has changed from "/manager" to "/manager/text".

You probably need to adjust the URL you are using to access the Manager application. However, there is always a chance you have found a bug in the Manager application. If you are sure you have found a bug, and that the bug has not already been reported, please report it to the Apache Tomcat team.

 

 

URL 不能以/manager開頭,將所有以/manager開頭的url改掉就解決了

 

 

 

6.把war包放到tomcat安裝目錄下的webapps目錄 

7.開啟80端口

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent 

7.1重啟防火牆

sudo systemctl restart firewalld.service

8.啟動和關閉tomcat

啟動:/usr/local/src/apache-tomcat-9.0.29/bin/startup.sh
關閉:/usr/local/src/apache-tomcat-9.0.29/bin/shutdown.sh

9.設置開機自動啟動

9.1在目錄/usr/local/src/apache-tomcat-9.0.29/bin創建setenv.sh文件

#catalina.sh在執行的時候會調用同級路徑下的setenv.sh來設置額外的環境變量

文件內容:

export CATALINA_HOME=/usr/local/src/apache-tomcat-9.0.29
export CATALINA_BASE=/usr/local/src/apache-tomcat-9.0.29
#設置Tomcat的PID文件
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#添加JVM選項
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

9.2編寫tomcat.service文件,在/usr/lib/systemd/system路徑下添加tomcat.service文件,內容如下:

 

[Unit]
Description=Tomcat9.0.29
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking

PIDFile=/usr/local/src/apache-tomcat-9.0.29/tomcat.pid
ExecStart=/usr/local/src/apache-tomcat-9.0.29/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

9.3設置開機啟動tomcat.service

systemctl enable tomcat.service

9.4啟動tomcat

systemctl start tomcat.service

**********報錯如下:***************************************************

Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.

執行:systemctl status tomcat.servic  查看詳細報錯詳細如下:

● tomcat.service - Tomcat9.0.29
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-12-05 17:43:06 CST; 21s ago
Process: 6097 ExecStart=/usr/local/src/apache-tomcat-9.0.29/bin/startup.sh (code=exited, status=1/FAILURE)

Dec 05 17:43:06 VM_0_2_centos systemd[1]: Starting Tomcat9.0.29...
Dec 05 17:43:06 VM_0_2_centos startup.sh[6097]: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
Dec 05 17:43:06 VM_0_2_centos startup.sh[6097]: At least one of these environment variable is needed to run this program
Dec 05 17:43:06 VM_0_2_centos systemd[1]: tomcat.service: control process exited, code=exited status=1
Dec 05 17:43:06 VM_0_2_centos systemd[1]: Failed to start Tomcat9.0.29.
Dec 05 17:43:06 VM_0_2_centos systemd[1]: Unit tomcat.service entered failed state.
Dec 05 17:43:06 VM_0_2_centos systemd[1]: tomcat.service failed.

 

 解決錯誤:

修改/usr/local/src/apache-tomcat-9.0.29/bin下的catalina.sh 文件,在文件頂部加入如下代碼:

export JAVA_HOME=/usr/local/src/jdk1.8.0_212
export JRE_HOME=/usr/local/src/jdk1.8.0_212/jre 

 重新啟動tomcat:systemctl start tomcat.service

重新查看tomcat服務狀態:systemctl status tomcat  

 

 

9.5.常用命令

開機啟動
systemctl enable tomcat.service
移除開機啟動
systemctl disable tomcat.service
開機禁止啟動
systemctl disable tomcat.service
啟動tomcat
systemctl start tomcat.service
關閉tomcat
systemctl stop tomcat.service
重啟
systemctl restart tomcat.service

mysql安裝

 1.下載安裝包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

下載到/usr/local/src目錄下面

 

 

 2.安裝mysql源

 

 

 3.檢查mysql源是否安裝成功

yum repolist enabled | grep "mysql.*-community.*"

 

 

 4.安裝MySQL服務端

yum install mysql-community-server

5.啟動MySQL服務

等同於命令:systemctl start mysqld
service mysqld start

 

 

 

重啟命令是:service mysqld restart

6.檢查mysql 的運行狀態

service mysqld status

 

 

 7.修改root本地登錄密碼

7.1查看初始密碼

grep 'temporary password' /var/log/mysqld.log

 

 

 

 7.2用初始密碼登錄

mysql -uroot -p


 

 

 

7.3修改初始密碼

set password for 'root'@'localhost'=password('密碼'); 

 

 

 

注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password),默認密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤

8.授權其他機器登陸

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root@123456' WITH GRANT OPTION;

FLUSH  PRIVILEGES;

9.退出mysql

 

 

 

10.防火牆開啟3306端口

10.1執行:sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent 

********報錯如下:防火牆未開啟*******

 

10.2開啟防火牆

 通過systemctl status firewalld查看firewalld狀態,發現當前是dead狀態,即防火牆未開啟。

 

 通過systemctl start firewalld開啟防火牆,沒有任何提示即開啟成功。

 

 

 再次通過systemctl status firewalld查看firewalld狀態,顯示running即已開啟了。

 

 如果要關閉防火牆設置,可能通過systemctl stop firewalld這條指令來關閉該功能。

10.3防火牆開啟3306端口

sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent 

 

 10.4重啟防火牆

sudo systemctl restart firewalld.service

 

 10.5查看所有開啟的端口命令:firewall-cmd --list-ports

 

 11.測試連接:

 

 12.設置mysql開機啟動

 

 

systemctl enable mysqld
systemctl daemon-reload

 

13.mysql命令

停止
service mysqld stop
開啟
service mysqld start
重啟
service mysqld restart

 

14.mysql部署到服務器時經常報錯如下:

### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 141,839,270 milliseconds ago. The last packet sent successfully to the server was 141,839,271 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
### The error may exist in file [/usr/local/src/apache-tomcat-9.0.29/webapps/ROOT/WEB-INF/classes/com/eggtwo/euq/entity/MemberMapper.xml]
### The error may involve com.eggtwo.euq.dao.MemberMapper.selectByLoginName-Inline
### The error occurred while setting parameters
### SQL: select id, loginName, saltKey, loginPassword, relName, email, phone, admin, deleted, createdTime from mms_member where loginName = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 141,839,270 milliseconds ago. The last packet sent successfully to the server was 141,839,271 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
; SQL []; The last packet successfully received from the server was 141,839,270 milliseconds ago. The last packet sent successfully to the server was 141,839,271 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 141,839,270 milliseconds ago. The last packet sent successfully to the server was 141,839,271 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

解決方案如下:

參考:https://blog.csdn.net/qiushisoftware/article/details/77718634

https://developer.aliyun.com/ask/78524?spm=a2c6h.13159736

https://msd.misuland.com/pd/3255818066314920538

第一步:查找my.cnf文件,查找的結果是在/etc目錄下

 

 修改my.cnf文件:

修改MySQL的參數,wait_timeout最大為31536000即1年,在my.cnf中加入:

wait_timeout=31536000
interactive_timeout=31536000

 

 重啟mysql服務

service mysqld restart

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM