技术文章

  • 在 macOS(Apple Silicon)根目录下创建目录的正确方式

    2025-10-29 17:30:05 236 0 技术文章

    在 macOS 上,我想在根目录(/)下创建一个目录,比如 /data1,用于放置项目数据。

    mkdir /data1
    

    结果系统提示:

    mkdir: /data1: Read-only file system
    

    一开始我以为是权限问题,于是又试了:

    sudo mkdir /data1
    

    但依然报错,说明即使 sudo 也不行。

    为什么会这样?

    从 macOS Big Sur(11) 开始,苹果对系统盘启用了 Signed System Volume(SSV)签名保护机制。

    这意味着:

    系统卷 / 是 只读的 APFS 快照;

    即使是 root 用户,也不能直接修改;

    mount -uw / 在 Apple Silicon(M1/M2/M3)上会报错:

    mount_apfs: volume could not be mounted: Permission denied
    mount: / failed with 66
    

    简单来说:根目录是锁死的。

  • 通过 pyenv 配合 venv 来创建项目专属的虚拟环境

    2024-12-03 17:37:48 4150 0 技术文章

    安装 pyenv

    curl https://pyenv.run | bash
    

    这条命令会自动安装以下工具:

    • pyenv
    • pyenv-doctor(检查 pyenv 安装的健康状况)
    • pyenv-virtualenv(用于创建 Python 虚拟环境)

    更新 Shell 配置

    vim ~/.bashrc
    
    echo -e 'export PATH="$HOME/.pyenv/bin:$PATH"\n' \
        'eval "$(pyenv init --path)"\n' \
        'eval "$(pyenv init -)"\n' \
        'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
    
    source ~/.bashrc
    

    安装 Python 版本

    pyenv install 3.11.9
    

    设置全局或本地 Python 版本

    设置一个全局的 Python 版本(用于所有项目):

    pyenv global 3.11.9
    

    你还可以为特定目录设置本地版本,例如在某个项目目录下:

    pyenv local 3.8.12
    

    这会创建一个 .python-version 文件,记录该项目使用的 Python 版本。

    创建虚拟环境(使用 venv)

    python -m venv venv
    

    激活虚拟环境

    对于 Bash/Zsh(Linux/macOS):

    source venv/bin/activate
    

    对于 Windows(CMD):

    .\venv\Scripts\activate
    
  • 解决 Python 3.8+ 遇到的 OpenSSL 版本不兼容的问题

    2024-11-09 16:40:57 6659 0 技术文章

    在安装 Python3.8 时可能会遇到与系统自带 OpenSSL 版本不兼容的问题。Python3.8 需要的 OpenSSL 版本为 1.0.21.1.x。如果系统中默认的 OpenSSL 版本低于需求(通常是 OpenSSL 1.0.1),会导致如下错误:

    Could not build the ssl module!
    Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
    
  • MySQL 容器异常 - mbind: Operation not permitted

    2024-06-03 10:39:11 5148 0 技术文章
    2024-06-03 09:23:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
    2024-06-03 09:23:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
    2024-06-03 09:23:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
    2024-06-03T09:23:25.944402Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
    2024-06-03T09:23:25.944530Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
    2024-06-03T09:23:25.944549Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
    2024-06-03T09:23:25.970311Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    2024-06-03T09:23:26.546899Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    2024-06-03T09:23:26.881580Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
    2024-06-03T09:23:26.881612Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
    2024-06-03T09:23:26.899326Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
    2024-06-03T09:23:26.899366Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
    2024-06-03T09:23:26.989154Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
    2024-06-03T09:23:27.078117Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
    2024-06-03T09:23:27.078165Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
    mbind: Operation not permitted
    mbind: Operation not permitted
    mbind: Operation not permitted
    
    • macOS 终端使用 Solarized Dark xterm-256color 主题

      2023-11-25 12:38:22 266 0 技术文章

      1. 下载主题文件

      Solarized 是一款经典的终端配色方案,护眼又高对比度。可以在官方仓库下载 macOS 终端主题:

      git clone https://github.com/altercation/solarized.git
      

      主题路径位于:

      solarized/osx-terminal.app-colors-solarized/
      

      其中包括两个文件:

      • Solarized Dark xterm-256color.terminal
      • Solarized Light xterm-256color.terminal

      2. 导入主题

      1. 打开 Terminal.app
      2. 依次点击:偏好设置 (Preferences)Profiles
      3. 点击左下角的 齿轮图标导入...
      4. 选择 Solarized Dark xterm-256color.terminal
      5. 设置为默认主题:在主题上右键 → 选择「设为默认」

      完成后重新打开终端,就能看到舒适的 Solarized Dark 效果。

      3. 优化选中文本配色

      1. 打开 终端 → 设置 → 配置文件 → 文本 → 选中颜色
      2. 点击右侧的小色块(打开颜色选取器)
      3. 在弹出的窗口上方点 “滑块图标”(像三根小杠的那个),切换模式
      4. 在上方的下拉菜单中选择:RGB 滑块
      5. 在十六进制颜色编号框输入 284B5A

      4. 设置字体

      在 macOS 终端中,个人比较喜欢 SF Mono Terminal 11,苹果官方风格,简洁干净。 JetBrains Mono 字体也相当不错,专为开发设计,字符区分度高(比如 0/O, 1/l/I),自带连字(可以关闭),粗细分布合理,长时间看不累。

      • VS Code 设置编辑器及终端的字体和字号

        2023-09-16 12:38:22 233 0 技术文章

        作为一名开发者,我们都希望拥有一个舒适的编码环境。最近在配置 VS Code 的字体时遇到了一些问题,经过一番调试,终于找到了完美的解决方案。今天分享这个过程,希望能帮到有相似困扰的朋友。

        第一次尝试:基础配置

        {
          "editor.fontFamily": "SF Mono, monospace",
          "editor.fontSize": 13,
          "terminal.integrated.fontFamily": "SF Mono, monospace"
          "terminal.integrated.fontSize": 13
        }
        

        结果:字体和字号都不生效。

        第二次尝试:带空格的字体加单引号

        {
          "editor.fontFamily": "'SF Mono', monospace",
          "editor.fontSize": 13,
          "terminal.integrated.fontFamily": "'SF Mono', monospace"
          "terminal.integrated.fontSize": 13
        }
        

        结果:字号生效,字体不生效。

        然而,在配置过程中还遇到了一个令人困扰的错误:

        终端仅支持等宽字体。如果这是新安装的字体,请确保重新启动 VS Code。

        最终打开目录 /System/Applications/Utilities/Terminal.app/Contents/Resources/Fonts/

        双击 SFMono-Regular.otf → “安装字体”

        问题解决!

        以下是完整的 ~/Library/Application\ Support/Code/User/settings.json

        {
            "workbench.colorTheme": "Solarized Dark",
            "roo-cline.allowedCommands": [
                "git log",
                "git diff",
                "git show"
            ],
            "roo-cline.deniedCommands": [],
            "security.workspace.trust.untrustedFiles": "open",
            "editor.fontFamily": "'SF Mono', Menlo, monospace",
            "editor.fontSize": 13,
            "terminal.integrated.fontFamily": "'SF Mono Terminal', Menlo, monospace",
            "terminal.integrated.fontSize": 13
        }
        
        • Undefined index: constraint_name 报错解决方法

          2022-12-09 16:32:12 3540 0 技术文章

          错误日志

          [error][yii\base\ErrorException:8] yii\base\ErrorException: Undefined index: constraint_name in /path/to/vendor/yiisoft/yii2/db/mysql/Schema.php:394
          

          原因

          MySQL 8.0.21 中返回的列名大小写不一致,导致 Yii2 在获取数据库模式时出错。

          解决方法

          1. 编辑 common/config/main-local.php,设置 PDO 属性 PDO::ATTR_CASE => PDO::CASE_LOWER
            'db' => [
             'class' => 'yii\db\Connection',
             'dsn' => 'mysql:host=localhost;dbname=db_name',
             'username' => 'username',
             'password' => '******',
             'attributes' => [PDO::ATTR_CASE => PDO::CASE_LOWER],
            ],
            
          2. 修改 /path/to/vendor/yiisoft/yii2/db/mysql/Schema.php:394
            foreach ($rows as $row) {
             $row = array_change_key_case($row, CASE_LOWER);
            

          推荐第一种方法,使列名明确指定为一致的大小写。

          参考文章:https://github.com/yiisoft/yii2/issues/18171

          • 入职满 7 周年纪念日

            2022-01-20 12:38:22 3602 0 技术文章

            IMG_0354.PNG

            • 入职满 6 周年纪念日

              2021-01-20 12:38:22 3292 0 技术文章

              IMG_8718.PNG

              • Docker 清理无效容器镜像及日志的方法

                2020-04-12 12:38:22 3671 0 技术文章

                清除无效容器、网络、镜像、缓存

                • docker system prune:删除停止的容器、未使用的网络、悬空的镜像和构建缓存。
                • docker system prune -a:删除停止的容器、未使用的网络、所有未使用的镜像(不仅仅是悬空的镜像)和构建缓存。

                清除日志

                1. 创建 clean_docker_log.sh,内容如下:
                  #!/bin/bash
                  

                logs=$(find /var/lib/docker/containers/ -name *-json.log)

                for log in $logs

                    do
                            echo "clean logs : $log"
                            cat /dev/null > $log
                    done
                

                echo "Docker logs cleanup completed."

                
                2. 给脚本增加可执行权限
                

                chmod +x clean_docker_log.sh

                
                3. 执行脚本
                

                ./clean_docker_log.sh

                
                
                • 使用 Docker 基于 Debian 安装 Java 环境失败的解决方法

                  2019-11-15 17:09:34 26343 0 技术文章
                  # 安装 default-jre 需要手动创建 /usr/share/man/man1 目录
                  RUN mkdir -p /usr/share/man/man1 \
                      && apt-get update \
                      && apt-get install -y \
                      default-jre \
                  

                  参考文章:https://stackoverflow.com/questions/55795154/docker-how-to-install-openjdk-jre-12-on-top-of-debian-jessie-slim

                  • 升级 Catalina 后出现 Read-only file system 问题解决方案

                    2019-10-07 18:03:36 26839 0 技术文章

                    由于项目的根目录在 /data1 目录,需要在根目录创建 data1 目录,但是提示:

                    mkdir: data1: Read-only file system
                    

                    先关闭 sip,终端输入 sudo mount -uw /

                    然后再创建目录或者创建软链接,即可成功!

                    • Yii China 是官方唯一认可的中文社区

                      2019-01-30 11:48:58 28566 1 技术文章

                      今天是 Yii Framework 2.0.16 版本发布 的日子,经过我们坚持不懈的进行国际化翻译,以及在中国进行大量的宣传和推广,Yii China 已经成为全球最大的 Yii 中文社区。

                      希望更多的 Yiiers 加入我们社区! https://www.yiichina.com

                      官方提供的社区推荐地址: https://github.com/yiisoft/yii2/wiki/communities#chinese

                    • GitLab 实现仓库完全迁移,包括所有提交记录、分支、标签

                      2018-12-28 18:20:29 26259 0 技术文章

                      具体命令如下:

                      cd <项目目录>
                      git fetch --all
                      git fetch --tags
                      git remote set-url origin <项目的新仓库地址>
                      git push origin --all 
                      git push --tags 
                      

                      参考文章:

                      https://developer.atlassian.com/blog/2016/01/totw-copying-a-full-git-repo/

                    • Mac OSX 目录操作遇到 Operation not permitted 问题

                      2018-12-12 11:41:28 31061 0 技术文章

                      今天在安装 PHP 扩展的时候发现使用 sudo 还依然提示 "Operation not permitted"。

                      这是由于 10.13 版本加强了权限的限制,即 rootless 机制,可以进入恢复模式关闭 rootless 机制。

                      官方说明:https://developer.apple.com/videos/play/wwdc2015/706/

                      解决方案

                      1. 重启 Mac,按 Command + R(Win 键盘:win + R)进入恢复模式

                      2. 打开终端,输入命令:

                        csrutil disable
                        
                      3. 重启后让机器正常启动,可以在终端查看 rootless 状态:

                        csrutil status
                        

                        显示

                        System Integrity Protection status: disabled.
                        

                        正常情况下 rootless 已经关闭。

                      4. 要想重新开启 rootless 机制,参考步骤 1,输入命令:

                        csrutil enable
                        
                    • 使用 pdflatex 生成 Yii 2 中文权威指南 PDF

                      2018-12-02 16:46:45 26138 0 技术文章

                      问题来源

                      https://github.com/yiisoft-contrib/yiiframework.com/issues/142 https://en.wikibooks.org/wiki/LaTeX/Internationalization#Chinese

                      解决方案

                      https://github.com/yiisoft-contrib/yiiframework.com/blob/master/commands/GuideController.php#L85

                      修改为:

                      // https://en.wikibooks.org/wiki/LaTeX/Internationalization#Chinese
                      // TODO this does not work yet. See https://github.com/yiisoft-contrib/yiiframework.com/issues/142
                      file_put_contents("$pdfTarget/main.tex", str_replace(['\usepackage[british]{babel}', '\begin{document}', '\end{document}'], ['\usepackage{CJKutf8}', '\begin{document}' . PHP_EOL . '\begin{CJK}{UTF8}{gbsn}', '\end{CJK}' . PHP_EOL . '\end{document}'], file_get_contents("$pdfTarget/main.tex")));
                      

                      {gbsn} 是“宋体”,所以前提是服务器已经安装中文的“宋体”字体。

                    • Yii 2 将 Gravatar 头像图片做本地化缓存

                      2018-09-15 18:11:52 25810 0 技术文章

                      Gravatar 是全球公认头像,但头像图片有时候访问奇慢无比,将整个页面的加载速度降了下来,如果能将头像图片缓存到本地,并设置过期时间,那性能会飞速提高,以下代码是 Yii2 的自定义 Helper 中的代码片断,用于实现 Gravatar 本地化访问。

                      public function gravatar($email, $s = 80, $atts = [], $d = 'mp', $r = 'g')
                      {
                          $key = md5(strtolower(trim($email)));
                          $img_file = Yii::getAlias("@webroot/uploads/avatar/$key.jpg");
                          $img_url = Yii::getAlias("@web/uploads/avatar/$key.jpg");
                          $noavatar_file = Yii::getAlias('@webroot/images/noavatar.jpg');
                          $noavatar_url = Yii::getAlias('@web/images/noavatar.jpg');
                      
                          // 缓存时间 30 天,超过 30 天会重新到 gravatar.com 去取
                          if (!file_exists($img_file) || filemtime($img_file) < time() - 3600 * 24 * 30) {
                              file_put_contents($img_file, file_get_contents("https://www.gravatar.com/avatar/$key?s=$s&d=$d&r=$r"));
                          }
                      
                          // 没有设置过头像的用户,显示自定义头像
                          if (md5_file($img_file) == md5_file($noavatar_file)) {
                              $img_url = $noavatar_url;
                          }
                      
                          return Html::img($img_url, $atts);
                      }
                      
                      • 使用 YUI Compressor 压缩 CSS 导致 image/svg+xml 无法显示的问题

                        2018-08-06 22:04:20 26681 0 技术文章

                        bootstrap 升级到 4.3 以后,.navbar-toggler-icon 的背景是一个 svg 图像,但被压缩后,url 中的空格全部消失了,所以无法显示这个图标。

                        .navbar-light .navbar-toggler-icon { background-image: url(data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://ww…p='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E); }
                        

                        于是想到修改 java 代码,重新编译。

                        https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java
                        

                        修改源码

                        找到 CssCompressor.java,修改第 141 行,

                        css = this.preserveToken(css, "url", "(?i)url\\(\\s*([\"']?)data\\:", true, preservedTokens);
                        

                        改为

                        css = this.preserveToken(css, "url", "(?i)url\\(\\s*([\"']?)data\\:", false, preservedTokens);
                        

                        重新编译

                        安装 ant

                        # yum -y install ant
                        # ant // 编译为 jar 文件
                        

                        生成 .jar 文件位于 build 目录。

                        THE END

                      • Tengine 2.2.2 配置 http2 协议出现的坑

                        2018-08-01 12:46:11 25268 1 技术文章

                        昨天本站将 nginx 配置改为支持 http2 协议,发帖,浏览帖子都很正常,但上传图片出现 504,改回 http 1.1 恢复正常,于是确定是配置 http2 造成的恶果,于是 google 搜索 "tengine http2 504" 等关键字,最终发现了阿里官方 issue:

                        https://github.com/alibaba/tengine/issues/1003

                        此 issue 作者遇到同样的情况:

                        从 nginx 1.10.1 升级为 tengin 2.1.2 后, 用户通过 multipart/form-data 上传文件时 如果文件大于 1M 就会上传失败 抓包分析后,发现在用户在上传大文件时,http body 内容不完整 导致 java MultipartHttpServletRequest request 拿到的 request.getFileNames() size 为 0

                        抓取了 tengin 与 tomcat 之间的报文,异常报文中 http body 内容异常

                        看这个 issue,确定是 2.2.2 的一个 BUG,接着回退到 2.2.1,问题依旧,回退到 2.2.0,问题得到解决。

                        在此提醒大家,如果使用 Tengine 需要配置 http2,建议不要使用 2.2.1 和 2.2.2 版本。

                      • Golang 中 Goroutine 的调度器模型

                        2018-07-24 18:35:36 25557 0 技术文章

                        Goroutine 可以说是 Golang 最大的特色