ubuntu24.04 搭建 java 环境服务,以及mysql数据库

@[toc]

安装 nginx

安装 nginx

bash 复制代码
sudo apt update
apt-get install nginx

nginx 检查 安装环境以及配置文件地址

bash 复制代码
nginx -t

检查环境是否正常

bash 复制代码
systemctl status nginx.service

重启 nginx 服务

复制代码
systemctl restart nginx.service

停止 nginx 服务

arduino 复制代码
# 停止
systemctl stop nginx.service

启动 nginx 服务

bash 复制代码
# 启动
systemctl start nginx.service

nginx 项目使用端口 配置文件配置方式

json 复制代码
server {
	listen 8082 default_server;
	listen [::]:8082 default_server;

	root /mnt/data/system/tms/dist;

	location / {
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}

	location /prod-api/ {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080/;
	}
}

📌 功能说明:

  • 监听 IPv4 和 IPv6 的 8082 端口;
  • 根目录指向前端打包文件(Vue/React 等);
  • 对根路径 / 使用了 try_files 来支持前端路由;
  • 对 /prod-api/ 路径做反向代理到本地 8080 接口服务。
json 复制代码
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
	listen 8082 default_server;
	listen [::]:8082 default_server;
	
	root /mnt/data/system/tms/dist;

	location / {
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}
	
	location /prod-api/ {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080/; 
	}
}
server {
	listen 8083 default_server;
	listen [::]:8083 default_server;
	
	root /mnt/data/system/tms/work;

	location / {
		try_files $uri $uri/ /index.html;
		index  index.html index.htm;
	}
	
	location /prod-api/ {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080/; 
	}
}

nginx文件安装完成之后的文件位置:

  • /usr/sbin/nginx:主程序
  • /etc/nginx:存放配置文件
  • /usr/share/nginx:存放静态文件
  • /var/log/nginx:存放日志

mysql

安装mysql

bash 复制代码
sudo apt update
# 下载mysql 默认版本一般是 8.0.19
sudo apt-get install mysql-server
# 安装mysql开发包
sudo apt install -y libmysqlclient-dev
# 设置mysql server开机自启
sudo systemctl enable mysql
# 设置安全内容,启动配置第一次会让你输入密码,或者执行时 选择忽略密码,后续配置完返回再次执行这个
sudo mysql_secure_installation
# 启动
sudo service mysql start

检查 mysql 是否正常启动

lua 复制代码
sudo service mysql status

碰到以下问题

vbnet 复制代码
Warning: The unit file, source configuration file or drop-ins of mysql.service changed on disk. Run 'systemctl daemon-reload' to reload units.

麻烦 重启systemd管理器

复制代码
systemctl daemon-reload

开放用户远程登录权限

ini 复制代码
# 第一次没配置密码可以直接进入
mysql -uroot -p

# 进去mysql 数据库
use mysql;

# 查询用户, 可以用 更新语句把 host 只为 localhost 的root 用户开放 修改为 %
select User,host from user;
# 刷新
FLUSH TABLES‌;

开放mysql配置远程登录权限

进入修改文件页面

bash 复制代码
vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 修改 bind-address = 0.0.0.0
# 添加 character_set_server=utf8
#重启 msyql
service mysql restart

安装 openjdk 17

bash 复制代码
sudo apt update
# 检查是否以及安装过
java -version

安装OpenJDK 默认是最新的

arduino 复制代码
sudo apt install default-jdk

安装自己需要的版本

复制代码
sudo apt install openjdk-8-jdk
sudo apt install openjdk-11-jdk
sudo apt install openjdk-17-jdk
sudo apt install openjdk-21-jdk

检查是否安装完成

复制代码
java -version
相关推荐
BD_Marathon25 分钟前
Ubuntu:Mysql服务器
服务器·mysql·ubuntu
CodeWithMe2 小时前
【Note】《深入理解Linux内核》 Chapter 15 :深入理解 Linux 页缓存
linux·spring·缓存
0wioiw02 小时前
Ubuntu基础(监控重启和查找程序)
linux·服务器·ubuntu
Tipriest_2 小时前
Ubuntu常用的软件格式deb, rpm, dmg, AppImage等打包及使用方法
linux·运维·ubuntu
GBXLUO2 小时前
windows的vscode无法通过ssh连接ubuntu的解决办法
vscode·ubuntu
胡斌附体3 小时前
linux测试端口是否可被外部访问
linux·运维·服务器·python·测试·端口测试·临时服务器
愚润求学3 小时前
【Linux】自旋锁和读写锁
linux·运维
大锦终3 小时前
【Linux】常用基本指令
linux·运维·服务器·centos
IT项目管理3 小时前
达梦数据库DMHS介绍及安装部署
linux·数据库
知北游天4 小时前
Linux:多线程---深入互斥&&浅谈同步
linux·运维·服务器