Docker 常用命令

启动 docker: systemctl start docker

停止 docker: systemctl stop docker

重启 docker: systemctl restart docker

查看 docker 状态: systemctl status docker

开机自启: systemctl enable docker

查看 docker 概要信息:docker info

查看 docker 总体帮助文档: docker --help

查看 docker 命令帮助文档: docker 具体命令 --help

JAR打包:mvn clean package、mvn clean package -DskipTests

Docker镜像:mvn docker:build、docker build -t myapp .

Docker运行:

  • docker run -e JAVA_OPTS=”-Xms256m -Xmx512m” myapp
  • docker run -d -p 8080:8080 myapp

验证服务:curl http://127.0.0.1:8080/actuator/health

 

‌docker images‌:列出本地所有镜像。‌‌
‌docker pull [镜像名]‌:从仓库拉取镜像(如 docker pull nginx)。‌‌
‌docker run [选项] [镜像名]‌:创建并运行容器(如 docker run -d -p 80:80 nginx)。‌‌
‌docker ps‌:查看运行中的容器。‌‌
‌docker ps -a‌:查看所有容器(包括已停止的)。‌‌
‌docker stop [容器名]‌:停止运行中的容器。‌‌
‌docker start [容器名]‌:启动已停止的容器。‌‌
‌docker exec -it [容器名] /bin/bash‌:进入容器终端(如 docker exec -it mynginx bash)。‌‌
‌docker logs [容器名]‌:查看容器日志。‌‌
‌docker rmi [镜像名]‌:删除本地镜像。‌‌
‌docker rm [容器名]‌:删除容器。‌‌

C:\Users\luozi>docker --help
Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  bake        Build from a file
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Authenticate to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  ai*         Docker AI Agent - Ask Gordon
  builder     Manage builds
  buildx*     Docker Buildx
  compose*    Docker Compose
  container   Manage containers
  context     Manage contexts
  debug*      Get a shell into any image or container
  desktop*    Docker Desktop commands
  extension*  Manages Docker extensions
  image       Manage images
  init*       Creates Docker-related starter files for your project
  manifest    Manage Docker image manifests and manifest lists
  mcp*        Docker MCP Plugin
  model*      Docker Model Runner
  network     Manage networks
  offload*    Docker Offload
  plugin      Manage plugins
  sandbox*    Docker Sandbox
  sbom*       View the packaged-based Software Bill Of Materials (SBOM) for an image
  scout*      Docker Scout
  system      Manage Docker
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default
                           "C:\\Users\\luozi\\.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host string        Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info",
                           "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "C:\\Users\\luozi\\.docker\\ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "C:\\Users\\luozi\\.docker\\cert.pem")
      --tlskey string      Path to TLS key file (default
                           "C:\\Users\\luozi\\.docker\\key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Run 'docker COMMAND --help' for more information on a command.

For more help on how to use Docker, head to https://docs.docker.com/go/guides/

Docker run 下的命令行:

C:\Users\luozi>docker run --help
Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Create and run a new container from an image

Aliases:
  docker container run, docker run

Options:
      --add-host list                    Add a custom host-to-IP mapping
                                         (host:ip)
      --annotation map                   Add an annotation to the
                                         container (passed through to the
                                         OCI runtime) (default map[])
  -a, --attach list                      Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16              Block IO (relative weight),
                                         between 10 and 1000, or 0 to
                                         disable (default 0)
      --blkio-weight-device list         Block IO weight (relative device
                                         weight) (default [])
      --cap-add list                     Add Linux capabilities
      --cap-drop list                    Drop Linux capabilities
      --cgroup-parent string             Optional parent cgroup for the
                                         container
      --cgroupns string                  Cgroup namespace to use
                                         (host|private)
                                         'host':    Run the container in
                                         the Docker host's cgroup
                                         namespace
                                         'private': Run the container in
                                         its own private cgroup namespace
                                         '':        Use the cgroup
                                         namespace as configured by the
                                                    default-cgroupns-mode
                                         option on the daemon (default)
      --cidfile string                   Write the container ID to the file
      --cpu-period int                   Limit CPU CFS (Completely Fair
                                         Scheduler) period
      --cpu-quota int                    Limit CPU CFS (Completely Fair
                                         Scheduler) quota
      --cpu-rt-period int                Limit CPU real-time period in
                                         microseconds
      --cpu-rt-runtime int               Limit CPU real-time runtime in
                                         microseconds
  -c, --cpu-shares int                   CPU shares (relative weight)
      --cpus decimal                     Number of CPUs
      --cpuset-cpus string               CPUs in which to allow execution
                                         (0-3, 0,1)
      --cpuset-mems string               MEMs in which to allow execution
                                         (0-3, 0,1)
  -d, --detach                           Run container in background and
                                         print container ID
      --detach-keys string               Override the key sequence for
                                         detaching a container
      --device list                      Add a host device to the container
      --device-cgroup-rule list          Add a rule to the cgroup allowed
                                         devices list
      --device-read-bps list             Limit read rate (bytes per
                                         second) from a device (default [])
      --device-read-iops list            Limit read rate (IO per second)
                                         from a device (default [])
      --device-write-bps list            Limit write rate (bytes per
                                         second) to a device (default [])
      --device-write-iops list           Limit write rate (IO per second)
                                         to a device (default [])
      --dns list                         Set custom DNS servers
      --dns-option list                  Set DNS options
      --dns-search list                  Set custom DNS search domains
      --domainname string                Container NIS domain name
      --entrypoint string                Overwrite the default ENTRYPOINT
                                         of the image
  -e, --env list                         Set environment variables
      --env-file list                    Read in a file of environment
                                         variables
      --expose list                      Expose a port or a range of ports
      --gpus gpu-request                 GPU devices to add to the
                                         container ('all' to pass all GPUs)
      --group-add list                   Add additional groups to join
      --health-cmd string                Command to run to check health
      --health-interval duration         Time between running the check
                                         (ms|s|m|h) (default 0s)
      --health-retries int               Consecutive failures needed to
                                         report unhealthy
      --health-start-interval duration   Time between running the check
                                         during the start period
                                         (ms|s|m|h) (default 0s)
      --health-start-period duration     Start period for the container
                                         to initialize before starting
                                         health-retries countdown
                                         (ms|s|m|h) (default 0s)
      --health-timeout duration          Maximum time to allow one check
                                         to run (ms|s|m|h) (default 0s)
      --help                             Print usage
  -h, --hostname string                  Container host name
      --init                             Run an init inside the container
                                         that forwards signals and reaps
                                         processes
  -i, --interactive                      Keep STDIN open even if not attached
      --ip ip                            IPv4 address (e.g., 172.30.100.104)
      --ip6 ip                           IPv6 address (e.g., 2001:db8::33)
      --ipc string                       IPC mode to use
      --isolation string                 Container isolation technology
  -l, --label list                       Set meta data on a container
      --label-file list                  Read in a line delimited file of
                                         labels
      --link list                        Add link to another container
      --link-local-ip list               Container IPv4/IPv6 link-local
                                         addresses
      --log-driver string                Logging driver for the container
      --log-opt list                     Log driver options
      --mac-address string               Container MAC address (e.g.,
                                         92:d0:c6:0a:29:33)
  -m, --memory bytes                     Memory limit
      --memory-reservation bytes         Memory soft limit
      --memory-swap bytes                Swap limit equal to memory plus
                                         swap: '-1' to enable unlimited swap
      --memory-swappiness int            Tune container memory swappiness
                                         (0 to 100) (default -1)
      --mount mount                      Attach a filesystem mount to the
                                         container
      --name string                      Assign a name to the container
      --network network                  Connect a container to a network
      --network-alias list               Add network-scoped alias for the
                                         container
      --no-healthcheck                   Disable any container-specified
                                         HEALTHCHECK
      --oom-kill-disable                 Disable OOM Killer
      --oom-score-adj int                Tune host's OOM preferences
                                         (-1000 to 1000)
      --pid string                       PID namespace to use
      --pids-limit int                   Tune container pids limit (set
                                         -1 for unlimited)
      --platform string                  Set platform if server is
                                         multi-platform capable
      --privileged                       Give extended privileges to this
                                         container
  -p, --publish list                     Publish a container's port(s) to
                                         the host
  -P, --publish-all                      Publish all exposed ports to
                                         random ports
      --pull string                      Pull image before running
                                         ("always", "missing", "never")
                                         (default "missing")
  -q, --quiet                            Suppress the pull output
      --read-only                        Mount the container's root
                                         filesystem as read only
      --restart string                   Restart policy to apply when a
                                         container exits (default "no")
      --rm                               Automatically remove the
                                         container and its associated
                                         anonymous volumes when it exits
      --runtime string                   Runtime to use for this container
      --security-opt list                Security Options
      --shm-size bytes                   Size of /dev/shm
      --sig-proxy                        Proxy received signals to the
                                         process (default true)
      --stop-signal string               Signal to stop the container
      --stop-timeout int                 Timeout (in seconds) to stop a
                                         container
      --storage-opt list                 Storage driver options for the
                                         container
      --sysctl map                       Sysctl options (default map[])
      --tmpfs list                       Mount a tmpfs directory
  -t, --tty                              Allocate a pseudo-TTY
      --ulimit ulimit                    Ulimit options (default [])
      --use-api-socket                   Bind mount Docker API socket and
                                         required auth
  -u, --user string                      Username or UID (format:
                                         <name|uid>[:<group|gid>])
      --userns string                    User namespace to use
      --uts string                       UTS namespace to use
  -v, --volume list                      Bind mount a volume
      --volume-driver string             Optional volume driver for the
                                         container
      --volumes-from list                Mount volumes from the specified
                                         container(s)
  -w, --workdir string                   Working directory inside the
                                         container

 

 

 

麒麟 Linux arm64 安装 Redis、nginx、oceanbase

首先确认系统架构uname -m:

[root@localhost sbin]# uname -m
aarch64

这里看到是aarch64那么就是arm架构,否则会显示x86_64

1.安装redis

操作流程:

wget https://download.redis.io/releases/redis-6.2.12.tar.gz

tar xvzf redis-6.2.12.tar.gz

cd redis-6.2.12/

make -j$(nproc)

make install

vim redis.conf #配置参数,可以忽略

./src/redis-server

2.安装nginx

nginx麻烦一点,需要配置一些参数:

官网下载源码:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.26.3.tar.gz
tar zxvf nginx-1.26.3.tar.gz
useradd -s /sbin/nologin -M nginx

#安装目录在/data/server/nginx
cd nginx-1.26.3

#配置参数

./configure \
–prefix=/data/server/nginx \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_realip_module \
–with-threads \
–with-file-aio \
–with-stream \
–with-http_stub_status_module \
–user=nginx \
–group=nginx

#编译安装
make && make install

接着进入sbin启动nginx即可。

配置参数有点多,找了点资料记录:

–prefix=  指向安装目录。

–sbin-path=  指定执行程序文件存放位置。

–modules-path=  指定第三方模块的存放路径。

–conf-path= 指定配置文件存放位置。

–error-log-path=  指定错误日志存放位置。

–pid-path=  指定pid文件存放位置。

–lock-path=  指定lock文件存放位置。

–user=  指定程序运行时的非特权用户。

–group=  指定程序运行时的非特权用户组。

–builddir=  指向编译目录。

–with-rtsig_module  启用rtsig模块支持。

–with-select_module  启用select模块支持,一种轮询处理方式,不推荐在高并发环境中使用,禁用:–without-select_module。

–with-poll_module  启用poll模块支持,功能与select相同,不推荐在高并发环境中使用。

–with-threads 启用thread pool支持。

–with-file-aio  启用file aio支持。

–with-http_ssl_module 启用https支持。

–with-http_v2_module    启用ngx_http_v2_module支持。

–with-ipv6    启用ipv6支持。

–with-http_realip_module    允许从请求报文头中更改客户端的ip地址,默认为关。

–with-http_addition_module    启用ngix_http_additon_mdoule支持(作为一个输出过滤器,分部分响应请求)。

–with -http_xslt_module    启用ngx_http_xslt_module支持,过滤转换XML请求 。

–with-http_image_filter_mdoule  启用ngx_http_image_filter_module支持,传输JPEG\GIF\PNG图片的一个过滤器,默认不启用,需要安装gd库。

–with-http_geoip_module  启用ngx_http_geoip_module支持,用于创建基于MaxMind GeoIP二进制文件相配的客户端IP地址的ngx_http_geoip_module变量。

–with-http_sub_module  启用ngx_http_sub_module支持,允许用一些其他文本替换nginx响应中的一些文本。

–with-http_dav_module  启用ngx_http_dav_module支持,增加PUT、DELETE、MKCOL创建集合,COPY和MOVE方法,默认为关闭,需要编译开启。

–with-http_flv_module  启用ngx_http_flv_module支持,提供寻求内存使用基于时间的偏移量文件。

–with-http_mp4_module  启用ngx_http_mp4_module支持,启用对mp4类视频文件的支持。

–with-http_gzip_static_module  启用ngx_http_gzip_static_module支持,支持在线实时压缩输出数据流。

–with-http_random_index_module  启用ngx_http_random_index_module支持,从目录中随机挑选一个目录索引。

–with-http_secure_link_module  启用ngx_http_secure_link_module支持,计算和检查要求所需的安全链接网址。

–with-http_degradation_module  启用ngx_http_degradation_module 支持允许在内存不足的情况下返回204或444代码。

–with-http_stub_status_module  启用ngx_http_stub_status_module 支持查看nginx的状态页。

–without-http_charset_module  禁用ngx_http_charset_module这一模块,可以进行字符集间的转换,从其它字符转换成UTF-8或者从UTF8转换成其它字符。它只能从服务器到客户端方向,只有一个字节的字符可以转换。

–without-http_gzip_module  禁用ngx_http_gzip_module支持,同–with-http_gzip_static_module功能一样。

–without-http_ssi_module  禁用ngx_http_ssi_module支持,提供了一个在输入端处理服务器包含文件(SSI)的过滤器。

–without-http_userid_module  禁用ngx_http_userid_module支持,该模块用来确定客户端后续请求的cookies。

–without-http_access_module  禁用ngx_http_access_module支持,提供了基于主机ip地址的访问控制功能。

–without-http_auth_basic_module  禁用ngx_http_auth_basic_module支持,可以使用用户名和密码认证的方式来对站点或部分内容进行认证。

–without-http_autoindex_module  禁用ngx_http_authindex_module,该模块用于在ngx_http_index_module模块没有找到索引文件时发出请求,用于自动生成目录列表。

–without-http_geo_module  禁用ngx_http_geo_module支持,这个模块用于创建依赖于客户端ip的变量。

–without-http_map_module  禁用ngx_http_map_module支持,使用任意的键、值 对设置配置变量。

–without-http_split_clients_module 禁用ngx_http_split_clients_module支持,该模块用于基于用户ip地址、报头、cookies划分用户。

–without-http_referer_module  禁用ngx_http_referer_modlue支持,该模块用来过滤请求,报头中Referer值不正确的请求。

–without-http_rewrite_module  禁用ngx_http_rewrite_module支持。该模块允许使用正则表达式改变URI,并且根据变量来转向以及选择配置。如果在server级别设置该选项,那么将在location之前生效,但如果location中还有更进一步的重写规则,location部分的规则依然会被执行。如果这个URI重写是因为location部分的规则造成的,那么location部分会再次被执行作为新的URI,这个循环会被执行10次,最后返回一个500错误。

–without-http_proxy_module  禁用ngx_http_proxy_module支持,http代理功能。

–without-http_fastcgi_module  禁用ngx_http_fastcgi_module支持,该模块允许nginx与fastcgi进程交互,并通过传递参数来控制fastcgi进程工作。

–without-http_uwsgi_module  禁用ngx_http_uwsgi_module支持,该模块用来使用uwsgi协议,uwsgi服务器相关。

–without-http_scgi_module  禁用ngx_http_scgi_module支持,类似于fastcgi,也是应用程序与http服务的接口标准。

–without-http_memcached_module  禁用ngx_http_memcached支持,用来提供简单的缓存,提高系统效率。

–without-http_limit_conn_module  禁用ngx_http_limit_conn_module支持,该模块可以根据条件进行会话的并发连接数进行限制。

–without-http_limit_req_module  禁用ngx_limit_req_module支持,该模块可以实现对于一个地址进行请求数量的限制。

–without-http_empty_gif_module  禁用ngx_http_empty_gif_module支持,该模块在内存中常驻了一个1*1的透明gif图像,可以被非常快速的调用。

–without-http_browser_module  禁用ngx_http_browser_mdoule支持,创建依赖于请求报头的值 。如果浏览器为modern,则$modern_browser等于modern_browser_value的值;如果浏览器为old,则$ancient_browser等于$ancient_browser_value指令分配的值;如果浏览器为MSIE,则$msie等于1。

–without-http_upstream_ip_hash_module 禁用ngx_http_upstream_ip_hash_module支持,该模块用于简单的负载均衡。

–with-http_perl_module  启用ngx_http_perl_module支持,它使nginx可以直接使用perl或通过ssi调用perl。

–with-perl_modules_path=  设定perl模块路径

–with-perl=  设定perl库文件路径

–http-log-path=  设定access log路径

–http-client-body-temp-path=  设定http客户端请求临时文件路径

–http-proxy-temp-path=  设定http代理临时文件路径

–http-fastcgi-temp-path=  设定http fastcgi临时文件路径

–http-uwsgi-temp-path=  设定http scgi临时文件路径

–http-scgi-temp-path=  设定http scgi临时文件路径

–without-http  禁用http server功能

–without-http-cache  禁用http cache功能

–with-mail  启用POP3、IMAP4、SMTP代理模块

–with-mail_ssl_module  启用ngx_mail_ssl_module支持

–without-mail_pop3_module  禁用pop3协议。

–without-mail_iamp_module  禁用iamp协议。

–without-mail_smtp_module  禁用smtp协议。

–with-google_perftools_module  启用ngx_google_perftools_mdoule支持,调试用,可以用来分析程序性能瓶颈。

–with-cpp_test_module 启用ngx_cpp_test_module支持。

–add-module=  指定外部模块路径,启用对外部模块的支持。

–with-cc=  指向C编译器路径。

–with-cpp=  指向C预处理路径。

–with-cc-opt=  设置C编译器参数,指定–with-cc-opt=”-I /usr/lcal/include”,如果使用select()函数,还需要同时指定文件描述符数量–with-cc-opt=”-D FD_SETSIZE=2048″。 (PCRE库)

–with-ld-opt=  设置连接文件参数,需要指定–with-ld-opt=”-L /usr/local/lib”。(PCRE库)

–with-cpu-opt=  指定编译的CPU类型,如pentium,pentiumpro,…amd64,ppc64…

–without-pcre  禁用pcre库。

–with-pcre  启用pcre库。

–with-pcre=  指向pcre库文件目录。

–with-pcre-opt=  在编译时为pcre库设置附加参数 。

–with-md5=  指向md5库文件目录。

–with-md5-opt=  编译时为md5库设置附加参数。

–with-md5-asm  使用md5汇编源。

–with-sha1=  指向sha1库文件目录。

–with-sha1-opt=  编译时为sha1库设置附加参数。

–with-sha1-asm  使用sha1汇编源。

–with-zlib=  指向zlib库文件目录。

–with-zlib-opt=  在编译时为zlib设置附加参数。

–with-zlib-asm=  为指定的CPU使用汇编源进行优化。

–with-libatomic  为原子内存的更新操作的实现提供一个架构。

–with-libatomic=  指向libatomic_ops的安装目录。

–with-openssl=  指向openssl安装目录。

–with-openssl-opt=  在编译时为openssl设置附加参数。

–with-debug  启用debug日志。

默认with或without的选项

选项(功能) with without 默认
prefix N/A N/A /usr/local/nginx
sbin-path N/A N/A prefix/sbin/nginx
conf-path N/A N/A prefix/conf/nginx.conf
pid-path N/A N/A prefix/logs/nginx.pid
error-log-path N/A N/A prefix/logs/error.log
http-log-path N/A N/A prefix/logs/access.log
user N/A N/A nobody
group N/A N/A nobody
select_module with without 如果平台不支持kqueue,epoll,/dev/poll,它将作为自动选择的事务处理方式
poll_module with without 如果平台不支持kqueue,epoll,/dev/poll,它将作为自动选择的事务处理方式
file_aio with N/A 关闭
ipv6 with N/A 关闭
http_ssl_module with N/A 关闭
http_realip_module with N/A 关闭
http_addition_module with N/A 关闭
http_xslt_module with N/A 关闭
http_image_filter_module with N/A 关闭
http_geoip_module with N/A 关闭
http_sub_module with N/A 关闭
http_dav_module with N/A 关闭
http_flv_module with N/A 关闭
http_gzip_static_module with N/A 关闭
http_random_index_module with N/A 关闭
http_secure_link_module with N/A 关闭
http_degradation_module with N/A 关闭
http_stub_status_module with N/A 关闭
http_charset_module N/A without 启用
http_gzip_module N/A without 启用
http_ssi_module N/A without 启用
http_userid_module N/A without 启用
http_access_module N/A without 启用
http_auth_basic_module N/A without 启用
http_autoindex_module N/A without 启用
http_geo_module N/A without 启用
http_map_module N/A without 启用
http_split_clients_module N/A without 启用
http_referer_module N/A without 启用
http_rewrite_module N/A without 启用
http_proxy_module N/A without 启用
http_fastcgi_module N/A without 启用
http_uwsgi_module N/A without 启用
http_scgi_module N/A without 启用
http_memcached_module N/A without 启用
http_limit_conn_module N/A without 启用
http_limit_req_module N/A without 启用
http_empty_gif_module N/A without 启用
http_brower_module N/A without 启用
http_upstream_ip_hash_module N/A without 启用
http_perl_module with N/A 禁用
http N/A without 启用
http-cache N/A without 启用
mail with N/A 禁用
pcre with without N/A
stream with N/A 禁用

3.安装oceanbase

安装包提前在官网下载的,

tar zxvf ./oceanbase-standalone-all-in-one-4.2.5_bp6_hotfix1_20251009.el7.aarch64.tar.gz

cd oceanbase-standalone-all-in-one/

bash bin/install_obd.sh

该脚本会安装 obd 和 OBClient,并将安装目录下 rpms 目录中的所有安装包复制到 obd 的本地镜像库中,同时关闭远程镜像库。执行成功后输出如下,您可复制并执行输出中的 source ~/.oceanbase-all-in-one/bin/env.sh 命令以应用环境配置。

启动交互式安装:

在 oceanbase-standalone-all-in-one 的安装目录下,执行 install_ob.sh 脚本启动交互式安装流程。

  1. 填写当前用户信息。
  2. 修改系统参数
  3. 配置集群信息。
  4. (可选)配置租户信息。
  5. 控制是否开启密码加密功能。
  6. (可选)配置监控信息。
  7. 确认配置。
  8. 部署成功。

当看到确认配置,基本上就成功了:

#Saved configurations:
cluster name: myoceanbase2
mysql port: 2881
rpc port: 2882
obshell port: 2886
cpu count: 16
memory limit: 22G
home path: /root/myoceanbase2/oceanbase_name
data dir: /data/1/myoceanbase2
log dir: /data/log1/myoceanbase2
datafile maxsize: 312G
log disk size: 54G
enable auto start: True
tenant name: ship
tenant cpu: 4
tenant memory: 8G
tenant log disk size: 51G

 

 

 

 

 

 

Vue3+Three.js实现

一、环境准备

1. 初始化 Vue3 项目

首先确保你已安装 Node.js(建议 v16+),然后通过 Vite 快速创建 Vue3 项目:

# 创建 Vue3 项目(选 Vue + TypeScript 或 JavaScript 均可)
npm create vite@latest vue3-three-demo -- --template vue
cd vue3-three-demo
npm install

2. 安装核心依赖

需要安装 Three.js 核心库和轨道控制器(Three.js 128+ 版本后控制器单独拆分):

# 安装 Three.js 核心 + 轨道控制器npm install three @tweenjs/tween.js
  • three:Three.js 核心库(3D 渲染核心)
  • @tweenjs/tween.js:可选,用于实现 3D 物体动画(本文会用到)

二、核心概念速览(必懂)

在写代码前,先记住 Three.js 3 个核心要素(缺少一个都无法渲染):

  • 场景(Scene):3D 世界的容器,所有 3D 物体、光照都要放在场景中
  • 相机(Camera):相当于人的眼睛,决定从哪个角度观察场景
  • 渲染器(Renderer):将场景和相机的内容渲染到页面 DOM 元素上
其他常用概念:
  • 几何体(Geometry):3D 物体的形状(如立方体、球体)
  • 材质(Material):3D 物体的外观(颜色、纹理、光泽)
  • 网格(Mesh):几何体 + 材质的组合(真正可渲染的 3D 物体)
  • 光照(Light):让 3D 物体有明暗层次(否则是纯色块)
  • 控制器(OrbitControls):让用户可以拖拽、缩放、旋转场景

三、编写第一个 3D 项目

创建 src/components/ThreeDemo.vue 组件,复制以下代码(含详细注释):

<template>
    <!-- 3D 渲染容器 -->
    <div class="three-container" ref="containerRef"></div>
</template>
<script setup lang="ts">
    import { ref, onMounted, onUnmounted } from 'vue';
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    import { Tween } from '@tweenjs/tween.js';
    // 核心对象引用
    const containerRef = ref<HTMLDivElement | null>(null);
    let scene: THREE.Scene, camera: THREE.PerspectiveCamera, renderer: THREE.WebGLRenderer;
    let cube: THREE.Mesh, controls: OrbitControls;
    // 初始化 3D 场景
    const initThree = () => {
    if (!containerRef.value) return;
    // 1. 创建场景(容器)
    scene = new THREE.Scene();
    scene.background = new THREE.Color(0xf0f0f0); // 场景背景色(浅灰)
    // 2. 创建相机(透视相机:模拟人眼视角)
    // 参数:视野角度(75°)、宽高比、近裁切面、远裁切面
    camera = new THREE.PerspectiveCamera(
    75,
    containerRef.value.clientWidth / containerRef.value.clientHeight,
    0.1,
    1000
    );
    // 设置相机位置(x, y, z),默认在原点(0,0,0),需要拉开距离才能看到物体
    camera.position.z = 5;
    // 3. 创建渲染器(WebGL 渲染器,高性能)
    renderer = new THREE.WebGLRenderer({ antialias: true }); // 开启抗锯齿
    renderer.setSize(containerRef.value.clientWidth, containerRef.value.clientHeight); // 设置渲染尺寸
    containerRef.value.appendChild(renderer.domElement); // 将渲染画布添加到 DOM
    // 4. 创建 3D 物体(立方体)
    // 几何体:BoxGeometry(宽, 高, 深)
    const geometry = new THREE.BoxGeometry(2, 2, 2);
    // 材质:MeshLambertMaterial(漫反射材质,需要光照才能显示)
    const material = new THREE.MeshLambertMaterial({
    color: 0x42b983, // 基础颜色(绿色)
    wireframe: false, // 是否显示线框(true 可看到几何体结构)
});
    // 网格:几何体 + 材质
    cube = new THREE.Mesh(geometry, material);
    scene.add(cube); // 将立方体添加到场景
    // 5. 添加光照(否则物体是纯色块,无明暗)
    // 环境光:均匀照亮所有物体,无阴影
    const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
    scene.add(ambientLight);
    // 方向光:模拟太阳光,有阴影效果
    const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
    directionalLight.position.set(5, 5, 5); // 光源位置
    scene.add(directionalLight);
    // 6. 添加轨道控制器(允许用户交互:拖拽旋转、滚轮缩放)
    controls = new OrbitControls(camera, renderer.domElement);
    controls.enableDamping = true; // 开启阻尼效果(旋转更顺滑)
    controls.dampingFactor = 0.05;
    // 7. 添加动画(立方体自动旋转)
    const animateCube = () => {
    // 使用 Tween 实现平滑旋转动画
    new Tween(cube.rotation)
    .to({ x: cube.rotation.x + Math.PI * 2, y: cube.rotation.y + Math.PI * 2 }, 5000)
    .repeat(Infinity) // 无限循环
    .start();
};
    animateCube();
    // 8. 监听窗口大小变化(自适应调整)
    window.addEventListener('resize', onWindowResize);
};
    // 窗口大小自适应
    const onWindowResize = () => {
    if (!containerRef.value) return;
    // 更新相机宽高比
    camera.aspect = containerRef.value.clientWidth / containerRef.value.clientHeight;
    camera.updateProjectionMatrix(); // 更新相机投影矩阵
    // 更新渲染器尺寸
    renderer.setSize(containerRef.value.clientWidth, containerRef.value.clientHeight);
};
    // 渲染循环(Three.js 核心,持续渲染场景)
    const renderLoop = () => {
    requestAnimationFrame(renderLoop); // 浏览器帧循环
    controls.update(); // 阻尼效果需要持续更新控制器
    Tween.update(); // 更新动画
    renderer.render(scene, camera); // 渲染场景和相机
};
    // 生命周期钩子:组件挂载时初始化
    onMounted(() => {
    initThree();
    renderLoop();
});
    // 生命周期钩子:组件卸载时清理(防止内存泄漏)
    onUnmounted(() => {
    window.removeEventListener('resize', onWindowResize);
    controls.dispose(); // 销毁控制器
    renderer.dispose(); // 销毁渲染器
    // 清理场景中所有物体
    scene.traverse((obj) => {
    if (obj instanceof THREE.Mesh) {
    obj.geometry.dispose();
    (obj.material as THREE.Material).dispose();
}
});
});
</script>
<style scoped>
    .three-container {
    width: 100vw;
    height: 80vh;
    margin: 20px 0;
}
</style>

2. 在主组件中使用

修改 src/App.vue,引入并使用 ThreeDemo 组件:

<template>
    <div id="app">
        <h1>Vue3 + Three.js 第一个 3D 项目</h1>
        <ThreeDemo />
    </div>
</template>
<script setup lang="ts">
    import ThreeDemo from './components/ThreeDemo.vue';
</script>
<style scoped>
    #app {
    text-align: center;
    padding: 2rem;
}
</style>

四、运行项目

npm run dev
打开浏览器访问 http://localhost:5173 即可

五、进阶优化:添加纹理贴图

如果想让立方体更真实,可以给它添加纹理贴图(替换之前的纯色材质)。

1. 准备纹理图片

在 public 文件夹下放入一张纹理图片(如 texture.jpg,可自行下载)。

2. 修改材质代码

将之前的 MeshLambertMaterial 替换为带纹理的材质:

// 加载纹理(Three.js 内置纹理加载器)
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('/texture.jpg'); // 图片路径(public 下直接写文件名)
// 纹理优化(可选)
texture.wrapS = THREE.RepeatWrapping; // 水平重复
texture.wrapT = THREE.RepeatWrapping; // 垂直重复
texture.repeat.set(2, 2); // 重复次数(x 轴 2 次,y 轴 2 次)
texture.anisotropy = renderer.capabilities.getMaxAnisotropy(); // 各向异性过滤(提升纹理清晰度)
// 带纹理的材质
const material = new THREE.MeshLambertMaterial({
    map: texture, // 纹理贴图
});
重新运行项目,你会看到立方体表面贴上了纹理图片,更具真实感。

六、关键 API 总结(快速查阅)

功能
核心 API
创建场景
new THREE.Scene()
透视相机
new THREE.PerspectiveCamera(fov, aspect, near, far)
WebGL 渲染器
new THREE.WebGLRenderer({ antialias: true })
立方体几何体
new THREE.BoxGeometry(width, height, depth)
漫反射材质
new THREE.MeshLambertMaterial({ color, map })
3D 物体(网格)
new THREE.Mesh(geometry, material)
环境光
new THREE.AmbientLight(color, intensity)
方向光
new THREE.DirectionalLight(color, intensity)
轨道控制器
new OrbitControls(camera, renderer.domElement)
纹理加载
new THREE.TextureLoader().load(url)
动画循环
requestAnimationFrame(renderLoop)
复杂几何体:尝试 SphereGeometry(球体)、CylinderGeometry(圆柱体)等;
高级材质:MeshPhongMaterial(高光材质)、MeshStandardMaterial(PBR 物理材质);
模型加载:使用 GLTFLoader 加载 3D 模型(.gltf/.glb 文件);
粒子系统:创建大量小物体实现粒子特效(如星空、烟雾);
后期处理:添加阴影、模糊、泛光等特效;
Vue 生态整合:结合 Pinia 管理 3D 状态,结合 Vue Router 实现多场景切换;

 

Spring 官宣正式弃用 RestTemplate

近日,Spring 团队正式宣布:RestTemplate 将在 Spring Framework 7.0 中进入弃用计划,并在后续版本中逐步移除。这意味着伴随开发者十余年的经典 HTTP 客户端,终于要走向历史舞台的终点。

  • Spring Framework 7.0(2025 年 11 月):宣布弃用计划。
  • Spring Framework 7.1(预计 2026 年 11 月):正式标记为@Deprecated。
  • Spring Framework 8.0(时间待定):彻底移除 RestTemplate。

根据 Spring 的维护节奏,RestTemplate 的开源支持会延续到 至少 2029 年,开发者仍有充足的时间完成迁移。

RestTemplate 最早诞生于 Spring Framework 3.0(2009 年),至今已有 15 年历史。它的设计基于“模板式 API”(类似 JdbcTemplate、JmsTemplate),在当时为开发者带来了极大便利。但随着技术生态的发展,它逐渐暴露出以下局限:

1.API 扩展性差: 新功能需要通过方法重载实现,导致 Javadoc 和 IDE 自动补全中充斥大量重复方法,开发体验逐渐恶化。

2.异步支持不足: AsyncRestTemplate 曾试图解决,但依赖 ListenableFuture,在并发组合和资源管理上力不从心。

3.流式处理受限: RestTemplate 默认会读取并关闭整个响应,难以处理 SSE(Server-Sent Events)等流式协议。

4.无法拥抱现代 Java: 在虚拟线程(Virtual Threads)、结构化并发(Structured Concurrency)和 Reactive Streams 成为主流的今天,RestTemplate 的 API 模式已经无法适配。

在 Spring Framework 6.1 引入并不断完善的 RestClient,将取代 RestTemplate 成为传统(阻塞式)HTTP 客户端的首选。

与 RestTemplate 相比,RestClient 带来:

  • 现代化的 Fluent API:链式调用,方法更简洁,IDE 提示更精准。
  • API 版本控制:可通过请求头、路径、Query 参数等方式自动插入 API 版本。
  • 灵活的 HttpMessageConverters:更容易扩展和自定义消息转换器。
  • Http Interface Groups:支持批量配置多个 HTTP 接口客户端,减少重复代码。•RestTestClient:全新的测试客户端,替代 TestRestTemplate,支持集成测试与 Mock 测试统一。

对于已经在用RestTemplate的项目,Spring 提供了平滑迁移方案:RestClient 可以直接包装现有 RestTemplate 实例,让你逐步替换而不是“一刀切”。

另一方面,WebClient 依旧是 Reactive 编程场景下的首选 HTTP 客户端:

  • 支持异步、非阻塞调用。
  • 原生支持流式协议(如 SSE)。
  • 与 Reactor / WebFlux 完美结合。

未来的 Spring HTTP 客户端格局将非常清晰:

  • RestClient:适合大多数同步阻塞式应用。
  • WebClient:适合需要Reactive、异步或流式处理的应用。

对于大多数企业级应用来说,这次调整意味着:

1.新项目:直接使用 RestClient 或 WebClient。

2.老项目:逐步迁移,先用 RestClient 包装 RestTemplate,再逐步替换。

3.测试场景:迁移到 RestTestClient,弃用 TestRestTemplate。

随着 Spring Boot 4.0 的模块化改造,开发者还可以直接通过:

  • spring-boot-starter-restclient
  • spring-boot-starter-webclient

来声明依赖,明确选择 HTTP 客户端类型。

用C#读取Modbus温度传感器

传感器地址表

寄存器地址 类型 功能描述 数据格式 示例值
0x0000 (0)
Input Register (只读)
温度值,高精度(浮点型,双寄存器)
浮点数
25.2°C(IEEE格式)
0x0001 (1)
Input Register (只读)
湿度值(如果是温湿一体设备)
浮点数
60.1%
0x0100 (256)
Holding Register (可读写)
单位配置 (0=°C, 1=°F)
16 位整数
0(摄氏度)
0x0200 (512)
Coil (线圈,可读写)
报警启用标志
1 位布尔值
1(启用报警提示)
0x0300 (768)
Discrete Input (只读)
故障状态指示
1 位布尔值
0(无故障)

安装相关依赖

在C#项目中,需要一个库来实现Modbus通讯功能。推荐使用NModbus,它是一个流行且易用的开源库。

步骤:

  • 1.打开Visual Studio。
  • 2.使用NuGet Package Manager安装NModbus:
Install-Package NModbus

001

设置Modbus通讯

Modbus常见的两种通讯方式是串口(Modbus RTU)TCP(Modbus TCP/IP)。下面以Modbus TCP为例。

代码示例:

using System;
using System.Net.Sockets;
using NModbus;

classProgram
{
    static void Main(string[] args)
    {
        string ipAddress = "192.168.1.100"; // 替换为传感器IP
        int port = 502; // 默认的Modbus TCP端口

        try
        {
            // 建立TCP连接
            using (var tcpClient = new TcpClient(ipAddress, port))
            {
                var factory = new ModbusFactory();
                var master = factory.CreateMaster(tcpClient);

                // 读取温度值(寄存器0地址)
                ushort startAddress = 0; // 温度地址
                ushort[] registers = master.ReadInputRegisters(1, startAddress, 2);

                // 将寄存器数据转换为浮点型
                float temperature = ConvertToFloat(registers[0], registers[1]);
                Console.WriteLine($"当前温度: {temperature} °C");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"错误: {ex.Message}");
        }
    }

    // 双寄存器转浮点数
    static float ConvertToFloat(ushort high, ushort low)
    {
        byte[] data = newbyte[4];
        Buffer.BlockCopy(BitConverter.GetBytes(low), 0, data, 0, 2);
        Buffer.BlockCopy(BitConverter.GetBytes(high), 0, data, 2, 2);
        return BitConverter.ToSingle(data, 0);
    }
}

解析Modbus地址与数据

  • 1.Modbus寄存器:
    温度传感器通常储存在输入寄存器(Input Register)或保持寄存器(Holding Register)。实际使用前,需要查阅设备文档确认其寄存器地址。
  • 2.数据转换:
    常见的温度数据格式包括整型或浮点型,需要在获取后根据传感器需求做相应处理。

调试注意事项

  • 1.确保网络或串口连接正常,并确认IP地址和端口匹配实际设备。
  • 2.校对寄存器地址,如果数据异常需检查设备手册。
  • 3.检查协议类型,确定使用Modbus TCP还是RTU协议。

常见错误处理:

  • 连接超时: 确认防火墙是否拦截。
  • 数据不正确: 检查是否需要字节顺序(Byte Order)调整。

 

 

123118
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |