网站维护记录

  大童  |   on Thursday, February 1, 2024  |  5212   |  11 minutes

my web site recording

思路

搭建git服务,git目录作为网站的主目录,可以远程通过git命令直接发布到这个目录 用nginx来做web server

自动化部署(用webhook)

参考:https://gitee.com/douboer/testhook

运行

[gavin@kvm-douboer ~/myweb]$ pwd /home/gavin/myweb 在服务器侧该目录下运行: [gavin@kvm-douboer ~]$ sudo hugo server -D –bind 24.233.3.126 -p 80 –baseURL=http://biboer.cn &

过程记录

20240222


有问题,git是密文方式存储,nginx不能直接解析; 变通的办法是,用一个定时任务发布到nginx指向的目录。 client: A1(从gitserver拉下来,日常编辑维护) ⬆️
server: git server –> A2(从gitserver定时拉取,不会手动变更) <– nginx


hexo wordpress hugo markdown


yum install net-tools -y netstat -lnpt

  • hugo example无法访问。 hugo server -D –themesDir ../..

solve: cd /home/gavin/notrack/exampleSite hugo server -D –themesDir ../.. –bind 24.233.3.126 -p 80 –baseURL=http://24.233.3.126:80

–themesDir themes目录所在的路径(相对于当前执行路径)

20240223

https://gohugo.io/getting-started/quick-start/


git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke

vs. ❓

git remote add origin https://github.com/theNewDynamic/gohugo-theme-ananke.git
git pull

20240224

find | grep config. | xargs -I {} cp {} /tmp

hugo server –bind 24.233.3.126 -p 80 –baseURL=http://24.233.3.126:80

20240225

部署hugo-theme-cleanwhite,穿越完成。 研究config.toml,algolia搜索没解决。 已解决。

  • 🔔 markdown不换行问题,末尾加两空格

20240225

git branch -l
git checkout master

20240226

  • markdown头部解析及方便维护问题。

  • npm❓

  • 通过webhook,自动部署服务 本地修改 – 提交到github/gitee – 触发webhook – push到web服务器

  • nodejs环境 问AI,在服务器侧写一段js代码,监听80端口用户访问http://www.biboer.cn/xxx/,当用户访问该链接触发服务器侧调用shell脚本“pushshell”,并打印log 用python代码解决。

  • ./themes/hugo-theme-cleanwhite/layouts/404.html # 定义404页

20240228

  • 从notebook采编代码,未完成❓
    • 解析markdown文件,按目录头(##)分割文件,输出到不同的文件中。
      • 文件名使用:目录标题.md
      • 生成的文件插入头部

格式:parsedairy.py -t -l 2 *.md -t 时间解析,放到文件头的date中,如: “date: 2024-01-00 18:00:00” -l num,解析到哪一级,如##,num为2

  • algolia 搜索,未成功❓ solved

  • hugo命令生成静态页面public作用,发布流程❓ A:自己部署nginx等web service,发布到相应目录部署。 用hugo自带的服务器能力,不需要用hugo命令生成public

20240310

<script>
var _hmt = _hmt ⎪⎪ [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?8af1866964126ae65f4b6d38d2030b73";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>

tracking ID: 8af1866964126ae65f4b6d38d2030b73 写到config.toml的ba_track_id中,即可。

模版中已经吧以上scipt写到themes/hugo-theme-cleanwhite/layouts/partials/footer.html中。 因此,所有页面加载时,都会附加以上脚本。

  • 图床实际上没有必要使用,用filezilla更为方便。 本地目录直接上传目标/home/gavin/myweb/static/img即可。 文章中直接引用!img,相当高效。

  • 文章的管理也一样,filezilla扔到/home/gavin/myweb/content/post下即可。

  • 如需修改webserver中myweb下的其他文件,在本地修改完,git push上去即可。 gitee上的webhook会触发推送到webserver上。great!!!✅

增加http://v6.51.la统计

18042004300/Ga^^^^23

<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id:"3LTQf5zyPQGoGAJu",ck:"3LTQf5zyPQGoGAJu"})</script>

写入:themes/hugo-theme-cleanwhite/layouts/partials/footer.html

20240311

制作icon

sips -z 128 128 IMG_1350.png --out favicon.png
icotool -c favicon.png -o favicon.ico

20240408

其实不用hook那么复杂

在本地(rungit.sh): git add . git commit -m “gavin’s website” git push origin master #增加以下远程执行就串起来了 ssh -p 21174 gavin@biboer.cn ‘cd myweb && git pull origin master’


租用服务器出问题,系统通过控制台重装后,web恢复过程

初始化,root进入

创建gavin,用户组wheel(可以sudo)

sudo useradd -m -G wheel gavin

设置或更改用户的密码

sudo passwd gavin

Sudo cd /etc/yum.repos.d
Sudo wget https://copr.fedorainfracloud.org/coprs/daftaupe/hugo/repo/epel-7/daftaupe-hugo-epel-7.repo -O hugo.repo
Sudo yum update
Sudo yum install hugo
hugo version

Sudo yum install git
git clone https://gitee.com/douboer/mewed.git

sudo yum install npm
Sudo npm -g install atomic-algolia
npm init

20240411

MAC上,把notebook并入到myweb中来维护,不单独维护github上的notebook。 这样日常笔记和web网站的维护一体化。不用搬来搬去了。

20240420

让git仓库、发布目录和本地obsidian笔记本三者保持一致,这样本地vi编辑md文件后,一键git push到远程仓库后。

  • 触发远程pull,完成发布
  • 本地可以使用obsidian浏览和编辑

发布环节很好,但obsidian看有个问题,就是图片链接问题。 图片在hugo中用!picname格式。 图片在obsidian中用以下格式之一:

这让如果在web上正常显示,obsidian中就无法显示,怎么解❓ solved


花了半天时间,搞定: 文章在themes/hugo-theme-cleanwhite/layouts/_default/single.html中渲染,思路就是改这个文件。 把所有!【【name】】转成<img src="/img/name" alt=“name”>,这样obsidian可以无缝对接。

    {{ $pattern := `!【【(.*?)】】` }}
    {{ $replace := `<img src="/img/$1" alt="$1">` }}
    {{ $content := .Content | replaceRE $pattern $replace }}
    {{ $content | safeHTML }}
    <!-- {{ .Content }} -->

‼️‼️ 注意:

- 必须用{{ $content | safeHTML }},用{{ $content }}渲染有问题。
- {{ $replace := `![$1](/img/$1)` }} 替换{{ $replace := `<img src="/img/$1" alt="$1">` }}不生效,不知原因❓

原来使用的的!imgname 在vim中替换:

:%s/![.\+](\/img\/\(.\+\))/!【【\1]]/g

附:obsidian设置 README.png README-5.png


❓ 进一步:obsidian中支持拷贝到特定文件夹 solved


markdown中html如要以文本形式显示,用\转义。

20240420

🚩 todo:

  • 同样方式,在single中可以增加相册的解析,解决目前gallary排版在手机终端和pc终端不同的表现(两张一排或三张一排导致其中一类终端必定不整齐。)
 @media only screen and (min-width : 365px) {
     /* Tablet view: 3 tiles */
     .gallery .box {
         width: 33.3%;
         padding-bottom: 33.3%;
     }
 }

themes/hugo-theme-cleanwhite/static/css/hugo-easy-gallery.css 50%改为33.3%,解决!

  • 渲染 >

  • 代码块长行无法折行问题? config.toml中配置: wrap = true
    无效。


修改themes/hugo-theme-cleanwhite/static/css/hugo-theme-cleanwhite.css

pre code{
  display:block;
  width:auto;
  white-space:pre-wrap; 原来为:pre
  word-wrap:normal
}
原来为:white-space:pre;

20240428

通过钩子方式实现把markdown中所有name转成<img src="/img/name" alt=“name”>。 发现, ./themes/hugo-theme-cleanwhite/layouts/_default/_markup/render-image.html只对图片链接起作用。 ./themes/hugo-theme-cleanwhite/layouts/_default/_markup/render-link.html只对链接起作用。 怎么解决❓有没有针对content内容的钩子? 似乎没有。

是不是可以在markdwon渲染时做定制❓ solved

20240420

扩展了段落前加||,替代<p style="font-family:'Microsoft YaHei',sans-serif;background-color:#BCC6CC ;padding:20px;border-radius:20px;line-height:35px;">段落内容</p> 用于题记等。

./themes/hugo-theme-cleanwhite/layouts/_default/single.html:

         {{ $patterns := dict `(.*?)` `<img src="/img/$1" alt="$1">` `\|\|(.*)` `<p style="font-family:'Microsoft YaHei',sans-serif;background-color:#E5E4E2 ;padding:20px;border-radius:20px;line-height:35px;">$1</p>` }}
         {{ range $old, $new := $patterns }}
             {{ $content = replaceRE $old $new $content }}
         {{ end }}

20240517

  1. hugo与微信公众号结合,发布markdown文章,同时发布一份到公众号中❓
  • 通过接口方式发布或修改一篇文章,如果公众号中相同标题的文章已经存在就更新内容,如果不存在就发布为新文章。
  • 文章的标题取更新的markdown内容中的title作为公众号的标题,markdown的文件名为链接中的filename,把"http://biboer.cn/post/filename/“内容采集到公众号。
  • 采集后美化文章再发布到公众号。
  1. 在个人网站上内嵌AI,实现智能采编❓

20240521

用obsidian的livesync插件,把资源同步到云上,在所有终端可以使用obsidian同步编辑和发布。

  • 在biboer.cn这台服务器上安装couchdb(LiveSync使用的数据库),参考这个 README-11.png 目录:/opt/couchdb https://biboer.cn:6984 注意:⚠️ http端口是5984,https是6984

README-9.png


README-10.png

  • 下载配置LiveSync插件 README-12.png

20240521 - 2

hugo server 改 nginx❓(原因是"hugo server"对https证书的支持没有搞定。)

  • yum nginx
  • 配置注意:
    • 权限问题,配置中user nginx 改为 user root;
    • site文件指定为: /home/gavin/myweb/public README-13.png
  • hugorun.sh注释掉:#echo $pass | sudo -S hugo server –bind 24.233.3.126 -p 80 –baseURL=http://biboer.cn &
  • hugorun.sh,用普通用户发布到public文件 #echo $pass | sudo -S hugo && npm run algolia 改为 hugo && npm run algolia

20240820

  1. 购买ssl证书,提供给商家域名,商家提供主机名、记录类型、记录值。
  2. 配置域名解析,完成后告诉商家。 README-14.png
  3. 商家提供SSL证书(发送到邮箱)。
  4. 证书放到web home下:
[gavin@kvm-douboer cert]$ pwd
/home/gavin/myweb/cert
[gavin@kvm-douboer cert]$ ls nginx/
biboer.cn.crt  biboer.cn.key
  1. 配置/etc/nginx/nginx.conf
 46 ssl on;
 47 ssl_certificate /home/gavin/myweb/cert/nginx/biboer.cn.crt;
 48 ssl_certificate_key /home/gavin/myweb/cert/nginx/biboer.cn.key;
  1. 验证&启动nginx
sudo nginx -t
sudo nginx -s reload
sudo systemctl start nginx

20240911

专门处理markdown的label,让页面更加丰富,输出到public

20241023

重启后如何自动检测并启动相关服务。

  • ssh免密登录
  • 挂载/data
  • 启动nginx
  • 启动gitea

20250210

在push时在脚本check_services.sh中,自动检查/data是否已挂载、nginx和gitea是否已启动。

20241115

ssh免密登录

问题:

gavin@GavinsMAC myweb % ~/tomyweb.sh
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:+a7CGzybNE9gRxwbGRIOUTOangbC+PXfnL76X0Su1ho.
Please contact your system administrator.
Add correct host key in /Users/gavin/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/gavin/.ssh/known_hosts:2
Host key for [biboer.cn]:21174 has changed and you have requested strict checking.
Host key verification failed.

SOLVED: mac本地

rm ~/.ssh/known_hosts

远程配置centos,SSH配置:确保远程服务器的 /etc/ssh/sshd_config 文件中,以下配置启用了公钥认证:

PubkeyAuthentication yes
PasswordAuthentication no  # 可选,禁用密码登录

sudo systemctl restart sshd # 配置完成后,重启SSH服务

samba/smb 共享


sudo yum install samba sudo useradd samba sudo vi /etc/samba/smb.conf

 39 [rootdir] #自定义的共享文件夹
 40  comment = SambaRoot
 41  path = /home/samba/ 
 42  read only = No
// 添加 Samba 用户帐号
sudo smbpasswd -a gavin
sudo systemctl start smb

未调通❓❓❓

Q & A

  • git server上以明文形式保存目录吗? A: 加密

  • ssh免密登录,无效❓

    • 本地mac操作:
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 21174 gavin@biboer.cn
  • 远程配置centos: SSH配置:确保远程服务器的 /etc/ssh/sshd_config 文件中,以下配置启用了公钥认证:
PubkeyAuthentication yes
PasswordAuthentication no  # 可选,禁用密码登录

sudo systemctl restart sshd # 配置完成后,重启SSH服务
  • hugo命令发布到public以后,部署❓

  • 远程拉取文件,scp出错❓ scp gavin@biboer.cn:/tmp/config* . A: 通配符问题,在zshrc中加配置。

echo "setopt nonomatch" >> ~/.zshrc
source ~/.zshrc
git rm -r --cached themes/hexo-theme-akarin
- [gavin@kvm-douboer ~/myweb]$ sudo npm run algolia
> myweb@1.0.0 algolia /home/gavin/myweb
> atomic-algolia
(node:62111) UnhandledPromiseRejectionWarning: AlgoliaSearchNetworkError: connect ECONNREFUSED 127.0.0.1:443
    at ClientRequest.error (/home/gavin/myweb/node_modules/algoliasearch/src/server/builds/node.js:233:14)
    at Object.onceWrapper (events.js:286:20)
    at ClientRequest.emit (events.js:198:13)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at TLSSocket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:62111) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:62111) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[gavin@kvm-douboer ~/myweb]$ sudo npm run algolia
❗️Solve:
> cat .env
ALGOLIA_APP_ID = 67T0HBIEFP
ALGOLIA_ADMIN_KEY = e712ba7148f242911a6f33da81e02a7f
ALGOLIA_INDEX_NAME = gavin
ALGOLIA_INDEX_FILE = public/algolia.json
  1. 查找docker包 [gavin@kvm-douboer ~]$ docker search twikoo
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
INDEX       NAME                              DESCRIPTION             STARS       OFFICIAL    AUTOMATED
docker.io   docker.io/imaegoo/twikoo          Twikoo 私有部署 Docker 镜像。  6
docker.io   docker.io/llnancy/twikoo                                  0
docker.io   docker.io/lzc256/twikoo                                   0
docker.io   docker.io/colsrch/twikoo                                  0
docker.io   docker.io/dijkeuorg/twikoo-arm64                          0
  1. 拉到本地
sudo docker pull docker.io/imaegoo/twikoo
  1. 启动服务
docker run -d -p 8081:8080 twikoo
# docker run -p 8084:8080 -v ${PWD}/data:/app/data -d docker.io/imaegoo/twikoo

如端口被占用,可用如下命令查看占用端口,和PID,如应用不需要,可kill该PID

netstat -lnpt
  1. 浏览器输入:http://biboer.cn:8081,返回
     {"code":100,"message":"Twikoo 浜戝嚱鏁拌繍琛屾甯革紝璇峰弬鑰� https://twikoo.js.org/frontend.html 瀹屾垚鍓嶇鐨勯厤缃�","version":"1.6.31"}
  1. 在config.toml中增加:
twikoo_env_id = "http://biboer.cn:8081"

完成以上后,可以评论。但上传图片显示:"上传失败:未配置图片上传服务

20240521

很久的问题❗️clash代理下,访问biboer速度慢的问题。

使用clash代理,在“规则判断”下模式下,在rules中增加: - ‘DOMAIN-KEYWORD,biboer,DIRECT’ README-7.png

但访问biboer.cn加载极慢❓

README-6.png 跟踪网页耗时,加载时在cdn1.lncld.net访问时阻塞时间长。hugo使用位置:

themes/hugo-theme-cleanwhite/layouts/partials/page_view_counter.html:
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>

themes/hugo-theme-cleanwhite/layouts/_default/single.html:
{{ partial "page_view_counter.html" . }}

README-8.png

在配置文件中增加

  • ‘DOMAIN-SUFFIX,cdn1.lncld.net,DIRECT’ 问题解决。solverd 🍎

20240526

gitee容量超限,大于1GB,无法上传❓在biboer.cn上搭建git server 搭建gitea。

http://biboer.cn:3000/gavin/mywed

20240718:

su git
[git@kvm-douboer myweb]$ /data/gitea/gitea  admin user list
ID   Username Email              IsActive IsAdmin 2FA
1    gavin    douboer@icloud.com true     true    false

20240705

挂载新盘/挂载/data:

sudo fdisk -l
sudo mount /dev/vdb /data 
cd /data/

启动gitea:

sudo systemctl enable gitea #激活gitea 并将它作为系统自启动服务
sudo systemctl start gitea  # 启动gitea

其他

  • 开源图床
  • 开源文件上传服务

参考网站