技术文章
在 macOS(Apple Silicon)根目录下创建目录的正确方式
在 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 来创建项目专属的虚拟环境
安装
pyenvcurl https://pyenv.run | bash这条命令会自动安装以下工具:
pyenvpyenv-doctor(检查pyenv安装的健康状况)pyenv-virtualenv(用于创建 Python 虚拟环境)
更新 Shell 配置
vim ~/.bashrcecho -e 'export PATH="$HOME/.pyenv/bin:$PATH"\n' \ 'eval "$(pyenv init --path)"\n' \ 'eval "$(pyenv init -)"\n' \ 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrcsource ~/.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 版本不兼容的问题
在安装 Python3.8 时可能会遇到与系统自带 OpenSSL 版本不兼容的问题。Python3.8 需要的 OpenSSL 版本为
1.0.2或1.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 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 permittedmacOS 终端使用 Solarized Dark xterm-256color 主题
1. 下载主题文件
Solarized 是一款经典的终端配色方案,护眼又高对比度。可以在官方仓库下载 macOS 终端主题:
git clone https://github.com/altercation/solarized.git主题路径位于:
solarized/osx-terminal.app-colors-solarized/其中包括两个文件:
Solarized Dark xterm-256color.terminalSolarized Light xterm-256color.terminal
2. 导入主题
- 打开 Terminal.app
- 依次点击:
偏好设置 (Preferences)→Profiles - 点击左下角的 齿轮图标 →
导入... - 选择
Solarized Dark xterm-256color.terminal - 设置为默认主题:在主题上右键 → 选择「设为默认」
完成后重新打开终端,就能看到舒适的 Solarized Dark 效果。
3. 优化选中文本配色
- 打开 终端 → 设置 → 配置文件 → 文本 → 选中颜色
- 点击右侧的小色块(打开颜色选取器)
- 在弹出的窗口上方点 “滑块图标”(像三根小杠的那个),切换模式
- 在上方的下拉菜单中选择:RGB 滑块
- 在十六进制颜色编号框输入
284B5A
4. 设置字体
在 macOS 终端中,个人比较喜欢
SF Mono Terminal 11,苹果官方风格,简洁干净。 JetBrains Mono 字体也相当不错,专为开发设计,字符区分度高(比如 0/O, 1/l/I),自带连字(可以关闭),粗细分布合理,长时间看不累。VS Code 设置编辑器及终端的字体和字号
作为一名开发者,我们都希望拥有一个舒适的编码环境。最近在配置 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 报错解决方法
错误日志
[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 在获取数据库模式时出错。
解决方法
- 编辑 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], ], - 修改 /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
- 编辑 common/config/main-local.php,设置 PDO 属性
入职满 7 周年纪念日

入职满 6 周年纪念日

Docker 清理无效容器镜像及日志的方法
清除无效容器、网络、镜像、缓存
docker system prune:删除停止的容器、未使用的网络、悬空的镜像和构建缓存。docker system prune -a:删除停止的容器、未使用的网络、所有未使用的镜像(不仅仅是悬空的镜像)和构建缓存。
清除日志
- 创建 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 doneecho "Docker logs cleanup completed."
2. 给脚本增加可执行权限chmod +x clean_docker_log.sh
3. 执行脚本./clean_docker_log.sh
使用 Docker 基于 Debian 安装 Java 环境失败的解决方法
# 安装 default-jre 需要手动创建 /usr/share/man/man1 目录 RUN mkdir -p /usr/share/man/man1 \ && apt-get update \ && apt-get install -y \ default-jre \升级 Catalina 后出现 Read-only file system 问题解决方案
由于项目的根目录在
/data1目录,需要在根目录创建data1目录,但是提示:mkdir: data1: Read-only file system先关闭 sip,终端输入
sudo mount -uw /然后再创建目录或者创建软链接,即可成功!
Yii China 是官方唯一认可的中文社区
今天是 Yii Framework 2.0.16 版本发布 的日子,经过我们坚持不懈的进行国际化翻译,以及在中国进行大量的宣传和推广,Yii China 已经成为全球最大的 Yii 中文社区。
希望更多的 Yiiers 加入我们社区! https://www.yiichina.com
官方提供的社区推荐地址: https://github.com/yiisoft/yii2/wiki/communities#chinese
GitLab 实现仓库完全迁移,包括所有提交记录、分支、标签
具体命令如下:
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 问题
今天在安装 PHP 扩展的时候发现使用 sudo 还依然提示 "Operation not permitted"。
这是由于 10.13 版本加强了权限的限制,即 rootless 机制,可以进入恢复模式关闭 rootless 机制。
官方说明:https://developer.apple.com/videos/play/wwdc2015/706/
解决方案
重启 Mac,按 Command + R(Win 键盘:win + R)进入恢复模式
打开终端,输入命令:
csrutil disable重启后让机器正常启动,可以在终端查看 rootless 状态:
csrutil status显示
System Integrity Protection status: disabled.正常情况下 rootless 已经关闭。
要想重新开启 rootless 机制,参考步骤 1,输入命令:
csrutil enable
使用 pdflatex 生成 Yii 2 中文权威指南 PDF
问题来源
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 头像图片做本地化缓存
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 无法显示的问题
在
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 协议出现的坑
昨天本站将
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 的调度器模型
Goroutine 可以说是 Golang 最大的特色
文章归档
文章日历
| 2025 年 12 月 | ||||||
|---|---|---|---|---|---|---|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
文章标签
- Linux
- Go
- Yii
- 新浪
- CentOS
- PHP
- Git
- WSL
- Composer
- Mac
- 入职
- Bootstrap
- macOS
- UCenter
- 厦门
- 出差
- 长沙
- 湖南卫视
- 微博
- Tengine
- YUI
- 泰国
- pecl
- 优化
- GitLab
- 迁移
- rootless
- 年会
- 生日
- Tengin
- RedHat
- Sphinx
- cygwin
- Windows
- Tmux
- Zsh
- 升级
- MySQL
- sql_mode
- Shadowsockets
- 面向对象
- HTTP
- 状态码
- grep
- unoconv
- PPT
- Nginx
- htpasswd
- golang
最新评论
-
崔亮 于 19-05-23 评论了Tengine 2.2.2 配置 http2 协议出现的坑 -
王媛 于 19-01-31 评论了Yii China 是官方唯一认可的中文社区 -
三杯蛙 于 19-01-24 评论了Go 语言中 json 的操作以及常见问题 -
三杯蛙 于 19-01-24 评论了新浪赴泰国曼谷和芭提雅团建 -
巡洋舰 于 18-09-05 评论了CentOS 安装 PHP7 -
小不点 于 11-03-02 评论了WordPress 如何控制每页显示的条数 -
白领厕工 于 10-12-22 评论了关于 phpMyAdmin 免输入用户名和密码,直接进入管理界面 -
清晨的欣赏 于 10-08-04 评论了PHP 5.4 的新特性 -
易赛官网 于 10-07-27 评论了PHP 5.4 的新特性 -
文秘之家 于 10-07-17 评论了PHP 5.4 的新特性
常用工具
- 时间戳转换
- URL ENCODE/DECODE
- JSON
- 正则测试