Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

使用Sphinx生成/管理文档

很多开源的软件都使用Sphinx来进行文档的管理,其中Ansible就是其中一个。

Sphinx使用 类MarkDown的reStructuredText格式 来进行内容的编写,然后使用 sphinx-build 命令来生成html文件。

安装、入门

1
2
3
4
sudo apt-get install python-pip
sudo pip install Sphinx

sphinx-quickstart

引用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

*重点(emphasis)通常显示为斜体*
`解释文字(interpreted text)通常显示为斜体`

**重点强调(strong emphasis)通常显示为粗体**

``行内文本(inline literal)通常显示为等宽文本,空格可以保留,但是换行不可以。``

章节头部由下线(也可有上线)和包含标点的标题 组合创建, 其中下线要至少等于标准文本的长度。
可以表示标题的符号有 =、-、`、:、'、"、~、^、_ 、* 、+、 #、<、> 。
对于相同的符号,有上标是一级标题,没有上标是二级标题。
标题最多分六级,可以自由组合使用。

# with overline, for parts
* with overline, for chapters
=, for sections
-, for subsections
^, for subsubsections
", for paragraphs

主题

1
2
3
sudo pip install sphinx_rtd_theme

sed -i "/html_theme/s/.*/html_theme = 'sphinx_rtd_theme'/" conf.py

管理历史文档

先使用 html2rest 把html转成reStructuredText格式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo pip install html2rest

#JSON:原始文档层次结构
  [
  { "id": "a16", "pId": "a", "name": "Administration", "file": "output/AdministrativeDocumentation.html" }, 
  { "id": "a1617", "pId": "a16", "name": "Basic Configuration Guide" },
  { "id": "a161718", "pId": "a1617", "name": "Configuring Deployments", "file": "output/ConfiguringDeployments.html" }
  ]


name=administration
cat $name.json | jq '.[].file' | sed 's/"//g' | while read line ; do cp "$line" $name.origin/  ; done
cd $name.origin
ls | while read f ; do html2rest $f >"../$name.rst/${f%%.*}.rst" ; done

这仅仅是把html转换成了reStructuredText格式,当然我们还可以做多一些的操作:把文件结构也创建出来。

docs-gen.sh脚本内容如下:

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
56
57
58
59
60
61
#!/bin/bash

JSON_FILE=~/administration.json

function children(){
local id=$1

local name="$( cat "$JSON_FILE" | jq '.[] | select(.id=="'$id'")' | jq '.name' | sed 's/"//g' )"
echo "id: $id, name: $name"

local filename="$( echo $name | sed 's/[^[:alnum:]]//g' )"

if [ ! -f "$filename.rst" ] ; then
cat > "$filename.rst" <<EOF
$name
======================================

EOF
fi

local nodes="$( cat "$JSON_FILE" | jq '.[] | select(.pId=="'$id'")' )"

if [ "x$nodes" == "x" ] ; then 
  return 1
fi

# if have children, create folder and toc
local foldername="$( echo $name | sed 's/[^[:alnum:]]//g' )"
local names="$( echo "$nodes" | jq ".name" | sed 's/[^[:alnum:]]//g' )"
local ids="$( echo "$nodes" | jq ".id" | sed 's/[^[:alnum:]]//g' )"

if ! grep '.. toctree::' "$foldername.rst" ; then
cat >>"$foldername.rst" <<EOF

Contents:

.. toctree::
   :maxdepth: 3
   :titlesonly:
   :hidden:
   :glob:
   
$( echo "$names" | sed "s#^#   $foldername/#" ) 

EOF
fi

mkdir -p "$foldername"
pushd "$foldername"

while read cid
do 
  children $cid
done < <(echo "$ids")

popd

}


children a

然后执行该命令,把目录、目录索引、临时文件创建好:

1
2
cd ~/administration
./docs-gen.sh

然后就是把最开始转换的rst文件拷贝过来:

1
2
3
4
5
6
7
8
9
10
cd ../administration.rst

ls | while read f ; do 
filename="$(echo $f | sed 's/.rst$//' | sed 's/[^[:alnum:]]//g' ).rst" ; 
find ../administration/ -name "$filename" -exec /bin/cp -f $f {} \;  ;  
done

#再执行一遍docs-gen.sh,把目录的索引再(确认)添加一次文件末尾
cd ../administration
./docs-gen.sh

完后生成 make html ,直接打开 _build/html/index.html 查看下内容。

最后就是根据具体情况,做一些细微的调整了。

  • 处理图片,修改 /usr/local/lib/python2.7/dist-packages/html2rest.py
  • 处理文档内互相引用的链接
  • 给标题添加TAG

生成PDF

除了生成html外,还可以直接编译成PDF,方便携带和查看。(官网是推荐使用latexpdf,但这得安装latex…)

1
2
3
4
5
6
7
8
9
10
[root@ansible workspace]# pip install rst2pdf

[root@ansible workspace]# vi conf.py 
...
#extensions = ['sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.pngmath']
extensions = ['sphinx.ext.doctest', 'sphinx.ext.todo', 'rst2pdf.pdfbuilder']

pdf_documents = [('index', u'Workspace', u'Workspace Doc', u'winse'),]

[root@ansible workspace]# sphinx-build -b pdf . _build/pdf

或者用 singlehtml 临时代替下也行。

1
make singlehtml

MISC

–END

使用TeamviewerVPN访问公司内网

一直以来都只是用Teamviewer的图形界面,如果仅仅针对单台机器操作还是蛮OK的。但是如果想要访问远程的整个集群,那就为难了。

以前通过 公司的跳板机 ,然后连接 内网搭建的VPN 来实现 透明 的访问公司的环境。也折腾过自己买一台aliyun的机器搞一个外网IP,然后通过SSH的反向代理来间接的跳转访问公司内网,但成本都还是比较高的。

既然Teamviewer提供了一种远程访问的方式,那么能不能通过Teamviewer来实现代理,继而类似于VPN的方式在家访问公司内网呢?

备注:一般最好双保险啊,Teamviewer和Anydesk都放一个!!!

安装

Teamviewer是提供了VPN的访问方式,需要在安装的时刻 选择【显示高级设置】,在下一步中选择【使用Teamviewer VPN】。连接的 两台主机都需要安装Teamviewer VPN 的功能!!!

使用VPN

更详细一点的:

访问内网

如果是Linux的话,可以在iptables上面配置SNAT,但是Linux Teamviewer暂时不支持VPN功能。 并且公司运行Teamviewer的机器是WIN7,不能通过运行nat命令(server版本才有)来设置转发。最后功夫不负有心人,找到了在win7下可以设置NAT的方法:

转发配置

  1. 连接的两台机器都启动 Routing an Remote Access 系统服务。(修改注册表IPEnableRouter的,不弄也行)
  2. 在公司Teamviwer机器上,下载并安装 NAT配置工具
  3. 在公司Teamviwer机器上,打开配置工具 WinpkFilter - Internet Gateway ,配置 本地连接 为Provider, Teamviewer VPN 为Client,然后启动 Start NAT。

  1. 在本地机器上,添加route,把访问 公司内网IP 的数据转到公司Teamviewer VPN,这样我们就可以透明的访问公司的所有机器了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#网关填公司Teamviewer端的IP地址!!!
C:\Windows\system32>route add 192.168.193.0 mask 255.255.255.0 7.138.125.65 metric 1

C:\Windows\system32>ping 192.168.193.110

正在 Ping 192.168.193.110 具有 32 字节的数据:
来自 192.168.193.110 的回复: 字节=32 时间=22ms TTL=63
来自 192.168.193.110 的回复: 字节=32 时间=21ms TTL=63
来自 192.168.193.110 的回复: 字节=32 时间=21ms TTL=63

192.168.193.110 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 21ms,最长 = 22ms,平均 = 21ms

完美,所有的事情Teamviewer都帮想到,并且实现了。

把上面的全部操作写到一个脚本,以后直接使用管理员权限运行即可:

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
winse@DESKTOP-ADH7K1Q:~/bigendian$ cat VPN-Route.bat
@setlocal enableextensions enabledelayedexpansion
@echo on

rem https://community.teamviewer.com/t5/Knowledge-Base/Are-there-parameters-to-start-TeamViewer/ta-p/4135
rem teamviewer.exe -i <ID> -P <Password> [-m fileTransfer/vpn]
start "teamviewer" "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"

set teamvpnipaddr=7.138.125.65

:loop
ping -n 1 !teamvpnipaddr! | find "TTL"
if not errorlevel 1 goto :run
if errorlevel 1 goto :endloop
:endloop
ping -n 2 127.0.0.1 >nul: 2>nul:
cls
goto :loop

:run
route delete 192.168.193.0
route add 192.168.193.0 mask 255.255.255.0 !teamvpnipaddr! metric 1

endlocal

pause

参考的原文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Hello everybody, I investigated a lot for this issue.
Establish a VPN session with TeamViewer to my home pc (remote side) and try to get access to this local network from my working place (local side).
I found an solution i never read anywhere before. Since Windows 7 has removed NAT option using netsh it is difficult to solve it with windows on board tools only.
- Install TeamViewer incl. VPN driver on both sides, activate unattended access on the remote side (my home pc). Use the button Show advanced options, and go to Advanced network options … Install VPN driver
- Install WinPkFilter Device Driver on remote side (my home pc) and restart (http://www.nat32.com/v2/install.htm Download installer: http://www.ntkernel.com/downloads/winpkflt_rtl.zip . NAT32 you don't need. This WinPkFilter package contains a simple GUI to configure the NAT between the VPN interface (client) and the remote side LAN interface (provider). see following hints ...
- Windows: Start RemoteAccess - service 'Routing an Remote Access'  and set to automatic (local/remote side).
- Optional: On the remote side (my home pc), the registry has to be modified. Start the registry editor for example by Regedt32, and browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters Set the parameter IPEnableRouter to “1”. Using console or batch as admin: reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "IPEnableRouter" /t REG_DWORD /d "1". On my system it worked without this option, but according internet forums it seems to be recommended.
- Now create a remote desktop session to your home pc and start also the VPN connection within this TeamViewer session (Menu / Extras / VPN). I created a free TeamViewer account and added all pc's to my computers to make the access to my machines easier.
- On remode side (my home pc) where WinPkFilter is installed start the Internet Gateway GUI of WinPkFilter: Start / Programms / WinpkFilter / Internet Gateway. Select (double click) the ethernet adapter of your local privat lan and set NAT Status to 'Provider'. Select the TeamViewer VPN adapter and set NAT Status to 'client'. Press 'Start NAT'
 - On local side (my working place) Add a route to the local side (my working place) to give access to several devices that have the same subnet, add the route like this:

route add <base IP of remote devices> mask 255.255.255.0 <IP of Teamviewer VPN on remote PC> 
metric 1

Example (home lan ip range: 192.168.2.x / TeamViewer VPN IP in home pc (remote side) 7.37.88.245
route add 192.168.2.0 mask 255.255.255.0 7.37.88.245 metric 1 <ENTER>
route add 192.168.2.0 mask 255.255.255.0 7.37.88.245 metric 1 -p <ENTER> (if persistent)
Do delete the route route delete 192.168.2.0
Now you should have access to your private home network. Good luck and have fun.

–END

Windows Run Ubuntu

@@更新 2021-05-25 [wsl-Ubuntu 20.04.2 LTS] 配置octopress @@更新 2023-11-28 [wsl-Ubuntu 22.04.2 LTS (Jammy Jellyfish)] 配置octopress

最新版的Windows已经可以安装ubuntu了,算是微软开源后的一个阶段性的成果了。

功能和windows兼容性很强(不像cygwin),软链接、文件权限都是和系统一致的。并且基本所有ubuntu的功能都可以使用,安装jekyll、docker都很顺利。同时打开系统的程序也很方便。非常赞和值得程序员去尝试!!

本文后面会逐渐增加使用过程中的一些操作,今天先更新系统安装、octopress安装、docker安装。

系统安装

直接去微软的官网下载最新版系统ISO,然后安装系统 专业版 (教育版比较干净一些,但是网上没有破解方式啊)。

Ubuntu

The Windows Subsystem for Linux lets developers run Linux environments – including most command-line tools, utilities, and applications – directly on Windows, unmodified, without the overhead of a virtual machine.

安装Ubuntu

最新版的Ubuntu已经进入到稳定版。直接打开商店,搜索Ubuntu,然后安装即可。大概200M的样子,很快就安装了。然后Launch会初始化创建用户。

相关的一些有用的文档:

安装mintty

CMD方式操作Ubuntu太难受了,mintty操作就像SecurtCRT一样,简单方便。安装 wsltty-1.8.0-install ,使用mintty来运行ubuntu。

默认mintty的配置放在 %APPDATA%\wsltty。在子目录theme下可以 http://ciembor.github.io/4bit/ 下载一个主题放到该目录下,然后在mintty配置页面选择该主题。

系统文件

root挂载点:C:\Users\<user>\AppData\Local\lxss or C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState

安装Jekyll

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
# https://superuser.com/questions/116625/recursively-change-owner-windows-7
#takeown /f "C:\path\to\folder" /r
#icacls "C:\path\to\folder" /reset /T
用powershell管理员权限 "提"权
PS E:\winsegit\octopress> takeown /F . /R
修改就旧系统的文件属性:
PS E:\winsegit\octopress> cacls *.* /T /G Everyone:F

sudo apt-get update
sudo apt-get install ruby-bundler
sudo apt-get install ruby-dev
sudo apt-get install make
sudo apt-get install gcc
bundle install

sudo gem update
sudo gem uninstall rake
sudo gem install rake -v 10.5.0
# sudo apt-get install nodejs
   
rake preview

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/var/lib/gems/2.3.0/gems/liquid-2.6.1/lib/liquid/htmltags.rb:43: warning: key "index0" is duplicated and overwritten on line 46
[2017-10-29 22:48:09] INFO  WEBrick 1.3.1
[2017-10-29 22:48:09] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu]
[2017-10-29 22:48:09] INFO  WEBrick::HTTPServer#start: pid=39 port=4000
Configuration file: /mnt/e/winsegit/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.
                  

上面warning提示也有对应的Issue,但也没所谓暂时不理: https://github.com/Microsoft/WSL/issues/1426

UPDATE 2023年11月18日09:22:51 (WSL1 + rvm)

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
winse@DESKTOP-BR4MG38:octopress$ sudo apt install make gcc -y
[sudo] password for winse:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gcc is already the newest version (4:11.2.0-1ubuntu1).
gcc set to manually installed.
make is already the newest version (4.3-4.1build1).
make set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 101 not upgraded.

winse@DESKTOP-BR4MG38:octopress$ gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: key 105BD0E739499BDB: 2 duplicate signatures removed
gpg: /home/winse/.gnupg/trustdb.gpg: trustdb created
gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: Total number processed: 2
gpg:               imported: 2
winse@DESKTOP-BR4MG38:octopress$ curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Sat 16 Jan 2021 02:46:22 AM CST
gpg:                using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/home/winse/.rvm/archives/rvm-1.29.12.tgz'
Installing RVM to /home/winse/.rvm/
    RVM PATH line found in /home/winse/.bashrc.
    RVM PATH line not found for Zsh, rerun this command with '--auto-dotfiles' flag to fix it.
    RVM sourcing line found in /home/winse/.bash_profile.
    RVM sourcing line not found for Zsh, rerun this command with '--auto-dotfiles' flag to fix it.
Installation of RVM in /home/winse/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/winse/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉  Donate: https://opencollective.com/rvm/donate


winse@DESKTOP-BR4MG38:octopress$

##-> @see https://github.com/rvm/rvm/issues/4764#issuecomment-624796884
  Open your terminal
  run /etc/apt/sources.list using vi /etc/apt/sources.list (It is possible that you can't save this file, and might get "permission denied" error. SO, in that case, open this file with sudo vi /etc/apt/sources.list)
  after opening it, go to the end of file and paste this line:
  deb http://security.ubuntu.com/ubuntu bionic-security main
  save this file by typing :wq
  now, paste this command in terminal:
  sudo apt update && apt-cache policy libssl1.0-dev
  You will see an update like libssl1.0-dev: Installed: (none) Candidate: 1.0.2n-1ubuntu5.3 Version table: 1.0.2n-1ubuntu5.3 500 500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
  then, run this command:
  sudo apt-get install libssl1.0-dev

winse@DESKTOP-BR4MG38:~$ sudo apt update && apt-cache policy libssl1.0-dev
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Get:6 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1,162 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [998 kB]
Reading package lists... Done
W: GPG error: http://security.ubuntu.com/ubuntu bionic-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://security.ubuntu.com/ubuntu bionic-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

##--> @see https://askubuntu.com/questions/943539/the-following-signatures-couldnt-be-verified-because-the-public-key-is-not-avai

winse@DESKTOP-BR4MG38:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3B4FE6ACC0B21F32
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.Ak5EisV4UJ/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3B4FE6ACC0B21F32
gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

winse@DESKTOP-BR4MG38:~$ sudo apt update && apt-cache policy libssl1.0-dev
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
103 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
libssl1.0-dev:
  Installed: (none)
  Candidate: 1.0.2n-1ubuntu5.13
  Version table:
     1.0.2n-1ubuntu5.13 500
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages

winse@DESKTOP-BR4MG38:~$ sudo apt-get install libssl1.0-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libssl1.0.0
The following NEW packages will be installed:
  libssl1.0-dev libssl1.0.0
0 upgraded, 2 newly installed, 0 to remove and 103 not upgraded.
Need to get 2,455 kB of archives.
After this operation, 10.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://security.ubuntu.com/ubuntu bionic-security/main amd64 libssl1.0.0 amd64 1.0.2n-1ubuntu5.13 [1,089 kB]
Get:2 http://security.ubuntu.com/ubuntu bionic-security/main amd64 libssl1.0-dev amd64 1.0.2n-1ubuntu5.13 [1,366 kB]
Fetched 2,455 kB in 4s (665 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libssl1.0.0:amd64.
(Reading database ... 29956 files and directories currently installed.)
Preparing to unpack .../libssl1.0.0_1.0.2n-1ubuntu5.13_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2n-1ubuntu5.13) ...
Selecting previously unselected package libssl1.0-dev:amd64.
Preparing to unpack .../libssl1.0-dev_1.0.2n-1ubuntu5.13_amd64.deb ...
Unpacking libssl1.0-dev:amd64 (1.0.2n-1ubuntu5.13) ...
Setting up libssl1.0.0:amd64 (1.0.2n-1ubuntu5.13) ...
Setting up libssl1.0-dev:amd64 (1.0.2n-1ubuntu5.13) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
winse@DESKTOP-BR4MG38:~$

winse@DESKTOP-BR4MG38:octopress$ rvm install 2.3
Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/22.04/x86_64/ruby-2.3.8.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for ubuntu.
Requirements installation successful.
Installing Ruby from source to: /home/winse/.rvm/rubies/ruby-2.3.8, this may take a while depending on your cpu(s)...
ruby-2.3.8 - #downloading ruby-2.3.8, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.7M  100 13.7M    0     0  3149k      0  0:00:04  0:00:04 --:--:-- 3149k
ruby-2.3.8 - #extracting ruby-2.3.8 to /home/winse/.rvm/src/ruby-2.3.8.....
ruby-2.3.8 - #configuring..........................................................
ruby-2.3.8 - #post-configuration..
ruby-2.3.8 - #compiling.............................................................................................................................................................................................................................................
ruby-2.3.8 - #installing..............
ruby-2.3.8 - #making binaries executable..
ruby-2.3.8 - #downloading rubygems-3.0.9
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  865k  100  865k    0     0   701k      0  0:00:01  0:00:01 --:--:--  701k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.3.8 - #extracting rubygems-3.0.9.....
ruby-2.3.8 - #removing old rubygems........
ruby-2.3.8 - #installing rubygems-3.0.9................................................................
ruby-2.3.8 - #gemset created /home/winse/.rvm/gems/ruby-2.3.8@global
ruby-2.3.8 - #importing gemset /home/winse/.rvm/gemsets/global.gems..............................there was an error installing gem rubygems-bundler
.............................
ruby-2.3.8 - #generating global wrappers........
ruby-2.3.8 - #gemset created /home/winse/.rvm/gems/ruby-2.3.8
ruby-2.3.8 - #importing gemsetfile /home/winse/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.8 - #generating default wrappers........
ruby-2.3.8 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.3.8 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
winse@DESKTOP-BR4MG38:octopress$

winse@DESKTOP-BR4MG38:octopress$ rvm list
   ruby-2.3.8 [ x86_64 ]

# Default ruby not set. Try 'rvm alias create default <ruby>'.

# => - current
# =* - current && default
#  * - default

winse@DESKTOP-BR4MG38:octopress$

winse@DESKTOP-BR4MG38:octopress$ bash --login
winse@DESKTOP-BR4MG38:octopress$ rvm use 2.3.8 --default
Using /home/winse/.rvm/gems/ruby-2.3.8

##--> @see https://mirrors.tuna.tsinghua.edu.cn/help/rubygems/

winse@DESKTOP-BR4MG38:octopress$ unset HTTPS_PROXY
winse@DESKTOP-BR4MG38:octopress$ bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems

winse@DESKTOP-BR4MG38:octopress$ bundle install
Fetching source index from https://mirrors.tuna.tsinghua.edu.cn/rubygems/
Resolving dependencies...
Fetching rake 10.5.0
Installing rake 10.5.0
Fetching RedCloth 4.2.9
Installing RedCloth 4.2.9 with native extensions
Fetching bigdecimal 1.3.2
Installing bigdecimal 1.3.2 with native extensions
Fetching blankslate 2.1.2.4
Installing blankslate 2.1.2.4
Using bundler 1.17.3
Fetching timers 1.1.0
Installing timers 1.1.0
Fetching celluloid 0.15.2
Installing celluloid 0.15.2
Fetching chunky_png 1.3.1
Installing chunky_png 1.3.1
Fetching fast-stemmer 1.0.2
Installing fast-stemmer 1.0.2 with native extensions
Fetching classifier 1.3.4
Installing classifier 1.3.4
Fetching coffee-script-source 1.7.1
Installing coffee-script-source 1.7.1
Fetching execjs 2.2.1
Installing execjs 2.2.1
Fetching coffee-script 2.3.0
Installing coffee-script 2.3.0
Fetching colorator 0.1
Installing colorator 0.1
Fetching fssm 0.2.10
Installing fssm 0.2.10
Fetching sass 3.2.19
Installing sass 3.2.19
Fetching compass 0.12.6
Installing compass 0.12.6
Fetching ffi 1.9.3
Installing ffi 1.9.3 with native extensions
Fetching tilt 1.4.1
Installing tilt 1.4.1
Fetching haml 4.0.5
Installing haml 4.0.5
Fetching jekyll-coffeescript 1.0.0
Installing jekyll-coffeescript 1.0.0
Fetching jekyll-gist 1.1.0
Installing jekyll-gist 1.1.0
Fetching jekyll-paginate 1.0.0
Installing jekyll-paginate 1.0.0
Fetching jekyll-sass-converter 1.0.0
Installing jekyll-sass-converter 1.0.0
Fetching rb-fsevent 0.9.4
Installing rb-fsevent 0.9.4
Fetching rb-inotify 0.9.5
Installing rb-inotify 0.9.5
Fetching listen 2.7.9
Installing listen 2.7.9
Fetching jekyll-watch 1.0.0
Installing jekyll-watch 1.0.0
Fetching kramdown 1.4.0
Installing kramdown 1.4.0
Fetching liquid 2.6.1
Installing liquid 2.6.1
Fetching mercenary 0.3.4
Installing mercenary 0.3.4
Fetching posix-spawn 0.3.8
Installing posix-spawn 0.3.8 with native extensions
Fetching yajl-ruby 1.1.0
Installing yajl-ruby 1.1.0 with native extensions
Fetching pygments.rb 0.6.0
Installing pygments.rb 0.6.0
Fetching redcarpet 3.1.2
Installing redcarpet 3.1.2 with native extensions
Fetching safe_yaml 1.0.4
Installing safe_yaml 1.0.4
Fetching parslet 1.5.0
Installing parslet 1.5.0
Fetching toml 0.1.1
Installing toml 0.1.1
Fetching jekyll 2.1.1
Installing jekyll 2.1.1
Fetching jekyll-date-format 1.0.0
Installing jekyll-date-format 1.0.0
Fetching jekyll-page-hooks 1.3.0
Installing jekyll-page-hooks 1.3.0
Fetching jekyll-sitemap 0.5.0
Installing jekyll-sitemap 0.5.0
Fetching json 1.8.2
Installing json 1.8.2 with native extensions
Fetching rack 1.5.2
Installing rack 1.5.2
Fetching rack-protection 1.5.3
Installing rack-protection 1.5.3
Fetching rdiscount 2.1.7.1
Installing rdiscount 2.1.7.1 with native extensions
Fetching rubypants 0.2.0
Installing rubypants 0.2.0
Fetching sass-globbing 1.0.0
Installing sass-globbing 1.0.0
Fetching sinatra 1.4.5
Installing sinatra 1.4.5
Fetching stringex 1.4.0
Installing stringex 1.4.0
Bundle complete! 16 Gemfile dependencies, 50 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from haml:

HEADS UP! Haml 4.0 has many improvements, but also has changes that may break
your application:

* Support for Ruby 1.8.6 dropped
* Support for Rails 2 dropped
* Sass filter now always outputs <style> tags
* Data attributes are now hyphenated, not underscored
* html2haml utility moved to the html2haml gem
* Textile and Maruku filters moved to the haml-contrib gem

For more info see:

http://rubydoc.info/github/haml/haml/file/CHANGELOG.md

winse@DESKTOP-BR4MG38:octopress$

winse@DESKTOP-BR4MG38:octopress$ rake preview
Starting to watch source with Jekyll and Compass. Starting Rack on port 14000
/home/winse/.rvm/gems/ruby-2.3.8/gems/liquid-2.6.1/lib/liquid/htmltags.rb:43: warning: key "index0" is duplicated and overwritten on line 46
[2023-11-18 09:42:44] INFO  WEBrick 1.3.1
[2023-11-18 09:42:44] INFO  ruby 2.3.8 (2018-10-18) [x86_64-linux]
[2023-11-18 09:42:44] INFO  WEBrick::HTTPServer#start: pid=24150 port=14000
Configuration file: /mnt/e/winsegit/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.

UPDATE 2021-05-25 24:09 (wsl-linux + rvm)

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
sudo apt-get update
sudo apt-get install make
sudo apt-get install gcc

## https://ruby-china.org/wiki/rvm-guide

winse@LAPTOP-I9ECVAQ4:e$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

# curl -sSL https://get.rvm.io | bash -s stable
# https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer
winse@LAPTOP-I9ECVAQ4:e$ cat rvm-installer.txt | bash -s stable 

winse@LAPTOP-I9ECVAQ4:e$ echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > ~/.rvm/user/db


# 依赖安装
## https://www.garron.me/en/linux/install-ruby-2-3-3-ubuntu.html
Edit this file /etc/apt/sources.list and add this line to the end of it.

deb http://security.ubuntu.com/ubuntu bionic-security main

After that run:

sudo apt update && apt-cache policy libssl1.0-dev

Finally,

sudo apt-get install libssl1.0-dev

##END

winse@LAPTOP-I9ECVAQ4:~$ rvm install 2.3

winse@LAPTOP-I9ECVAQ4:~$ rvm list

winse@LAPTOP-I9ECVAQ4:~$ bash --login
winse@LAPTOP-I9ECVAQ4:~$ rvm use 2.3.8 --default
Using /home/winse/.rvm/gems/ruby-2.3.8

## 
winse@LAPTOP-I9ECVAQ4:octopress$ bundle install

winse@LAPTOP-I9ECVAQ4:octopress$ rake preview

winse@DESKTOP-BR4MG38:~$ ln -s /mnt/e/local/npp/notepad++.exe text

安装docker

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
winse@DESKTOP-ADH7K1Q:~$ uname -r
4.4.0-43-Microsoft
winse@DESKTOP-ADH7K1Q:~$ uname -a
Linux DESKTOP-ADH7K1Q 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

winse@DESKTOP-ADH7K1Q:~$  sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common

winse@DESKTOP-ADH7K1Q:~$ lsb_release -cs
xenial
winse@DESKTOP-ADH7K1Q:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
winse@DESKTOP-ADH7K1Q:~$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

winse@DESKTOP-ADH7K1Q:~$ sudo apt-get update

winse@DESKTOP-ADH7K1Q:~$ sudo apt-get install docker-ce

winse@DESKTOP-ADH7K1Q:~$ sudo service docker start
 * Starting Docker: docker                                                                                                                     [ OK ]
winse@DESKTOP-ADH7K1Q:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
winse@DESKTOP-ADH7K1Q:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
winse@DESKTOP-ADH7K1Q:~$

运行windows系统应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
winse@DESKTOP-ADH7K1Q:~$ ln -s /mnt/e/local/usr/share/npp/notepad++.exe text

winse@DESKTOP-ADH7K1Q:~$ cp -r ../winse-cygwin/new_post.sh ./
winse@DESKTOP-ADH7K1Q:~$ cat new_post.sh
cd ~/winsegit/octopress/
rake new_post["$1"] | tail -1 | awk -F: '{print $2}' | while read line
do
name=${line#source/_posts/}
newpath=source/_stash/$name
mv $line $newpath

echo -e "\n\n--END" >>$newpath

~/text $newpath &
done

winse@DESKTOP-ADH7K1Q:~$ ./new_post.sh "windows run ubuntu"
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
mkdir -p source/_posts

重新配置git

用powershell修改原来的权限后,然后用shell来进行设置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#powershell
takeown /F . /R
cacls *.* /T /G Everyone:F

#ubuntu shell
winse@DESKTOP-ADH7K1Q:~$ cp -r ../winse-cygwin/.ssh ./

winse@DESKTOP-ADH7K1Q:~$ cd .ssh
winse@DESKTOP-ADH7K1Q:~/.ssh$ chmod 600 id_rsa authorized_keys
winse@DESKTOP-ADH7K1Q:~/.ssh$ chmod 644 id_rsa.pub config

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress/_deploy$ rm -rf *
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress/_deploy$ git clone git@github.com:winse/winse.github.com.git ./

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ git config --global user.email winseliu@qq.com
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ git config --global user.name winse

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ sh public.git.sh

–END

在Cenots7双击运行程序

Linux本来就是作为服务器来运行的,双击运行程序的需求比较少。但是还是有一些,同时也没有Windows桌面快捷方式那么的方便。

在Centos7中建立”快捷方式”双击运行,需要建立一个desktop类型的文件:

1
2
3
4
5
6
7
[root@k8s ~] cat ~/Desktop/Cassandra.desktop
[Desktop Entry]
Name=Cassandra
Comment=Launch Cassandra
Exec=su - hadoop /home/hadoop/apache-cassandra-2.2.10/bin/cassandra -f
Terminal=true
Type=Application

右键创建快捷的方式,在Centos7上面没有找到。

In Gnome : - right click on the desktop and ‘create launcher’ - browse to the script location and give a name

参考

–END

使用Flamegraph查看磁盘使用情况

以前有使用FlameGraph做Java程序的堆栈(热点代码)的显示。其实磁盘也可以使用类似的方式来显示查看占用情况,找出没用的数据。

1
2
3
4
5
$ git clone https://github.com/brendangregg/FlameGraph.git

#使用管理员权限运行
winse@Lenovo-PC /cygdrive/e/git/FlameGraph
$ ./files.pl /cygdrive/c/ | ./flamegraph.pl --hash --countname=bytes > /cygdrive/r/c.svg

然后浏览器查看即可,主要还是查看占用比。(但是不一定所有文件都包括在SVG里面)。

当然,默认官网提供的 files.pl 是获取所有的目录。我们可以做下层级控制,代码修改如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ git diff
diff --git a/files.pl b/files.pl
index 27654be..5d1012e 100755
--- a/files.pl
+++ b/files.pl
@@ -29,7 +29,16 @@ sub usage {
 usage() if @ARGV == 0 or $ARGV[0] eq "--help" or $ARGV[0] eq "-h";

 foreach my $dir (@ARGV) {
-    find(\&wanted, $dir);
+    find({
+       preprocess => \&preprocess,
+       wanted => \&wanted,
+    }, $dir);
+}
+
+sub preprocess {
+       my $depth = $File::Find::dir =~ tr[/][];
+       return @_ if $depth < 8;
+       return ;
 }

 sub wanted {

下列的文件夹可以排查下进行处理:

  • C:\pagefile.sys C:\swapfile.sys : 系统属性-高级-性能选项-虚拟内存
  • C:\hiberfil.sys : powercfg -h -zie 60% ; powercfg.exe /hibernate off
  • C:\ProgramData\Package Cache

参考

–END