杨校老师课堂之Java项目部署到云端服务器之安装MySQL、Jdk、Tomcat

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 杨校老师课堂之Java项目部署到云端服务器之安装MySQL、Jdk、Tomcat
部署项目到公网上去思路剖析

· 公网服务器
  · 数据库
    ·     下载、安装、配置、远程连接
                   ·  使用本地的Navicat去远程连接 操作数据库 
  · JDK   安装Tomcat的前提 
  · tomcat 
    ·目录结构
      · webapps
         ·放入你的项目
拥有一台服务器,安装centos系统
  1. Centos7.x
 # 安装Centos的wget插件
   yum  install wget  -y
    # MySQL的选择网站:http://repo.mysql.com/  网站有诸多版本,选择合适的下载即可。
    # 如下,我选择的是MySQL5.7
   wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
安装MySQL5.7
sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm

sudo yum install mysql-server

效果图如下:

效果图如下:

安装细节
  1. 安装MySQL过程中,如果是安装的MySQL5.6,安装后默认密码是为空的,可直接进入数据库的,若是安装的是Mysql5.7就需要初始密码
  2. 若不想查询初始密码,可以跳过MySQL权限验证操作,进入数据库进行修整密码,然后在打开权限验证即可。
# 方式一: 查询初始密码:
mysql5.6安装后默认密码是为空的,可直接进入数据库的,但是mysql5.7就需要初始密码 
2. cat /var/log/mysqld.log | grep password 查询MySQL5.7密码
3.     [root@izb6rc3amsrxv6z local]# cat /var/log/mysqld.log | grep password
       # 初始化密码: soadrod;c9Pr
       2020-04-16T01:34:20.422336Z 1 [Note] A temporary password is generated for root@localhost: soadrod;c9Pr
       2020-04-16T01:52:45.445074Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T01:52:45.445078Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T01:52:54.766386Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
       2020-04-16T02:30:43.300676Z 0 [Note] Shutting down plugin 'validate_password'
       2020-04-16T02:30:44.813774Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:30:44.813777Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:42:29.107064Z 0 [Note] Shutting down plugin 'validate_password'
       2020-04-16T02:42:30.119448Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:42:30.119451Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:43:33.339551Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:43:33.339554Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:45:39.090209Z 0 [Note] Shutting down plugin 'validate_password'
       2020-04-16T02:45:40.607605Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:45:40.607608Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:49:08.842072Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:49:08.842075Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:49:25.046531Z 0 [Note] Shutting down plugin 'sha256_password'
       2020-04-16T02:49:25.046534Z 0 [Note] Shutting down plugin 'mysql_native_password'
       2020-04-16T02:53:45.817187Z 8 [Note] Access denied for user 'root'@'localhost' (using password: YES)
       2020-04-16T02:59:24.456338Z 14 [Note] Access denied for user 'root'@'223.96.218.217' (using password: YES)
       2020-04-16T02:59:26.824028Z 15 [Note] Access denied for user 'root'@'223.96.218.217' (using password: YES)
       [root@izb6rc3amsrxv6z local]# 
       
4. 密码修改,代码如下
mysql> alter user 'root'@'localhost' identified by 'Admin123..';
---------------------------------------------------------------
# 方式二: 跳过权限验证
[root@izb6rc3amsrxv6z /]# vi /etc/my.cnf
       # For advice on how to change settings please see
       # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
       
       [mysqld]
       #
       # Remove leading # and set to the amount of RAM for the most important data
       # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
       # innodb_buffer_pool_size = 128M
       #
       # Remove leading # to turn on a very important data integrity option: logging
       # changes to the binary log between backups.
       # log_bin
       #
       # Remove leading # to set options mainly useful for reporting servers.
       # The server defaults are faster for transactions and fast SELECTs.
       # Adjust sizes as needed, experiment to find the optimal values.
       # join_buffer_size = 128M
       # sort_buffer_size = 2M
       # read_rnd_buffer_size = 2M
       
       # 跳过MySQL的权限机制   就不需要输入密码 进去 更改密码  再将本命令删除 或 注释
       skip-grant-tables
       
       datadir=/var/lib/mysql
       socket=/var/lib/mysql/mysql.sock
       
       # Disabling symbolic-links is recommended to prevent assorted security risks
       symbolic-links=0
       
       log-error=/var/log/mysqld.log
       pid-file=/var/run/mysqld/mysqld.pid
       # 以下是在重启数据库
       # 尝试了老命令 发现不行   结果告诉我了一个新的命令“systemctl restart  mysql.service”
       [root@izb6rc3amsrxv6z etc]# service mysql restart
           Redirecting to /bin/systemctl restart  mysql.service
           Failed to restart mysql.service: Unit not found.
       # 重启数据库的服务
       [root@izb6rc3amsrxv6z etc]# systemctl restart mysqld

# 1. 注意:在MySQL5.7版本又出现了不同的地方,即在mysql数据库中的user用户表中,没有password这个字段属性了,而是更改为了authentication_string
# 2. 修改语句如下:(下方的sorry则是我的数据库密码)
update mysql.user set authentication_string = password('sorry') where user = 'root';
   centOS7下找回mysql的密码 | 忘记密码,这么办?
     更改数据库密码步骤
      1. 配置文件[/etc/my.cnf] 设置 跳过密码验证
      2. 重启数据库服务
      3. 进入数据库之后? 选中数据库  运行修改密码的语句  
      4. 退出 重启数据库
       [root@izb6rc3amsrxv6z etc]# mysql -uroot -p
       Enter password: 
       Welcome to the MySQL monitor.  Commands end with ; or \g.
       Your MySQL connection id is 2
       Server version: 5.7.29 MySQL Community Server (GPL)
       
       Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
       
       Oracle is a registered trademark of Oracle Corporation and/or its
       affiliates. Other names may be trademarks of their respective
       owners.
       
       Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
     
       
       #想执行更改密码操作   失败了 原因是 没有选中数据库
       mysql> update user set authentication_string = password('sorry') where user = 'root';
       ERROR 1046 (3D000): No database selected
       mysql> show databases;
       +--------------------+
       | Database           |
       +--------------------+
       | information_schema |
       | mysql              |
       | performance_schema |
       | sys                |
       +--------------------+
       4 rows in set (0.00 sec)
       # 选中数据库
       mysql> use mysql
       Reading table information for completion of table and column names
       You can turn off this feature to get a quicker startup with -A
       
       Database changed
       # 显示该数据库下 有几张表
       mysql> show tables;
       +---------------------------+
       | Tables_in_mysql           |
       +---------------------------+
       | columns_priv              |
       | db                        |
       | engine_cost               |
       | event                     |
       | func                      |
       | general_log               |
       | gtid_executed             |
       | help_category             |
       | help_keyword              |
       | help_relation             |
       | help_topic                |
       | innodb_index_stats        |
       | innodb_table_stats        |
       | ndb_binlog_index          |
       | plugin                    |
       | proc                      |
       | procs_priv                |
       | proxies_priv              |
       | server_cost               |
       | servers                   |
       | slave_master_info         |
       | slave_relay_log_info      |
       | slave_worker_info         |
       | slow_log                  |
       | tables_priv               |
       | time_zone                 |
       | time_zone_leap_second     |
       | time_zone_name            |
       | time_zone_transition      |
       | time_zone_transition_type |
       | user                      |
       +---------------------------+
       31 rows in set (0.00 sec)
       
       # 查询 user表的 表结构
       mysql> desc user ;
       +------------------------+-----------------------------------+------+-----+-----------------------+-------+
       | Field                  | Type                              | Null | Key | Default               | Extra |
       +------------------------+-----------------------------------+------+-----+-----------------------+-------+
       | Host                   | char(60)                          | NO   | PRI |                       |       |
       | User                   | char(32)                          | NO   | PRI |                       |       |
       | Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Insert_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Update_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Delete_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Drop_priv              | enum('N','Y')                     | NO   |     | N                     |       |
       | Reload_priv            | enum('N','Y')                     | NO   |     | N                     |       |
       | Shutdown_priv          | enum('N','Y')                     | NO   |     | N                     |       |
       | Process_priv           | enum('N','Y')                     | NO   |     | N                     |       |
       | File_priv              | enum('N','Y')                     | NO   |     | N                     |       |
       | Grant_priv             | enum('N','Y')                     | NO   |     | N                     |       |
       | References_priv        | enum('N','Y')                     | NO   |     | N                     |       |
       | Index_priv             | enum('N','Y')                     | NO   |     | N                     |       |
       | Alter_priv             | enum('N','Y')                     | NO   |     | N                     |       |
       | Show_db_priv           | enum('N','Y')                     | NO   |     | N                     |       |
       | Super_priv             | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N                     |       |
       | Lock_tables_priv       | enum('N','Y')                     | NO   |     | N                     |       |
       | Execute_priv           | enum('N','Y')                     | NO   |     | N                     |       |
       | Repl_slave_priv        | enum('N','Y')                     | NO   |     | N                     |       |
       | Repl_client_priv       | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_view_priv       | enum('N','Y')                     | NO   |     | N                     |       |
       | Show_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_routine_priv    | enum('N','Y')                     | NO   |     | N                     |       |
       | Alter_routine_priv     | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_user_priv       | enum('N','Y')                     | NO   |     | N                     |       |
       | Event_priv             | enum('N','Y')                     | NO   |     | N                     |       |
       | Trigger_priv           | enum('N','Y')                     | NO   |     | N                     |       |
       | Create_tablespace_priv | enum('N','Y')                     | NO   |     | N                     |       |
       | ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
       | ssl_cipher             | blob                              | NO   |     | NULL                  |       |
       | x509_issuer            | blob                              | NO   |     | NULL                  |       |
       | x509_subject           | blob                              | NO   |     | NULL                  |       |
       | max_questions          | int(11) unsigned                  | NO   |     | 0                     |       |
       | max_updates            | int(11) unsigned                  | NO   |     | 0                     |       |
       | max_connections        | int(11) unsigned                  | NO   |     | 0                     |       |
       | max_user_connections   | int(11) unsigned                  | NO   |     | 0                     |       |
       | plugin                 | char(64)                          | NO   |     | mysql_native_password |       |
       | authentication_string  | text                              | YES  |     | NULL                  |       |
       | password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
       | password_last_changed  | timestamp                         | YES  |     | NULL                  |       |
       | password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |
       | account_locked         | enum('N','Y')                     | NO   |     | N                     |       |
       +------------------------+-----------------------------------+------+-----+-----------------------+-------+
       45 rows in set (0.00 sec)
       
       # 更改数据库密码了  
       mysql> update mysql.user set authentication_string = password('sorry') where user = 'root';
       Query OK, 1 row affected, 1 warning (0.00 sec)
       Rows matched: 1  Changed: 1  Warnings: 1
       
       mysql> exit
       Bye
       # 删除  【跳过数据库的登陆权限验证】  存在/etc/my.cnf
       [root@izb6rc3amsrxv6z etc]# vi /etc/my.cnf
       # 再次重启MySQL服务
       [root@izb6rc3amsrxv6z etc]# systemctl restart  mysqld
       # 准备再次登录 数据库
       [root@izb6rc3amsrxv6z etc]# mysql -uroot -p
       # 没有输入密码,测试 是否可以进入  发现不行 ,表示更改密码生效
       Enter password: 
       ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
       [root@izb6rc3amsrxv6z etc]# mysql -uroot -p
       Enter password: #sorry
       Welcome to the MySQL monitor.  Commands end with ; or \g.
       Your MySQL connection id is 3
       Server version: 5.7.29
       
       Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
       
       Oracle is a registered trademark of Oracle Corporation and/or its
       affiliates. Other names may be trademarks of their respective
       owners.
       
       Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       
       mysql> 
       
关于MySQL 远程连接访问:

1. 如果想把密码的要求设置的简单一些时,可以按照如下截图操作:
    
2. 赋予root用户可以接收任意主机(%)访问
    `   grant all privileges on *.* to 'root'@'%' identified by 'Admin123..';`
3. 刷新权限 【单单赋予权限是不行的,一定要记得刷新操作】
       `flush privileges;`
安装上传软件

  [root@izb6rc3amsrxv6z /]# yum install lrzsz -y
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ============================================================================================
     Package                Arch                        Version                            Repository                                Size
    ======================================
    Installing:
     lrzsz                   x86_64                     0.12.20-36.el7                     base                                    78 k
    
    Transaction Summary
    ======================================
    Install  1 Package
    
    Total download size: 78 k
    Installed size: 181 k
    Downloading packages:
    lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                                                           |  78 kB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                                   1/1 
      Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                                   1/1 
    
    Installed:
      lrzsz.x86_64 0:0.12.20-36.el7                                                                                                                                                                                  
    
    Complete!
    [root@izb6rc3amsrxv6z /]# 
Jdk环境搭建
  [root@izb6rc3amsrxv6z /]# cd /www/develop/java
    [root@izb6rc3amsrxv6z java]# ls
    [root@izb6rc3amsrxv6z java]# rz -E
    rz waiting to receive.
    [root@izb6rc3amsrxv6z java]# ls
    jdk-8u211-linux-x64.tar.gz
    [root@izb6rc3amsrxv6z java]# tar -zxf  jdk-8u211-linux-x64.tar.gz  
    [root@izb6rc3amsrxv6z java]# ls
    jdk1.8.0_211  jdk-8u211-linux-x64.tar.gz
    #配置jdk的环境变量 /etc/profile
    #在 /etc/profile内的最后加上以上内容,路径下写你自己设置的路径
    export JAVA_HOME=/www/develop/www/develop/java/jdk1.8.0_211
    export PATH=$JAVA_HOME/bin:$PATH
    #更新环境变量
    [root@izb6rc3amsrxv6z java]# source /etc/profile
    # 核查jdk是否安装成功  查看版本   查看javac有没有内容输出
    [root@izb6rc3amsrxv6z java]# java -version
    java version "1.8.0_211"
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Tomcat的安装、配置
    [root@izb6rc3amsrxv6z /]# cd /www/develop/tomcat
    [root@izb6rc3amsrxv6z java]# ls
    [root@izb6rc3amsrxv6z java]# rz -E
    rz waiting to receive.
    [root@izb6rc3amsrxv6z java]# ls
    jdk-8u211-linux-x64.tar.gz
    [root@izb6rc3amsrxv6z java]# tar -zxf  jdk-8u211-linux-x64.tar.gz  
    [root@izb6rc3amsrxv6z java]# ls
    jdk1.8.0_211  jdk-8u211-linux-x64.tar.gz
    #配置jdk的环境变量 /etc/profile
    #在 /etc/profile内的最后加上以上内容,路径下写你自己设置的路径
    export PATH=$/www/develop/www/develop/apache/apache-tomcat-8.5.40/bin:$PATH
    #更新环境变量
    [root@izb6rc3amsrxv6z /]# source /etc/profile
    #核查jdk是否安装成功  查看版本   查看javac有没有内容输出
    [root@izb6rc3amsrxv6z java]# catalina.sh start
    java version "1.8.0_211"
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
    
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
11天前
|
安全 Java 数据安全/隐私保护
在Java项目中集成单点登录(SSO)方案
在Java项目中集成单点登录(SSO)方案
|
2天前
|
关系型数据库 MySQL Linux
Docker安装mysql详细教程, mysqld: Can‘t read dir of ‘/etc/mysql/conf.d/‘(报错已解决)
Docker安装mysql详细教程, mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory) 已解决
|
1天前
|
Oracle 关系型数据库 MySQL
linux安装及卸载mysql
在Linux上安装MySQL客户端涉及添加RPM源,运行`yum install mysql-community-client.x86_64 -y`。忘记密码时,编辑`/etc/my.cnf`,添加`skip-grant-tables`,重启MySQL,然后登录修改密码。卸载MySQL需停服,用`rpm -ev`逐个卸载相关组件,删除文件夹,并验证是否卸载干净。重新安装客户端可使用`rpm -ivh`命令。
29 8
|
4天前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
24 3
|
11天前
|
设计模式 Java 数据库连接
Java中的设计模式在实际项目中的应用
Java中的设计模式在实际项目中的应用
|
11天前
|
SQL NoSQL Java
如何在Java项目中实现分布式锁
如何在Java项目中实现分布式锁
|
10天前
|
监控 Java
Java面试题:Java内存、多线程与并发工具包的深度探索,Java内存管理策略及其优化技巧,Java多线程并发控制的工具类与机制,Java并发工具包在实际项目中的应用
Java面试题:Java内存、多线程与并发工具包的深度探索,Java内存管理策略及其优化技巧,Java多线程并发控制的工具类与机制,Java并发工具包在实际项目中的应用
10 0
|
11天前
|
Java 测试技术 Maven
在Java项目中集成单元测试与覆盖率工具
在Java项目中集成单元测试与覆盖率工具
|
16天前
|
IDE Oracle Java
day4:JDK、IntelliJ IDEA的安装和环境变量配置
【7月更文挑战第4天】🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!!
42 0
|
12天前
|
存储 Ubuntu Java
【Linux】已解决:Ubuntu虚拟机安装Java/JDK
【Linux】已解决:Ubuntu虚拟机安装Java/JDK
20 1

推荐镜像

更多