# omPlatform **Repository Path**: iplayaball/omPlatform ## Basic Information - **Project Name**: omPlatform - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-11 - **Last Updated**: 2024-06-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 项目特点 备份、还原互为相反的过程,备份记录可以还原,还原记录也可以再次还原。 难理清的点 两种历史记录:更新记录、还原记录 历史记录只能还原一次 更新或者还原时,会备份上一次更新或者还原的包 还原某一条历史记录时,就会把这条历史记录备份的包拿出来运行 备份的包永远是上次更新或者还原的包 要确定还原记录还原的是哪个包,需要找到到它还原的历史记录(可能是更新记录或者还原记录) 它还原的包是它还原的历史记录备份的包 # 项目最初构想 Java 直接执行 shell 命令的代码比 Python 肯定要复麻烦复杂些,所以打算把所有执行命令的功能包括传输文件的功能统统交 Python 来实现,Java 主要负责管理数据、WebMVC、WebSocket的功能。所以 Java 只需要执行本地的 Python 脚本。 Java 调用 Python,Python 在执行比较复杂的 Linux 命令的时候适当调用 bash 脚本。 Java 直接执行 shell 命令的代码比 Python 肯定要复麻烦复杂些,所以打算把所有执行命令的功能包括传输文件的功能统统交给 Python 来实现,Java 主要负责管理数据、WebMVC、WebSocket的功能。所以 Java 只需要执行本地的 Python 脚本。 有执行 Linux 命令的功能,调试和修改代码应该会比较频繁,所以更新 Linux 中运行的 Spring boot 程序要方便些。所以想到 spring boot 的热更新功能,想要实现代码变动就自动重启服务。 rsync 把本机的 Java 代码更新到 vagrant 上的 centos 里,里面运行的 spring boot 在代码有更新就自动重启。 实际测试发现,代码文件更新了并不能自动重启,得在更新代码文件后再编译下才可以。 原来是想到 wsl 的 Ubuntu 能直接访问本地的文件系统,本地的代码它能直接访问,所以只要 idea 写代码,在 wsl 里启动就可以了,不用经过远程传文件。 但是 wsl 里的网络有问题没能解决,它和 vagrant 里的 Linux 网络不通,也就不能远程管理另一台 vagrant 里的应用服务了。 wsl 的网络不用变动,只要把 vagrant 的网络改成桥接方式就可以了,wsl 就能访问到 vagrant 了,虽然反过来,vagrant 还是不能访问 wsl,但是暂时不用这样访问。 # linux 上安装 maven、java java 为了简单想直接通过 linux 系统包管理工具 apt 一键安装,但是试了安装 maven 时行不通。 所以还是通过下载 maven java 的安装包方式安装。 写了 shell 脚本来安装,当作 shell 的练习了,顺便体验下 pycharm 的 bash support 号称最强的 bash 缩写插件的功能,还有 ai 提示插件来提示下一句代码。 bash support 好像也没什么作用,code gee x 倒是挺智能的,能提示一些有用的 shell 代码。 # linux 上热启动 spring-boot 更新代码文件后需要再编译下 `mvn compile` ```shell rsync -avzP --exclude .git --exclude target --exclude om-front --exclude .idea /e/code/anbang/omPlatform root@192.168.56.10:/root/ && ssh root@192.168.56.10 "cd /root/omPlatform/abom; mvn compile" mvn spring-boot:run ``` # rsync windows 安装 rsync 还是遇到点麻烦,花了些时间才搞定。 原来在安榜电脑上用过 windows rsync,但是记不清安装时顺不顺利了。不过依稀记得那时使用过程中有个问题一直解决不了,是 rsync 不能自动输入密码,而测试服又不允许使用免密登录的方式,所以就用 python 写了脚本,但是脚本的传输文件输出信息没有 rsync 那么好看,rsync 能显示有哪些修改过的文件。 当时应该是折腾 windows rsync expect 自动输入密码费了不少时间精力,最终也没能成功解决。 # mysql 允许远程访问 在 centos 里启动的 abom 服务要连接 mysql 数据库,如果在 centos 本地安装个 docker mysql,和 windows 的 mysql 就是两个不同的测试数据库了。 所以打算把 centos 里启动的 abom 也连接 windows 里的 mysql 数据库。 发现个小问题:vagrant 里的 centos ping 192.168.56.1 不通。 允许本机的 mysql 通过 192.168.1.209 访问,它默认只能通过 localhost 访问。 ```mysql use mysql; SELECT `Host`,`User` FROM user; # 修改 user 表 UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1; SELECT `Host`,`User` FROM user; flush privileges; ``` # 用一个连接多次执行命令 后端 通过 websocket 向客户端浏览器每隔两秒发一次管理的应用服务的进程的状态,如果每次都重新建立连接打开新的 session,会挺消耗 cpu 资源的。 测试了 java ssh2 方式,每次重新建立连接,观察到 windows “任务管理器”界面显示 virtualbox 进程的 cpu 使用率变动频率挺快的,cpu 应该是挺活跃的。 ssh2 没有找到这种功能的使用方式,所以就用了 jsch。ssh2 只有 session,jsch 可以在 session 里再建立 channel,不过 channel 也不能多次执行命令,要重新用 session 打开新的 channel 才能执行新的命令。 start、stop 这样简单的功能,也需要多次执行命令,最少也得执行两次命令吧!不能一次执行,要先查看进程是否在运行,启动时如果在运行就不用启动了,直接结束启动功能。 # @Autowired 没注册上 ```java @Component public class WebSocketHandler extends TextWebSocketHandler { @Autowired private PsInfoSender psInfoSender; } ``` 加了 @Component 的,应该就能注册成功的 但是 `registerWebSocketHandlers` 这里是 `new WebSocketHandler()` ```java public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { log.info("websocket启动成功!"); registry.addHandler(new WebSocketHandler(), "/ws/serverStatus") .setAllowedOrigins("*"); } } ``` # jschExecutor.disconnect() 阻塞 两台机器,其中一台机器关机后,那个 jschExecutor.disconnect() 就阻塞住了。 把 `new JschExecutor(ip)` 放在 try 里面,JschExecutor 构造器在连接不上远程主机时,也把异常抛出来,连接不上时就没有创建成功对象,jschExecutor 还是 null ,是 null 时就不要执行 disconnect。 ```java public void putPsInfo(String ip) { JschExecutor jschExecutor = null; try { jschExecutor = new JschExecutor(ip); String psInfoStr = jschExecutor.execCmd(CMD_GET_PS_INFO); allHostPsInfo.put(ip, formatPsInfo(psInfoStr)); } catch (Exception e) { if (jschExecutor != null) { jschExecutor.disconnect(); } } } ``` # 日志级别 每两秒一次的日志打印太多了,可是在查上面的卡住的问题时,又必须通过打印来排查在哪一行代码卡住了,起初也没想到会是 disconnect 会卡住。 以前遇到简单的 bug 时, 习惯是把打印的代码注释掉或者直接删除,没有发生问题时,觉得打印是多余的内容,影响正常代码的阅读,但是出现问题后,又得把原来觉得没必要的打印代码打开,这样就太麻烦了。 所以,需要一个日志级别,开启一种日志级别,比这种日志级别低的日志就不会被打印。spring boot 的默认日志级别是 info,debug、trace级别的日志就不会被打印。 ```text TRACE: This is the most detailed log level, used to log fine-grained informational messages that are typically enabled only during development and debugging. DEBUG: This log level is used to log messages that provide detailed information about the progress of the application, typically enabled during development and debugging. INFO: This is the default log level, used to log informational messages that are relevant to the normal operation of the application. WARN: This log level is used to log warning messages, indicating that something unexpected happened but the application can still continue to function correctly. ERROR: This log level is used to log error messages, indicating that a serious problem occurred, which may cause the application to fail or behave incorrectly. FATAL: This log level is used to log fatal messages, indicating that a very serious problem occurred, which caused the application to terminate abnormally. ``` # git commit 规范 查过很多次,就这简单的几种类型,等到要提交的时候又忘了,所以,还是把规范写出来,方便自己查阅。 ```text (): ``` ## type - feat: A new feature - fix: A bug fix - docs: Documentation only changes - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) - refactor: A code change that neither fixes a bug nor adds a feature - test: Adding missing tests or correcting existing tests - chore: Changes to the build process or auxiliary tools and libraries such as documentation generation - revert: Reverts a previous commit scope: The scope of the change (e.g. 'core', 'ui', 'docs', etc.) subject: A short description of the change body: A more detailed description of the change footer: Any additional information or context about the change ## type example feat(core): Add support for new feature fix(ui): Fix bug where button was not displaying correctly docs(readme): Update README file with new installation instructions style: Add missing semicolon to fix linter errors refactor(core): Simplify codebase by removing unused functions test(unit): Add new unit tests for new feature chore(deps): Update dependency to latest version revert(core): Revert changes made in commit 123456789