前言:
本文章使用的环境介绍: 本地系统:MacBoot M4 内存:24G 远程系统:阿里云云服务器Ubuntu24 内存:2G 后端代码仓库地址: https://gitee.com/whltaoin_admin/hmtt_cloud-project.git 版本: 68d8d89b533b539027d63336cb1f077cfe8e3c53
安装目标:阿里云云服务器 安装方式:docker
# 下载镜像
docker pull nacos/nacos-server:1.2.0
# 运行镜像
docker run --env MODE=standalone --name nacos --restart=always -d -p 8848:8848 nacos/nacos-server:1.2.0
# 运行地址
http://varin.cn:8848/nacos
通过 Docker 拉取 nacos/nacos-server:1.2.0
镜像(若本地未缓存),并以独立模式(standalone) 启动一个名为 nacos
的容器,同时配置容器自动重启、端口映射,确保 Nacos 服务可外部访问且稳定运行。
命令片段 | 核心作用 | 详细说明 |
---|---|---|
docker run | Docker 核心指令 | 用于“创建并启动一个 Docker 容器”的基础命令(若镜像本地不存在,会自动从 Docker Hub 拉取)。 |
--env MODE=standalone | 设置环境变量 | - --env(可简写为 -e):用于向容器内部传递环境变量,影响应用运行配置; - MODE=standalone:指定 Nacos 的运行模式为独立模式(单机模式),适合开发、测试场景; (补充:Nacos 还有 cluster 集群模式,需额外配置数据库、节点信息,用于生产环境)。 |
--name nacos | 命名容器 | 给启动的容器指定一个唯一名称 nacos,后续操作(如停止、重启、进入容器)可直接用该名称,无需记复杂的容器 ID(例:docker stop nacos)。 |
--restart=always | 配置容器重启策略 | 定义容器退出后的重启规则: - always:无论容器因何种原因退出(包括手动停止后重启 Docker 服务),都会自动重启; (其他常见策略:on-failure 仅故障退出时重启、no 不自动重启)。 |
-d | 后台运行容器 | 全称 --detach,让容器在“后台(守护进程模式)”运行,不会占用当前终端窗口(若不加 -d,终端会直接输出 Nacos 的日志,关闭终端则容器停止)。 |
-p 8848:8848 | 端口映射 | - -p:用于将“宿主机端口”与“容器内部端口”绑定,格式为 宿主机端口:容器内部端口; - 左侧 8848:宿主机(即你运行 Docker 的机器)的端口,外部通过该端口访问 Nacos; - 右侧 8848:Nacos 容器内部的默认服务端口(Nacos 官方默认端口,不可随意修改容器内端口,除非通过环境变量自定义); (例:若宿主机 8848 端口已被占用,可改为 8849:8848,外部访问时用 http://宿主机IP:8849)。 |
nacos/nacos-server:1.2.0 | 指定镜像 | - nacos/nacos-server:Docker Hub 上的 Nacos 官方镜像名称; - :1.2.0:指定镜像的版本号(固定使用 1.2.0 版本,避免因拉取最新版导致兼容性问题); (若想使用最新版,可改为 nacos/nacos-server:latest,但生产环境建议固定版本)。 |
命令执行成功后,可通过以下步骤确认 Nacos 是否正常运行:
docker ps | grep nacos
,若能看到 nacos
容器且 STATUS
为 Up
(运行中),说明容器启动成功;http://宿主机IP:8848/nacos
(若修改了宿主机端口,需替换为自定义端口);nacos
,登录后即可使用 Nacos 的配置管理、服务注册等功能。--env SPRING_DATASOURCE_PLATFORM=mysql
等环境变量,将数据存储到外部 MySQL 数据库,避免容器删除后数据丢失;nacos/nacos-server:2.3.2
),但需注意版本间的配置差异;docker stop nacos
;若需彻底删除容器,执行 docker rm nacos
(删除前需先停止容器)。安装目标:Mac 使用恐惧:brew openjdk版本:8
# 查询
brew install jdk
#安装
brew install openjdk@8
# 查询软件安装列表
brew list
> 安装目标:Mac > > 使用恐惧:brew > > Maven版本:3.6.1 >
# 查询
brew install jdk
#安装
brew install maven@3.6.1
# 查询软件安装列表
brew list
# settings.xml
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
# 拉取镜像
docker pull mysql:5.7
# 运行
docker run -d -p 3306:3306 --privileged=true -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:5.7
# 配置
cd /usr/local/mysql/conf
vim my.cnf
# 配置内容
[client]
default_character_set=utf8
[mysqld]
collation_server=utf8_general_ci
character_set_server=utf8
# 进入docker mysql 命令:
docker exec -it mysql /bin/bash
# 修改密码
ALTER USER 'root'@'%' IDENTIFIED BY '<new password>' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED BY '<new password>';
安装:brew install redis
cd /opt/homebrew/Cellar/redis/8.2.1/bin/
sudo reids-cli
1. 安装命令:brew install nginx 2. 查看安装信息:brew info nginx
==> nginx: stable 1.29.1 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
Installed
/opt/homebrew/Cellar/nginx/1.29.1 (27 files, 2.5MB) *
Poured from bottle using the formulae.brew.sh API on 2025-09-15 at 21:44:38
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/n/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@3 ✔, pcre2 ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www
The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /opt/homebrew/etc/nginx/servers/.
To restart nginx after an upgrade:
brew services restart nginx
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;
解释: 安装目录:/opt/homebrew/Cellar/nginx/1.29.1 前端资源:/opt/homebrew/var/www 配置文件:/opt/homebrew/etc/nginx/nginx.conf 默认端口:8080
# 进入到brew中nginx的配置目录中
cd /opt/homebrew/etc/nginx
# 创建目录
mkdir leadnews.conf
# 编写app项目的配置
vim heima-leadnews-app.conf
# heima-leadnews-app.conf内容
=============
upstream heima-app-gateway{
server localhost:51601;
}
server {
listen 8801;
location / {
root /opt/homebrew/var/www/app-web;
index index.html;
}
location ~/app/(.*) {
proxy_pass http://heima-app-gateway/$1;
proxy_set_header HOST $host; # 不改变源请求头的值
proxy_pass_request_body on; #开启获取请求体
proxy_pass_request_headers on; #开启获取请求头
proxy_set_header X-Real-IP $remote_addr; # 记录真实发出请求的客户端IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #记录代理信息
}
}
============
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 引入自定义配置文件
include leadnews.conf/*.conf;
}
brew serices restart nginx