Centos7.4搭建环境,JDK1.8、Tomcat9、MyS
Yum安装MySQL和JDK是在线下载,文件大下得慢,本人懒得等,所有安装文件先下载好再通过FTP传输到服务器
所有资源已上传到百度云,不知道允不允许分享百度云链接所以没有粘贴,需要的可评论
[toc]
环境版本简介
- Linux各类环境
- Linux:CentOS 7.4 64位
- Java 1.8:JDK-8u181-linux-x64.tar.gz
- MySql:mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar(Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), RPM Bundle)
- FTP:vsftpd
- 可视化工具
- Linux:Xshell 6 Build 0095
- MySql:SQLyog 12.5.1或Navicat 12 for MySQL
- FTP:FileZilla Client 3.35.2
vi/vim操作介绍
操作输入(按ESC,输入的时候在底部展示代码)
insert:插入内容
清空文件内容
:.,$d
保存并退出文本
:wq
不保存并不保存文本
:q!
一、登录服务器
安装Xshell 6 并启动,分别输入服务器公网IP,远程连接的帐号和密码
[图片上传失败...(image-68361a-1536306382381)]
[图片上传失败...(image-335e2d-1536306382381)]
[图片上传失败...(image-cf7810-1536306382381)]
[图片上传失败...(image-d32fae-1536306382381)]
二、搭建FTP
Linux命令
yum -y install vsftpd
启动FileZilla Client,文件-站点管理器-按图输入(公网IP、服务器帐号和密码)
[图片上传失败...(image-5c6ea2-1536306382381)]
[图片上传失败...(image-657e35-1536306382381)]
进相应目录,创建文件夹,并分别拉压缩文件进去(实际放去哪都行)
[图片上传失败...(image-c73a55-1536306382381)]
[图片上传失败...(image-21723d-1536306382381)]
[图片上传失败...(image-b0a043-1536306382381)]
三、Linux命令解压文件
cd /usr/local/mysql
tar -xvf mysql-8.0.12.tar
cd /usr/local/tomcat
tar -xzvf apache-tomcat-9.0.10.tar.gz
cd /usr/local/java
tar -xzvf jdk-8u181-linux-x64.tar.gz
apache-tomcat-9.0.10.tar.gz和jdk-8u181-linux-x64.tar.gz各解压出一个文件夹,
我把各自文件夹内的所有东西分别拖动至/usr/local/tomcat和/usr/local/java
使用FileZilla Client查看并拖动
四、安装JDK
Linux命令
vim /etc/profile
文本尾部粘贴,环境变量
export JAVA_HOME=/usr/local/java
export JRE_HOME=$JAVA_HOME/jre
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
保存并退出,ESC后输入
:wq
使环境变量的文件立即生效:
source /etc/profile
查看Java版本
java -version
成功结果如图:
[图片上传失败...(image-cdcfe1-1536306382381)]
五、安装tomcat
启动和关闭tomcat
/usr/local/tomcat/bin/startup.sh
/usr/local/tomcat/bin/shutdown.sh
六、安装MySql
一、必须先卸载原有的mariadb
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs
二、安装SQL
cd /usr/local/mysql
rpm -ivh mysql-community-common-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.12-1.el7.x86_64.rpm
yum install libnuma*
rpm -ivh mysql-community-server-8.0.12-1.el7.x86_64.rpm
yum install openssl
yum install openssl-devel
rpm -ivh mysql-community-devel-8.0.12-1.el7.x86_64.rpm
三、初始化SQL
1、启动、关闭和开机启动SQL
systemctl start mysqld
systemctl stop mysqld
systemctl enable mysqld
2、必须修改随机密码
cat /var/log/mysqld.log | grep password
*结果:
2018-08-17T01:53:42.653589Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tC9lp;PokHG
帐号@ip: 密码 root@localhost: tC*9lp;PokHG 密码是tC*9lp;PokHG
登录mysql并开启远程访问(Windows/Mac可视化工具连接数据库)
mysql -u root -p(回车)
(可粘贴输入密码,回车)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';(必须同时包含大小写字母、数字和符号)
exit(回车)
mysql -u root -p(回车)
(输入新密码,回车)
use mysql;
update user set host='%' where user='root';(%为所有ip都可以远程访问)
FLUSH PRIVILEGES;(刷新生效)
exit
3.设置开机自启动
如果要开机自启动tomcat,配置如下:
chmod +x /etc/rc.d/rc.local
vi /etc/rc.d/rc.local
在文件尾部添加下面几行:
export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
/usr/local/tomcat/bin/startup.sh
(:wq保存并退出)
七、开启防火墙并打开相关端口
Linux开启端口后,阿里云/腾讯云的控制台的云服务器的设置相关的配置安全组(打开端口)
Linux开启端口
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
默认端口(修改端口可谷歌百度)
My SQL:3306
Tomcat :8080
防火墙命令(参考)
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
八、连接数据库,测试Tomcat
地址栏输入:公网:8080,成功结果如图
[图片上传失败...(image-287e6d-1536306382381)]
SQLyog for Win连接云服务器的MySQL
[图片上传失败...(image-563289-1536306382381)]
成功结果
[图片上传失败...(image-5c7e95-1536306382381)]
九、Tomcat配置域名
参考:
https://blog.csdn.net/qq_36731677/article/details/60154115
https://blog.csdn.net/omelon1/article/details/78752828
1、阿里云的域名,在域名的解析设置,将域名指向一个IPV4地址(服务器公网IP)
2、打开编辑文件
cd /usr/local/tomcat/conf
vim server.xml
修改端口(修改后无需域名/IP:8080,只要在地址栏输入域名或公网IP)
修改前
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
修改后
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
指定域名
修改前
<Host name="localhost" 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 "%r" %s %b" />
</Host>
修改后
<Host name="www.llliuweijian.top" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="" reload="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 "%r" %s %b" />
</Host>
参考文章
https://www.jianshu.com/p/88b4d86f3b1c
https://blog.csdn.net/jared456/article/details/80380853
https://blog.csdn.net/envon123/article/details/76683432
若干...