centos java安装 域名_centos7.5安装java JDK、tomcat、mysql

参考资料:

腾讯云服务器配置环境前请先设置安全组

f33ec35d3d9da80f220e0862c98cf854.png

jdk安装

1.先检查原服务器上是否已经安装了java jdk,如果已安装可以先卸载

5bb45b2c16375e0698319a78b3a35a79.png

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

5028ef5216bd2b63056a1f1073951b18.png

执行:esc

执行::wq!

5.4刷新配置文件,验证JDK是否配置成功:

先定为到 /etc目录,然后执行

source /etc/profile

java -version

00f3abd1947b545a24e1a390625ff89e.png

tomcat安装

372435bed8f71870760fb13e5bb8882b.png

2.将jtomcat复制到/usr/local/src/下(可以使用xftp传输)

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

4.配置环境变量

vim /etc/profile

做如下配置:

c93ae6071f4145c30696cbbfd488fd9b.png

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

export TOMCAT_HOME=/usr/local/src/apache-tomcat-9.0.29

export CATALINA_HOME=/usr/local/src/apache-tomcat-9.0.29

export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar

export PATH=$PATH:${JAVA_HOME}/bin:${TOMCAT_HOME}/bin

刷新配置:

207634d6108666dc369f7ba38de92af3.png

5.修改端口及域名指向

将/usr/local/src/apache-tomcat-9.0.29/conf下的server.xml下载到自己电脑上

端口号修改为80

绑定网站

如需要绑定多个域名,可以增加多个Host节点

注意:server.xml绑定的网站在webapps中一定要存在,不然 启动tomcat时会报错

********如上配置运行网站时报错如下:************************

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

0df56862a560c7be00a329b2dc72fd1d.png

解决方案是:

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

将value标签注释掉

075de887b21dd82ae12b51a4bb9a1032.png

**************再次运行网站报错如下:*******************

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.

e685054943721a872ca124cd27f325c3.png

URL 不能以/manager开头,将所有以/manager开头的url改掉就解决了

6.把war包放到tomcat安装目录下的webapps目录

删除webapps目录下的examples和docs目录

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

查看tomcat启动日志判断是否 启动成功:

首先定位到/usr/local/src/apache-tomcat-9.0.29/logs目录,然后执行:

tail -f catalina.out

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.29export 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.29After=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.

837ce9f4af1a2f617caa262be3409742.png

解决错误:

修改/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

b3b0ca797baa868c792d9dd42e9aa7ec.png

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目录下面

3c41727cfee37f4fa59e3aceee3615f4.png

2.安装mysql源

03f26e7baea1ce59df02a2406699164e.png

3.检查mysql源是否安装成功

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

c627f3632778acca2e8b5c5e014bae62.png

4.安装MySQL服务端

yum install mysql-community-server

5.启动MySQL服务

等同于命令:systemctl start mysqld

service mysqld start

0bd9f9d5ed5bebb3a6830256475cfc8b.png

重启命令是:service mysqld restart

6.检查mysql 的运行状态

service mysqld status

ba2ed34ea21b85d4e05cb82b3b820514.png

7.修改root本地登录密码

7.1查看初始密码

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

7a7333b1cc8148e6e79593b5824a41fe.png

7.2用初始密码登录

mysql -uroot -p

15e195cd48d886de9b29cce41183e2bc.png

7.3修改初始密码

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

b138c8f8ed2f0d1be620af7255766959.png

注意: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 '设置的密码'WITH GRANT OPTION;

FLUSH PRIVILEGES;

196890db0085e58de182ef6d344feea8.png

9.退出mysql

2c074434cad200fbf94caff71b5f120f.png

10.防火墙开启3306端口

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

********报错如下:防火墙未开启*******

a601cd26f0596635c74536b45d8c1821.png

10.2开启防火墙

通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。

cd221b8e4d5d4dc50b400975e3e2bb53.png

通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。

660add8fe19b3a4ea55c8498352e69ec.png

再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。

09e9e2079d63b0c1d38e476420287044.png

如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。

10.3防火墙开启3306端口

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

2ff9c2eae4f3a79bfa8c3bdf71bcdc23.png

10.4重启防火墙

sudo systemctl restart firewalld.service

558fef8b28523060e32b148c227c7bf6.png

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

940c0d9dff9eed0afd3edb355cfa07ac.png

11.测试连接:

ad3e9c552ebd0d947892fe92428ebffe.png

12.设置mysql开机启动

systemctl enable mysqld

systemctl daemon-reload

fc1ceb8c94ca1e69898d5e27b6e1851e.png

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.

解决方案如下:

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

84f2773636b51cfe641260f49e5f79e2.png

修改my.cnf文件:

修改MySQL的参数,wait_timeout最大为31536000即1年,在my.cnf中加入:

wait_timeout=31536000interactive_timeout=31536000

526d40a814a85e6a1b7038bcb49aabb8.png

重启mysql服务

service mysqld restart

89fb951f07b1b43380696ae76daff02a.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值