阿里云服务器部署项目

57次阅读

目录

1. 远程连接云服务器并安装 MySQL

1.1 直接使用阿里云的云服务器控制台来远程登录自己购买的服务器。

1.2 连接成功 , 进入服务器内网 ip(购买的服务器有一个公网 ip 和一个内网 ip)

1.3 添加 mysql 源

1.4MD5 校验

1.5 安装 MySQL

1.6 启动 MySQL

1.7 数据库安全配置

1.8 设置 MySQL 可远程登录

1.9 阿里云防火墙打开 3306 端口

3. 远程连接云服务器并安装 jdk

3.1 先查下是否已经安装过 jdk

4. 使用 Xftp7 工具 , 上传项目的包 (package)

5. 使用 Xshell7 工具 , 运行服务器上的项目

5.1 给项目开放端口

5.2 运行项目


1. 远程连接云服务器并安装 MySQL

1.1 直接使用阿里云的云服务器控制台来远程登录自己购买的服务器。

https://account.aliyun.com/

阿里云服务器部署项目插图

阿里云服务器部署项目插图1

1.2 连接成功 , 进入服务器内网 ip(购买的服务器有一个公网 ip 和一个内网 ip)

阿里云服务器部署项目插图2

1.3 添加 mysql 源

首先打开 MySQL 的官网 , 需要根据自己的服务器信息选择合适的源信息 , 因操作系统是 CentOS, 所以选择的是 yum 源 (yum 源地址 :https://dev.mysql.com/downloads/repo/yum/)。
因操作系统是最新的 CentOS8.2, 所以选择了最新的 MySql 版本 :mysql80-community-release-el8-1.noarch.rpm。

[root@iZuf6gmsvearrdlgnwikfoZ ~]# wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm [root@iZuf6gmsvearrdlgnwikfoZ ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm 

1.4MD5 校验

[root@iZuf6gmsvearrdlgnwikfoZ ~]# md5sum mysql80-community-release-el8-1.noarch.rpm

1.5 安装 MySQL

[root@iZuf6gmsvearrdlgnwikfoZ ~]# yum install mysql-server

1.6 启动 MySQL

[root@iZuf6gmsvearrdlgnwikfoZ ~]# sudo systemctl start mysqld [root@iZuf6gmsvearrdlgnwikfoZ ~]# systemctl status mysqld [root@iZuf6gmsvearrdlgnwikfoZ ~]# ps -ef | grep mysqld mysql 13805 1 0 Apr27 ? 00:40:16 /usr/libexec/mysqld --basedir=/usr root 116339 116251 0 11:02 pts/0 00:00:00 grep --color=auto mysqld [root@iZuf6gmsvearrdlgnwikfoZ ~]# 

1.7 数据库安全配置

在整个密码设置的过程中 , 一共 5 个步骤 :

设置 root 密码、是否禁止 root 账户远程登录、是否禁止匿名账号登录、是否删除测试库、是否确认修改。根据需求改即可。

[root@iZuf6gmsvearrdlgnwikfoZ ~]# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y 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? (Press y|Y for Yes, any other key for No) : n ... skipping. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! 

1.8 设置 MySQL 可远程登录

在 user 表中设置 root 用户可以访问的地址

[root@iZuf6gmsvearrdlgnwikfoZ ~]# mysql -h localhost -u root -p ## 登录数据库 , 输入密码后完成登录 mysql> use mysql; ## 选择 mysql 库 mysql> select user,host from user; ## 查询连接配置 +------------------+-----------+ | user | host | +------------------+-----------+ | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) mysql> update user set host='%' where user='root';## 允许使用 root 账户进行远程登录 mysql> flush privileges; ## 刷新设置

1.9 阿里云防火墙打开 3306 端口

阿里云服务器部署项目插图3

此处设置成功后, 用命令查看一下 3306 端口开放没, 若每日有可以使用命令开启(记住设置后要刷新防火墙才能生效)

防火墙操作常用命令

查看防火墙某个端口是否开放
firewall-cmd –query-port=3306/tcp
开放防火墙端口 3306
firewall-cmd –zone=public –add-port=3306/tcp –permanent
注意 : 开放端口后要重启防火墙生效
重启防火墙
systemctl restart firewalld
关闭防火墙端口
firewall-cmd –remove-port=3306/tcp –permanent
查看防火墙状态
systemctl status firewalld
关闭防火墙
systemctl stop firewalld
打开防火墙
systemctl start firewalld
开放一段端口
firewall-cmd –zone=public –add-port=40000-45000/tcp –permanent
查看开放的端口列表
firewall-cmd –zone=public –list-ports
查看被监听(Listen) 的端口
netstat -lntp

查端口被哪个进程占用
netstat -lnp|grep 3306

[root@iZuf6gmsvearrdlgnwikfoZ ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success [root@iZuf6gmsvearrdlgnwikfoZ ~]# systemctl restart firewalld [root@iZuf6gmsvearrdlgnwikfoZ ~]# firewall-cmd --query-port=3306/tcp yes [root@iZuf6gmsvearrdlgnwikfoZ ~]# 

最后设置 MySQL 开机启动

[root@iZuf6gmsvearrdlgnwikfoZ ~]# systemctl enable mysqld

阿里云服务器部署项目插图4

本地连接成功后, 可以直接用 navicat 把项目用到数据库复制到该服务器上。

至此 , 项目中用到的数据库放到了服务器上 , 版本 :MySQL: 8.0.26。

若安装过程中出现问题 , 难以解决 , 可以重置服务器系统 , 不过安装在服务器上的东西都会被重置。

3. 远程连接云服务器并安装 jdk

同理还是用远程连接阿里云服务器进行 jdk 的安装。

3.1 先查下是否已经安装过 jdk

使用命令 :java -version

若安装会有版本信息 , 例如 :

[root@iZuf6gmsvearrdlgnwikfoZ ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

若想卸载 , 可以进行如下操作 :

查看系统是否自带 jdk
[root@xxx ~]# rpm -qa |grep java
[root@xxx ~]# rpm -qa |grep jdk
[root@xxx ~]#
如果有输出信息 , 批量卸载系统自带

rpm -qa | grep java | xargs rpm -e –nodeps
如果使用 yum 安装的 jdk, 请使用下面命令卸载

yum -y remove java-1.8.0-openjdk-headless.x86_64

3.2 安装 jdk

[root@iZuf6gmsvearrdlgnwikfoZ ~]# yum install java-1.8.0-openjdk* -y

安装成功后 : 查看版本

[root@iZuf6gmsvearrdlgnwikfoZ ~]# java -version openjdk version "1.8.0_312" OpenJDK Runtime Environment (build 1.8.0_312-b07) OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

至此 , 服务器上的 jdk 安装成功 , 版本 :JDK: 1.8.0_312

4. 使用 Xftp7 工具 , 上传项目的包 (package)

其实只需要下载 XShell7,Xftp7 下载不下载就行 (用于可视化上传文件), 可以使用 Linux 命令中的rzsz命令来实现文件的上传与下载 , 还可以直接把文件拖拽到 XShell 窗口中实现上传文件到 Liunx 服务器。

在项目打包前 , 需要更改项目中 yaml 的数据库配置 :

spring.datasource.username= 自己数据库的用户 spring.datasource.password= 自己数据库的密码 spring.datasource.url=jdbc:mysql:// 自己服务器的公网 ip:3306/ 库名?useSSL=false&useUnicode=true&characterEncoding=UTF-8

阿里云服务器部署项目插图5

将项目 package 后 , 连接 Xftp, 拖进自己服务器即可。

5. 使用 Xshell7 工具 , 运行服务器上的项目

也可以在远程连接工具上进行运行。

5.1 给项目开放端口

同样是在服务器的防火墙设置那里开放安全组 : 开放 8080 端口 , 同 1.9 部分 ( 记住刷新防火墙 ( 重启防火墙 ))

5.2 运行项目

显示运行中的 java 程序
ps -aux | grep java

关闭进程
kill -9 id
不断运行
nohup java -jar sportsmeeting-v0.1.jar &

查看 nginx 进程 :
ps -ef | grep nginx

查看 进程 id 所占用的端口号
netstat -nap | grep 进程 id

查看运行日志
tail -f spring.log

至此 , 项目部署成功 !

原文链接:https://blog.csdn.net/qq_50904598/article/details/130700275

正文完
 
追风者
版权声明:本站原创文章,由 追风者 2024-01-02发表,共计5975字。
转载说明:声明:本站内容均来自互联网,归原创作者所有,如有侵权必删除。 本站文章皆由CC-4.0协议发布。