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
相关推荐
Sapphire~1 小时前
Linux-07 ubuntu 的 chrome 启动不了
linux·chrome·ubuntu
伤不起bb2 小时前
NoSQL 之 Redis 配置与优化
linux·运维·数据库·redis·nosql
广东数字化转型2 小时前
nginx怎么使用nginx-rtmp-module模块实现直播间功能
linux·运维·nginx
啵啵学习2 小时前
Linux 里 su 和 sudo 命令这两个有什么不一样?
linux·运维·服务器·单片机·ubuntu·centos·嵌入式
半桔3 小时前
【Linux手册】冯诺依曼体系结构
linux·缓存·职场和发展·系统架构
网硕互联的小客服3 小时前
如何利用Elastic Stack(ELK)进行安全日志分析
linux·服务器·网络·安全
冰橙子id4 小时前
linux——磁盘和文件系统管理
linux·运维·服务器
无聊的小坏坏4 小时前
环境变量深度解析:从配置到内核的全链路指南
linux·bash
才鲸嵌入式5 小时前
01 Ubuntu20.04下编译QEMU8.2.4,交叉编译32位ARM程序,运行ARM程序的方法
linux·c语言·单片机·嵌入式·arm·qemu·虚拟机
FREEDOM_X5 小时前
新版NANO下载烧录过程
ubuntu·机器人