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
相关推荐
Yana.nice4 小时前
Linux 只保留 30 天内日志(find命令删除日志文件)
linux·运维·chrome
DFT计算杂谈7 小时前
无 Root 权限在 Tesla K80 零门槛部署 DeepSeek 大模型
linux·服务器·网络·数据库·机器学习
Zhang~Ling8 小时前
从 fopen 到 struct file:从零开始拆解 Linux 文件 I/O
linux·运维·服务器
DeeplyMind8 小时前
Linux 深入 per-VMA lock:Linux 缺页路径如何摆脱 mmap_lock
linux·per-vma lock
爱写代码的森9 小时前
蒙三方库 | harmony-utils之FileUtil文件重命名与属性查询详解
linux·运维·服务器·华为·harmonyos·鸿蒙·huawei
XMAIPC_Robot10 小时前
软硬协同实时控制|RK3588业务调度+FPGA硬件时序,ethercat实现半导体设备微秒级响应(125us)
linux·arm开发·人工智能·fpga开发
重生的黑客10 小时前
Linux 进程优先级、切换与调度:从孤儿进程到 O(1) 调度模型
linux·运维·服务器·进程优先级·nice
骑上单车去旅行12 小时前
MD5校验对比脚本
linux·服务器·windows
平生幻12 小时前
Linux 常用命令
linux
ShirleyWang01213 小时前
让headlamp控制台能访问
linux·服务器·python·k8s·k3s