What & How & Why

这是本文档旧的修订版!


运维问题收集

一些个人网站环境配置及常见问题记录


AMH


MySQL无法自动启动

MYSQL 在重启服务器时不能启动,尝试以下方法:

删除 my.inf

cd /etc/
rm my.inf

Typecho


一些使用 Typecho 创建网站的相关 tips.

Typecho升级指南


Typecho 可以通过以下方式来进行升级:

  1. 下载最新的版本:Typecho On Github
  2. 删除服务器上三个目录的文件,如果修改了源代码可以使用 Github 的对比工具来进行合并。三个目录分别是:/admin, /var, 和根目录下的 index.php
  3. 上传最新的对应文件即可。


InstantClick

instantclick.js 是一种ajax无刷新和预加载页面的技术,对于普通博客程序,有着明显的加速作用。instantclick.jspjax 加上预加载页面,而且,使用方法也十分的简单。

安装InstantClick


下载 InstantClick

footer.php</body> 标签之前插入以下代码:

...
<script src="instantclick.min.js" data-no-instant></script>
<script data-no-instant>InstantClick.init();</script>
</body>
</html>

点击时候的预加载


默认情况下是在鼠标悬停到链接上方即开始加载,有时候这样会带来服务器的额外开销问题。将 init 函数的参数设置为 mousedown 则可以通过点击的一瞬间进行预加载:

InstantClick.init('mousedown');

修改预加载条的颜色


在样式表中加入如下代码即可:

#instantclick-bar {
  background: gray;
}

与 PrismJS兼容


先对 Prismjs 中需要预加载的部分进行设置:

找到 58 行:

<script>var pres = document.getElementsByTagName('pre');
改为:
<script data-no-instant>var pres = document.getElementsByTagName('pre');
找到 64 行:
<script src="' . $jsUrl . '"></script>
改为:
<script src="' . $jsUrl . '" data-no-instant></script>
找到 66 行:
<script defer="defer" src="' . Helper::options()->pluginUrl . '/Prismjs/line-number-wrap-fix.js' . '"></script>
改为:
<script defer="defer" src="' . Helper::options()->pluginUrl . '/Prismjs/line-number-wrap-fix.js' . '" data-no-instant></script>
再修改位于 footer.phpinstantclick 的白名单部分,添加属于 prismjs 的规则:
if (typeof Prism !== 'undefined') {<?php  if (Helper::options()->plugin('Prismjs')->showln): ?>
var pres = document.getElementsByTagName('pre');
    for (var i = 0; i < pres.length; i++){
        if (pres[i].getElementsByTagName('code').length > 0)
            pres[i].className  = 'line-numbers';} <?php endif; ?>
Prism.highlightAll(true,null);}
PHP 部分 {<?php if (Helper::options()→plugin('Prismjs')→showln): ?> 对判断插件是否使用了行号。如果没启用插件,会导致网站 505 错误。

如果不使用行号,直接使用以下代码:
if (typeof Prism !== 'undefined') {
Prism.highlightAll(true,null);}

Mathjax


Mathjax与InstantClick不兼容


footer.php 中找到 InstantClick.on('change', function(isInitialLoad) 部分,加入以下规则:

if (typeof MathJax !== 'undefined'){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);}

Mathjax的直接添加


header.php 中的 <head> 之间加入如下代码:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true
    },
    "HTML-CSS": { availableFonts: ["TeX"] }
  });
</script>
<script type="text/javascript"
   src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
注:近日 MathJax 自营 CDN 已经停止服务,需自行寻找相关 CDN。

Icomoon




~~DISQUS~~