kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

octopress+github建立个人博客

github能登录,无法点开个人设置页面

直接打开 https://github.com/settings

rake preview 时间格式

1
2
3
4
vim /usr/local/lib/ruby/gems/2.3.0/gems/rack-1.6.11/lib/rack/commonlogger.rb

#        now.strftime("%d/%b/%Y:%H:%M:%S %z"),
        now.strftime("%Y-%m-%d %H:%M:%S.%L %z"),

格式变化

1
2
3
192.168.120.177 - - [03/Nov/2022:08:51:15 +0800] "GET /favicon.png HTTP/1.1" 200 400 0.0009
变为
192.168.120.177 - - [2022-11-03 09:51:51.783 +0800] "GET /favicon.png HTTP/1.1" 200 400 0.0009

修复错误

错误

1
ArgumentError on line ["58"] of /usr/local/lib/ruby/gems/2.3.0/gems/fssm-0.2.10/lib/fssm/support.rb: comparison of String with 0 failed

vim /usr/local/lib/ruby/gems/2.3.0/gems/fssm-0.2.10/lib/fssm/support.rb

58行

1
2
3
4
-          version[0] > 0 || version[1] >= 6
+          version = version.split(".")
+          #p version, version[0], version[1]
+          version[0].to_i > 0 || version[1].to_i >= 6

127.0.0.1 改为 本机IP

vim Rakefile

1
2
-  rackupPid = Process.spawn("rackup --port #{server_port}")
+  rackupPid = Process.spawn("rackup --host 0.0.0.0 --port #{server_port}")

静态建立blog

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
ubuntu 18.04:
	openssl 编译错误,需要先卸载 libssl-dev,再编译安装
	vim /usr/local/lib/ruby/2.3.0/net/https.rb 删除 require 'openssl'

ubuntu 16.04:

sudo apt-get install zlib1g-dev libssl-dev

git clone https://github.com/abcdxyzk/abcdxyzk.github.io_base.git

tar xf ruby-2.3.8.tar.gz
cd ruby-2.3.8
make
make install

zlib:
	cd ext/zlib
	ruby extconf.rb  
	make
	make install


openssl:
	cd ext/openssl
	ruby extconf.rb  
	make
	make install

	这时出错,make: *** No rule to make target `/include/ruby.h', needed by `ossl.o'

	其实是ext/openssl/Makefile中忘了给路径变量top_srcdir赋值,调用的时候当然就报错了,修改 Makefile 增加 top_srcdir = ../..

	出错2:
	openssl_missing.h:78:35: error: macro "EVP_MD_CTX_create" passed 1 arguments,but takes just 0
	EVP_MD_CTX *EVP_MD_CTX_create(void);
	...
	解决2:
	sudo apt purge libssl-dev && sudo apt install libssl1.0-dev


### ubuntu_ruby_gems_2.3.0.tar || centos_ruby_gems_2.3.0.tar

sudo cp -r usr/local/lib/ruby/gems/2.3.0/* /usr/local/lib/ruby/gems/2.3.0/


### centos or ubuntu: ubuntu_local_bin.tar

sudo cp bundler bundle compass jekyll /usr/local/bin/
sudo cp bayes.rb  kramdown  listen  rackup  safe_yaml  summarize.rb  tilt  /usr/local/bin/


mkdir public

rake preview
rake renerate

对于ruby低于1.9.3,下载 http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p551.tar.bz2

高于1.9.3 ???

有时https连不了,http却可以,所以修改Gemfile

1
2
3
4
5
6
7
8
9
10
diff --git a/Gemfile b/Gemfile
index b02ee4b..7f7aac3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,4 @@
-source "https://rubygems.org"
+source "http://rubygems.org"
 
 group :development do
   gem 'rake', '~> 10.0'

Step 1 安装git ruby nodejs

1
2
sudo apt-get install git zlib1g-dev libyaml-dev openssl libssl-dev tcl-dev tk-dev node/nodejs
sudo apt-get install ruby ruby-dev 安装的版本偏低不行,要1.9.3以上https://www.ruby-lang.org/en/downloads/

Step 2 准备octopress

1
2
3
4
5
6
7
8
9
git clone git://github.com/imathis/octopress.git octopress
cd octopress    # 如果你使用RVM, 你会被询问你是否信任 .rvmrc 文件 (选择 yes).
ruby --version  # 这条命令应该输出 Ruby 1.9.3
然后安装依赖
sudo gem install bundler
rbenv rehash    # 如果你使用 rbenv, 执行 rehash 以运行 bundle 命令 (好像不需要这条)
bundle install    # 在octopress目录运行
最后安装默认主题
rake install

Step 3 部署到github上

(1)以 用户名/用户名.github.io 的格式建立一个新项目。
(2)部署
首先运行
rake setup_github_pages
这条命令会询问你刚才建立的项目的地址,按提示输入,然后就会生成一些用于部署的文件和deploy目录,deploy目录就是对应master分支。 接着执行

1
2
rake generate
rake deploy  # 会cd到_deploy目录运行 commit 和 push

这两条命令会生成博客内容,然后添加到git中,自动执行git commit然后推送到主分支(master branch)。几分钟后,你会收到github通知你你的提交已经被接受并发布了你的网站的email。

rake generate可能报错:

1
Error reading file /var/lib/gems/1.9.1/gems/jekyll-sitemap-0.6.1/lib/sitemap.xml: No such file or directory - /home/kk/kk/github/octopress/source/var/lib/gems/1.9.1/gems/jekyll-sitemap-0.6.1/lib/sitemap.xml

是jekyll-sitemap-0.6.1的bug,修改Gemfile.lock, jekyll-sitemap (0.6.1) 改成 jekyll-sitemap (0.6.3), 再

1
bundle install

不要忘记把为你的博客提交source(Don’t forget to commit the source for your blog)

1
2
3
git add .
git commit -m 'your message'
git push origin source # 记住只push source,要push master就得先pull一下,因为_deploy目录也对应master,而他一运行rake deploy就会push

Step 4 发布博客

你发布的文章被放在source/_posts目录下,并按照Jekyll的命名规则命名:YYYY-MM-DD-post- title.markdown。这个名字会被用于生成url且日期会被用于为文章按时间排序。 但这样比较麻烦,于是Octopress提供了一个rake task来自动按照正确的命名规则建立博文,并生成基本内容。
格式是:rake new_post[“title”]
样例:

1
2
rake new_post["tt"]  
# 这条命令会创建 source/_posts/2011-07-03-tt.markdown文件  

会生成如下内容的文件:

1
2
3
4
5
6
7
8
---
layout: post
title: "tt"
date: 2011-07-03 5:59
comments: true
external-url:
categories:
---

你可以在这里设置评论功能开关,设置分类。如果你的博客有多个作者共用,你可以在文件中添加【author:Your Name】。如果你在编辑一个草稿,你可以添加【published: false】以使其在生成博客内容时被自动忽略。

Step 5 生成 & 预览

rake generate # 在公开目录中生成博文和页面 rake watch # 查看 source/ and sass/ 的改动 rake preview # 在浏览器中输入 http://localhost:4000 即可预览。

Step 6 推送到github

rake deploy 然后过几分钟,github就会自动更新你的博客了。
注意:执行rake deploy前一定要先rake generate一下
不要忘记把为你的博客提交source(Don’t forget to commit the source for your blog)

1
2
3
git add .
git commit -m 'your message'
git push origin source 

另一台机子的时候

安装需要软件,然后clone自己的代码库

1
2
3
4
5
6
7
8
9
10
11
git checkout -b source origin/source
sudo gem install bundler
bundle install
rake install
rake setup_github_pages
mkdir _deploy
cd _deploy
git init
git remote add origin git@github.com:abcdxyzk/abcdxyzk.github.io.git
git pull origin master
cd ..

deploy目录就是对应master分支,所以必须要先保持一致
不然先运行rake deploy会在
deploy目录先commit,再push,这就会导致其他和另外机子上提交的冲突。
如果先rake deploy的话,可以在_deploy目录reset回去,然后pull。

记住多台机子操作的时候一开始先

1
2
3
4
需要保持_deploy/.git/config有master分支
git pull
cd _deploy
git pull