-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
169 lines (104 loc) · 69.7 KB
/
atom.xml
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Friends</title>
<link href="/atom.xml" rel="self"/>
<link href="http://cequn.wang/"/>
<updated>2018-08-28T08:18:04.649Z</updated>
<id>http://cequn.wang/</id>
<author>
<name>CequnWang</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>open edx platform -- Ubuntu 16.04 native installaton</title>
<link href="http://cequn.wang/2018/08/28/open-edx-platform-Ubuntu-16-04-native-install/"/>
<id>http://cequn.wang/2018/08/28/open-edx-platform-Ubuntu-16-04-native-install/</id>
<published>2018-08-28T07:00:00.000Z</published>
<updated>2018-08-28T08:18:04.649Z</updated>
<content type="html"><![CDATA[<p>最近在折腾edx平台,这个平台比较复杂,加上自己个人技术能力有限,瞎捣鼓了很长一段时间,现记录下过程中的一些使用及问题,方便以后查询。 <a id="more"></a></p><h3 id="创建云服务器实例">创建云服务器实例</h3>这里选用的是aliyun的美国服务器,因为在国内,受到防火墙的原因,安装基本会被各种奇怪的问题中断,尝试过很多遍都不成功,换了节点国外节点整个安装过程大概在2-3个小时。<li>为了节省花费,可选用弗吉尼亚的抢占式实例(比较了下应该是几个区域里最便宜的),个人选择了通用型(2vCPU,8GB,高效云盘50G),总体花费在0.09/时外加0.5/GB的出网流量,停机状态下,话费约为0.03/时,所以这个价格相对来说还是很划算的。</li><li><p>默认的是root登录,可创建个管理员账户 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">adduser <usrname></div><div class="line"># 修改/etc/sudoers</div><div class="line"><username> ALL=(ALL:ALL) ALL</div></pre></td></tr></table></figure></p><p>接下来进行更新 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">apt update -y</div><div class="line">apt upgrade -y</div><div class="line">reboot</div></pre></td></tr></table></figure></p></li><li><p>配置<code>~/.ssh/conf</code>添加Host,然后执行<code>ssh-copy-id <Host></code>将key复制到服务器上,这样可以通过</p><h3 id="安装edx">安装edx</h3></li><li><p>可参考<a href="https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/146440579/Native+Open+edX+Ubuntu+16.04+64+bit+Installation" target="_blank" rel="external">官方文档</a>的说明,这里可以执行以下脚本 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo wget https://raw.githubusercontent.com/cequn/edx.scripts/master/edx.platform-install.sh</div><div class="line">sudo chmod 755 edx.plaform-install.sh</div><div class="line">sudo ./edx.platform-install.sh</div></pre></td></tr></table></figure></p><p>整个安装过程约持续2-3个小时,这时候你可以去干点其他事情了 第三步的密码生成是可选的,如果已有了安装的平台,可以将密码拷贝过来,另外如果担心ssh中断问题,可以使用<code>nohup</code>来执行任务。最后,可以检查log目录下的文件来查看安装过否出现错误(目前来看,只要不是国内的节点,安装十分流畅,没有任何错误)</p></li><li>安装完成后,可以通过<code>sudo /edx/bin/supervisorctl status</code>来查看当前运行的进程 <待插入图片><li>通过ip来访问lms和studio(端口:18010)</li><li><p>创建管理员用户 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo su -s /bin/bash edxapp</div><div class="line">cd </div><div class="line">/edx/bin/python.edxapp /edx/bin/manage.edxapp lms manage_user <your-usr-name> <your-email> --staff --superuser --setting aws</div></pre></td></tr></table></figure></p></li><li><p>域名解析,如果想要类似于<code>example.com</code>和<code>studio.example.com</code>来分别指向lms和studio,在控制台设置好解析后,在服务器端修改<code>/etc/nginx/site-enabled/cms</code>, <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"># listen 18010;</div><div class="line">listen 80;</div><div class="line">server_name studio.example.cn;</div></pre></td></tr></table></figure></p></li><li><p>创建快照,最好创建一组实例快照,防止在后续的配置过程中出现不知道如何处理的问题,目前快照服务在国外节点暂不收费</p><h3 id="配置">配置</h3><p>大部分情况下所需要修改的配置主要是四个json文件,所在的位置为<code>/edx/app/edxapp</code>,可以发现lms和cms的很多内容还是重复的,这样修改比较繁琐,一个比较好的方法是通过在<code>/edx/app/edx_ansible</code>目录下创建<code>server-vars.yml</code>文件配置变量,可以参考<a href="https://github.com/edx/configuration/blob/master/playbooks/sample_vars/server_vars.yml" target="_blank" rel="external">官方的一个例子</a>或者<a href="https://github.com/tkeemon/openedx-server-vars/blob/master/server-vars.yml" target="_blank" rel="external">这个</a>, 然后通过以下来更新,这样会覆盖点原来的json文件 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/edx/bin/update edx_platform $(cd /edx/app/edxapp/edx-platform; git rev-parse HEAD)</div></pre></td></tr></table></figure></p><p>但需要注意的是在执行update之前,先要执行<code>sudo /edx/bin/supervisorctl stop all</code>,停掉lms,cms的服务</p><h3 id="其他">其他</h3>平台会在根目录下创建一个/edx,主要有四个部分</li><li>/edx/app 所有的应用模块所在的位置</li><li>/edx/bin pip,ansible,一些管理命令所在的位置</li><li>/edx/etc 配置文件的位置</li><li><p>/edx/var 数据文件,log查看</p><hr><p>欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2018/08/28/open-edx-platform-Ubuntu-16-04-native-install/</p></li></待插入图片></li>]]></content>
<summary type="html">
<p>最近在折腾edx平台,这个平台比较复杂,加上自己个人技术能力有限,瞎捣鼓了很长一段时间,现记录下过程中的一些使用及问题,方便以后查询。
</summary>
<category term="edx" scheme="http://cequn.wang/categories/edx/"/>
<category term="open edx" scheme="http://cequn.wang/tags/open-edx/"/>
<category term="云服务" scheme="http://cequn.wang/tags/%E4%BA%91%E6%9C%8D%E5%8A%A1/"/>
</entry>
<entry>
<title>腾讯云: jupyter notebook和jupyterhub</title>
<link href="http://cequn.wang/2018/03/10/%E8%85%BE%E8%AE%AF%E4%BA%91-jupyter-notebook%E5%92%8Cjupyterhub/"/>
<id>http://cequn.wang/2018/03/10/腾讯云-jupyter-notebook和jupyterhub/</id>
<published>2018-03-10T06:18:00.000Z</published>
<updated>2018-08-28T06:44:25.498Z</updated>
<content type="html"><![CDATA[<p>腾讯云有个优惠活动,主机是1核2G+1Mbps+50G云盘,价格是很优惠,120元/16个月,价格相较于阿里云还是便宜很多.果断的入手了.最近因为一直在使用Python,所以想搭建一个jupyter notebook服务器版本,之前使用阿里云时候尝试了很多次没成功,也是因为自己可能对服务器操作的很多方面不是很熟悉,配置方法很多也是网上看的教程.但这次在腾讯云上的实践却是很顺利.一开始安装了个jupyter notebook准备个人使用足够.后来因为一个同事最近也在学习,所以就想安装个多用户版本的(jupyterhub).接下来开始吧: <a id="more"></a></p><h4 id="jupyter-notebook">Jupyter notebook</h4><h5 id="远程登录">远程登录</h5><p>选用的是腾讯云系统为ubuntu 16.04版本,默认的登录账户为ubuntu,首次登录的密码是随机分配的,你可以在自己的控制台进行修改,然后记下ip地址,本地打开终端 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh ubuntu@your_server_ip</div></pre></td></tr></table></figure></p><h5 id="准备工作">准备工作</h5><p>系统默认已经装有python2.7和python3.5版本,所以接下来我们安装以下python的包管理工具pip. <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">#使用的腾讯的镜像,速度还是很快的</div><div class="line">sudo apt-get install python3-pip</div></pre></td></tr></table></figure></p><p>后续使用 pip 安装第三方库时,由于网络限制,速度会比较慢(我在安装jupyter时发现速度不到10k)。将 PyPI 的源修改为国内源,这里使用的是中国科学技术大学提供的源(国内的还有豆瓣,阿里的源,可自己百度看看)。 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">mkdir ~/.pip</div><div class="line">nano ~/.pip/pip.conf</div><div class="line">#添加下面内容并保存</div><div class="line">[global]</div><div class="line">index-url = https://mirrors.ustc.edu.cn/pypi/web/simple</div><div class="line">format = columns</div></pre></td></tr></table></figure></p><p>接下来可根据自己习惯,配置一个virtualenv,我嫌麻烦并没有安装.然后安装jupyter <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"># U是指upgrade</div><div class="line">sudo pip3 install -U jupyter</div></pre></td></tr></table></figure></p><h5 id="创建登录密码">创建登录密码</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"># 第一行会让你输入密码,并且生成密码的sha1值,后续会使用</div><div class="line">PASSWD=$(python3 -c 'from notebook.auth import passwd; print(passwd())')</div><div class="line">echo "c.NotebookApp.password = u'${PASSWD}'"</div></pre></td></tr></table></figure><h5 id="配置jupyter">配置jupyter</h5><p>运行<code>jupyter --generate-config</code>会生成一个<code>.jupyter</code>目录,编辑其下面的<code>jupyter_config.py</code>文件,末尾添加: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">c.NotebookApp.ip = '*'</div><div class="line">c.NotebookApp.open_browser = False</div><div class="line">c.NotebookApp.port = 8881</div><div class="line">c.NotebookApp.password = u'sha1:${PASSWD}' # 上面创建密码的sha1值</div></pre></td></tr></table></figure></p><p>此时执行<code>jupyter notebook</code>我们就可以在浏览器通过ip地址来访问了 ##### Jupyter系统服务 创建<code>/lib/systemd/system/jupyter.service</code>文件,添加下面的内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[Unit]</div><div class="line">Description=Jupyter Notebook</div><div class="line">[Service]</div><div class="line">Type=simple</div><div class="line">PIDFile=/run/jupyter.pid</div><div class="line">ExecStart=/usr/local/bin/jupyter notebook</div><div class="line">User=ubuntu</div><div class="line">Group=ubuntu</div><div class="line">WorkingDirectory=/home/ubuntu/notebooks</div><div class="line">Restart=always</div><div class="line">RestartSec=10</div><div class="line">[Install]</div><div class="line">WantedBy=multi-user.target</div></pre></td></tr></table></figure></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo systemctl enable jupyter.service</div><div class="line">sudo systemctl daemon-reload</div><div class="line">sudo systemctl start jupyter.service</div></pre></td></tr></table></figure><h5 id="nginx配置">Nginx配置</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install nginx</div><div class="line">sudo nano /etc/nginx/sites-available/default</div></pre></td></tr></table></figure><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">server {</div><div class="line"> listen 80 default_server;</div><div class="line"> listen [::]:80 default_server ipv6only=on;</div><div class="line"> location / {</div><div class="line"> proxy_pass http://localhost:8881;</div><div class="line"> proxy_http_version 1.1;</div><div class="line"> proxy_set_header Upgrade $http_upgrade;</div><div class="line"> proxy_set_header Connection "upgrade";</div><div class="line"> proxy_set_header Origin "";</div><div class="line">}</div><div class="line">}</div></pre></td></tr></table></figure><p>重启nginx服务: <code>sudo service nginx restart</code> #### Jupyterhub 可参考官网的文档: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install npm nodejs-legacy</div><div class="line">sudo npm install -g configurable-http-proxy</div><div class="line">sudo pip3 install jupyterhub</div></pre></td></tr></table></figure></p><p>此时,可以运行<code>jupyterhub</code>,通过<code>your_server_ip:8000</code>来访问. ##### Jupyterhub 配置 我新建了目录<code>jupyterhub</code>,并运行通过<code>jupyterhub --generate-config</code>生成配置文件,配置文件添加内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">#c.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator'</div><div class="line">#c.GitHubOAuthenticator.oauth_callback_url = 'https://your_server_ip/hub/oauth_callback'</div><div class="line">#c.GitHubOAuthenticator.client_id = 'Some cryptic string'</div><div class="line">#c.GitHubOAuthenticator.client_secret = 'Some cryptic string'</div><div class="line">#上面几行是使用github授权的登录,但是试了没成功,所以没有使用</div><div class="line"></div><div class="line">c.LocalAuthenticator.create_system_users = True</div><div class="line">c.Authenticator.whitelist = {'ubuntu', 'jupyter1', 'jupyter2'}</div><div class="line">c.Authenticator.admin_users = {'ubuntu'}</div><div class="line">c.Spawner.notebook_dir = '~/notebooks'</div><div class="line">c.JupyterHub.ssl_cert = 'mycert.pem'</div><div class="line">c.JupyterHub.ssl_key = 'mykey.key'</div><div class="line">c.JupyterHub.proxy_cmd = ['/usr/local/bin/configurable-http-proxy']</div></pre></td></tr></table></figure></p><p>添加用户(文件夹权限很重要): <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo adduser jupyter1</div><div class="line">sudo mkdir /home/jupyter1/notebooks</div><div class="line">sudo chmod 775 /home/jupyter1/notebooks</div></pre></td></tr></table></figure></p><p>另外创建个文件<code>userlist</code>,添加内容(看官网教程需要这个,并没发现到如何作用,貌似是跟github授权登录挂钩的): <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ubuntu admin</div><div class="line">jupyter1</div><div class="line">jupyter2</div></pre></td></tr></table></figure></p><p>生成密钥(在chrome里面使用时,仍然提示no secure): <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem</div></pre></td></tr></table></figure></p><h5 id="jupyterhub.service">Jupyterhub.service</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[Unit]</div><div class="line">Description=Jupyterhub</div><div class="line"></div><div class="line">[Service]</div><div class="line">User=root</div><div class="line">Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/anaconda3/bin"</div><div class="line">ExecStart=/usr/local/bin/jupyterhub -f /home/ubuntu/jupyterhub/jupyterhub_config.py</div><div class="line"></div><div class="line">[Install]</div><div class="line">WantedBy=multi-user.target</div></pre></td></tr></table></figure><hr><p>欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2018/03/10/腾讯云-jupyter-notebook和jupyterhub/</p>]]></content>
<summary type="html">
<p>腾讯云有个优惠活动,主机是1核2G+1Mbps+50G云盘,价格是很优惠,120元/16个月,价格相较于阿里云还是便宜很多.果断的入手了.最近因为一直在使用Python,所以想搭建一个jupyter notebook服务器版本,之前使用阿里云时候尝试了很多次没成功,也是因为自己可能对服务器操作的很多方面不是很熟悉,配置方法很多也是网上看的教程.但这次在腾讯云上的实践却是很顺利.一开始安装了个jupyter notebook准备个人使用足够.后来因为一个同事最近也在学习,所以就想安装个多用户版本的(jupyterhub).接下来开始吧:
</summary>
<category term="jupyter" scheme="http://cequn.wang/tags/jupyter/"/>
<category term="python" scheme="http://cequn.wang/tags/python/"/>
</entry>
<entry>
<title>树莓派3上运行Homebridge</title>
<link href="http://cequn.wang/2017/10/10/%E6%A0%91%E8%8E%93%E6%B4%BE3%E4%B8%8A%E8%BF%90%E8%A1%8CHomebridge/"/>
<id>http://cequn.wang/2017/10/10/树莓派3上运行Homebridge/</id>
<published>2017-10-10T06:09:00.000Z</published>
<updated>2018-08-28T06:44:25.498Z</updated>
<content type="html"><![CDATA[<p>Youtube上看到一个很酷的视频<a href="https://www.youtube.com/watch?v=I-8QzW_thhY" target="_blank" rel="external">MK smart house</a>(想看请学会翻墙)。自己搜索了下,最开始发现了google assistant sdk for python,于是乎就想利用手上树莓派3来试试,根据<a href="https://developers.google.com/assistant/sdk/develop/python/hardware/setup" target="_blank" rel="external">官方文档</a>一步步来设置了,运行<code>google-assistant-demo</code>,提问了一些时间天气,都完全没问题。但使用该项服务,也比较麻烦,第一,大陆地区被墙,我开始时运行卡住了,咋回事呀,瞎忙活好久才想起来没有vpn;第二,这个现在不支持中文;第三,每次对话开始使用<code>Ok/Hey google</code>,感觉很二,网上文档较少,也不知道咋改。自己也根据一些例子写了简单的程序来控制卧室的床头灯,效果还不错,关键对我这蹩脚的英文口音识别还挺高。</p><p>后来想着自己的IPhone上有siri,而且支持中文,这样不是更方便些。于是网上搜索,发现大神真是多,有个家伙叫KhaosT是个在美留学的中国人,曾在苹果的HomeKit团队实习过,他写了个Homebridge,是用 NodeJS模拟了一个HomeKit Accessory Server,这样不用局限于那些比较昂贵的Accessory了。而且目前有500个之多的相应Plugin,下面是按照<a href="https://github.com/nfarina/homebridge" target="_blank" rel="external">github上教程</a>来安装的,过程中遇到了些问题,也找到了解决办法。 <a id="more"></a></p><h4 id="安装tightvnc">安装TightVNC</h4><p>我的rpi3安装了最新的strech镜像,开机后,设置了无线,以及配置了<code>raspi-config</code>,这里我直接使用了ssh访问,当然如果习惯了图形界面,可以按照下面的这些步骤来安装个VNC: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install tightvncserver</div><div class="line">tightvncserver -geometry 1600x900 :1 #设置密码</div><div class="line">sudo nano /etc/systemd/system/vncserver@:1.service #添加</div></pre></td></tr></table></figure></p><p>粘帖一下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[Unit]</div><div class="line">Description=Remote desktop service (VNC)</div><div class="line">After=syslog.target network.target</div><div class="line"></div><div class="line">[Service]</div><div class="line">Type=forking</div><div class="line">User=pi</div><div class="line">#PAMName=login</div><div class="line">#PIDFile=/home/pi/.vnc/%H%i.pid</div><div class="line">#ExecStartPre=/usr/bin/vncserver -kill %i</div><div class="line">ExecStart=/usr/bin/vncserver -geometry 1600x900 %i</div><div class="line">ExecStop=/usr/bin/vncserver -kill %i</div><div class="line"></div><div class="line">[Install]</div><div class="line">WantedBy=multi-user.target</div></pre></td></tr></table></figure></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">sudo chmod +x /etc/systemd/system/vncserver@:1.service </div><div class="line">sudo systemctl daemon-reload</div><div class="line">sudo systemctl enable vncserver@:1</div><div class="line">sudo systemctl start vncserver@:1</div></pre></td></tr></table></figure><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install autocutsel #可以共享剪切板</div><div class="line">autocutsel -fork # add to .vnc/xstartup</div></pre></td></tr></table></figure><p>在客户端机器上,可以使用chrome的插件vncviewer来访问。</p><h4 id="安装homebridge">安装homebridge</h4><h5 id="更新">更新</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo apt-get update</div><div class="line">sudo apt-get upgrade</div></pre></td></tr></table></figure><h5 id="安装nodejs">安装nodejs</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - #目前版本为8.6</div><div class="line">sudo apt-get install -y nodejs</div></pre></td></tr></table></figure><h5 id="安装avahi和homebridge">安装avahi和homebridge</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install libavahi-compat-libdnssd-dev</div><div class="line">sudo npm install -g --unsafe-perm homebridge</div></pre></td></tr></table></figure><p>安装完后,如果当你运行homebridge,出现以下报错: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">module.js:472</div><div class="line"> throw err;</div><div class="line"> ^</div><div class="line">Error: Cannot find module '../build/Release/dns_sd_bindings'</div></pre></td></tr></table></figure></p><p>解决方法: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo npm install --unsafe-perm mdns</div><div class="line">cd /usr/lib/node_modules/homebridge</div><div class="line">sudo npm rebuild --unsafe-perm</div></pre></td></tr></table></figure></p><h5 id="配置config.json">配置config.json</h5><p>在home目录下的./homebridge目录下新建config.json:(特别注意格式,否则无法读取) <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line"> "bridge": {</div><div class="line"> "name": "CQHome", //可选修改</div><div class="line"> "username": "B8:27:EB:A0:2C:A1", //修改,为pi的mac地址</div><div class="line"> "port": 45536, //可选修改</div><div class="line"> "pin": "031-45-188" //可选修改</div><div class="line"> },</div><div class="line"> "platforms": [</div><div class="line"> { </div><div class="line"> }]</div><div class="line"> "accessories”:[{</div><div class="line"> }]</div><div class="line">}</div></pre></td></tr></table></figure></p><p>其中的<code>platforms</code>和<code>accessories</code>,可在安装homebridge-plugins后来进行修改添加配置</p><h4 id="安装摄像头">安装摄像头</h4><p>由于目前手头只有个camera v2.1, 于是先拿这个来试试效果,当然video streaming这块也不懂,似乎也复杂。找了一个<code>homebridge-camera-rpi</code>,测试发现视频传输很流畅,一开始一直延迟较高,后来发现因为vpn打开的原因,好了,具体的安装及配置<a href="https://github.com/moritzmhmk/homebridge-camera-rpi" target="_blank" rel="external">参考这里</a>。</p><p>在rpi3上运行homebridge,然后iphone手机打开home app,添加时候需要输入8位code,此处即为配置文件中的pin码。</p><h4 id="控制台灯-温湿度">控制台灯, 温湿度</h4><p>在某宝上购买了些电子原件,什么继电器,温湿度传感器等,东西都比较便宜,继电器貌似才3块多点,这里要注意其支持5v,因为Pi的输出只有3.3v和5v两种。继电器上的接口,一端为NC/COM/NO,按如下图连接: <img src="relay-light.jpg" alt="灯与继电器连接电路图"> 另一端有DC+/IN/DC-,DC+/DC-连接5V电源,IN连接Digital PIN,下图为Pi的GPIO分布图: <img src="rp2_pinout.jpg" alt="Rpi-GPIO"> 温湿度传感器选用了AM2302,最好选用下图这种已经接好电容电阻: <img src="dht22.jpg" alt="AM2302温适度传感器"> 连接至两个设备的GPIO号最好记下来,我使用的是GPIO4(温湿度)和GPIO27(继电器)。</p><h5 id="温湿度传感器">温湿度传感器</h5><p>安装Plugin,这里使用的是<code>homebridge-dht</code>和<code>homebridge-gpio-wpi2</code>, <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">sudo npm install -g homebridge-dht</div><div class="line">sudo npm install -g --unsafe-perm homebridge-gpio-wpi2</div></pre></td></tr></table></figure></p><p>对于<code>homebridge-dht</code>设置读取传感器数据的步骤太复杂,这里我做了些修改,使用python来实现。 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">git clone https://github.com/adafruit/Adafruit_Python_DHT.git </div><div class="line">cd Adafruit_Python_DHT</div><div class="line">sudo python setup.py install</div></pre></td></tr></table></figure></p><p>接下来编写程序读取数据,这里为<code>/home/pi/pydht22.py</code>: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">import Adafruit_DHT as dht</div><div class="line">import sys</div><div class="line">pin = int(sys.argv[1])</div><div class="line">sensor = dht.DHT22</div><div class="line">humidity, temperature = dht.read_retry(sensor, pin)</div><div class="line">if humidity is not None and temperature is not None:</div><div class="line">print '{0:d} {1:0.1f} c {2:0.1f} %'.format(0,temperature, humidity)</div><div class="line">else:</div><div class="line">print '{0:d} {1:d} c {2:d} %'.format(3,0,0) #格式是为了保持与Plugin一致</div></pre></td></tr></table></figure></p><p>修改plugin程序: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">cd /usr/lib/node-modules/homebridge-dht/</div><div class="line">nano index.js</div><div class="line">#找到以下位置并修改:</div><div class="line">....</div><div class="line">dhtExec = config.dhtExec || "dht22"; #将dht22改为python,当然其实也可以在配置文件中指定</div><div class="line">...</div><div class="line">exec(dhtExec, ['-g', this.gpio], function(error, responseBody, stderr) { #修改['-g', this.gpio],去掉’-g‘,改为你的dht22.py文件的绝对路径,这里是/home/pi/pydht22.py</div></pre></td></tr></table></figure></p><p>保存退出,接下来可以修改<code>~/.homebridge/config.json</code>文件,在<code>accessories</code>里添加: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">{ "accessory": "Dht",</div><div class="line"> "name": "dht22",</div><div class="line"> "name_temperature": "Temperature",</div><div class="line"> "name_humidity": "Humdity",</div><div class="line"> "service": "dht22",</div><div class="line"> "gpio": "4" }</div></pre></td></tr></table></figure></p><p>运行homebridge程序,然后在IPhone的Home程序里添加即可。</p><h5 id="继电器控制">继电器控制</h5><p>按照<code>homebridge-gpio-wpi2</code>的<a href="https://github.com/rsg98/homebridge-gpio-wpi2" target="_blank" rel="external">github上说明操作</a>了,结果出现以下错误: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">Unable to determine hardware version. I see: Hardware : BCM2835 </div><div class="line">- expecting BCM2708 or BCM2709. Please report this to [email protected]</div></pre></td></tr></table></figure></p><p>估计是版本太低,于是手动安装了最新版: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">sudo apt-get purge wiringpi</div><div class="line">git clone git://git.drogon.net/wiringPi</div><div class="line">cd ~/wiringPi</div><div class="line">./build</div><div class="line">pigo -v #这时候是2.4.4版本</div></pre></td></tr></table></figure></p><p>可以正常使用。</p><h5 id="展示">展示</h5><img src="/2017/10/10/树莓派3上运行Homebridge/homekit.jpg" alt="Home程序截图" title="Home程序截图"><p>Siri语音测试: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">Me:打开卧室灯</div><div class="line">Siri:好,灯已打开</div><div class="line">Me:卧室灯状态</div><div class="line">Siri: 你的灯当前已打开</div><div class="line">Me:卧室温度</div><div class="line">Siri:你的“CQHome”家中卧室温度是29℃</div><div class="line">Me:卧室湿度</div><div class="line">Siri:湿度的这项数据现在是70%</div><div class="line">....</div></pre></td></tr></table></figure> ___ 欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2017/10/10/树莓派3上运行Homebridge/</p>]]></content>
<summary type="html">
<p>Youtube上看到一个很酷的视频<a href="https://www.youtube.com/watch?v=I-8QzW_thhY" target="_blank" rel="external">MK smart house</a>(想看请学会翻墙)。自己搜索了下,最开始发现了google assistant sdk for python,于是乎就想利用手上树莓派3来试试,根据<a href="https://developers.google.com/assistant/sdk/develop/python/hardware/setup" target="_blank" rel="external">官方文档</a>一步步来设置了,运行<code>google-assistant-demo</code>,提问了一些时间天气,都完全没问题。但使用该项服务,也比较麻烦,第一,大陆地区被墙,我开始时运行卡住了,咋回事呀,瞎忙活好久才想起来没有vpn;第二,这个现在不支持中文;第三,每次对话开始使用<code>Ok/Hey google</code>,感觉很二,网上文档较少,也不知道咋改。自己也根据一些例子写了简单的程序来控制卧室的床头灯,效果还不错,关键对我这蹩脚的英文口音识别还挺高。</p>
<p>后来想着自己的IPhone上有siri,而且支持中文,这样不是更方便些。于是网上搜索,发现大神真是多,有个家伙叫KhaosT是个在美留学的中国人,曾在苹果的HomeKit团队实习过,他写了个Homebridge,是用 NodeJS模拟了一个HomeKit Accessory Server,这样不用局限于那些比较昂贵的Accessory了。而且目前有500个之多的相应Plugin,下面是按照<a href="https://github.com/nfarina/homebridge" target="_blank" rel="external">github上教程</a>来安装的,过程中遇到了些问题,也找到了解决办法。
</summary>
<category term="SmartHome" scheme="http://cequn.wang/categories/SmartHome/"/>
<category term="rpi3" scheme="http://cequn.wang/tags/rpi3/"/>
<category term="homebridge" scheme="http://cequn.wang/tags/homebridge/"/>
</entry>
<entry>
<title>配置Sublime为Matlab的编辑器</title>
<link href="http://cequn.wang/2017/09/19/%E9%85%8D%E7%BD%AEsublime%E4%B8%BAMatlab%E7%9A%84%E7%BC%96%E8%BE%91%E5%99%A8/"/>
<id>http://cequn.wang/2017/09/19/配置sublime为Matlab的编辑器/</id>
<published>2017-09-19T01:27:00.000Z</published>
<updated>2018-08-28T06:44:25.498Z</updated>
<content type="html"><![CDATA[<p>最近自己的Matlab的图形界面出现一些问题,一时间也没找到解决方法,于是就试图采用Sublime Text编辑器+Matlab命令行的环境来运行自己的程序。</p><li>Matlab R2015a(Liunx平台,Ubuntu 16.04)</li><li><a href="https://www.sublimetext.com/3" target="_blank" rel="external">Sublime 3</a></li><a id="more"></a><h4 id="新建build-system">新建Build System</h4><p>在Sublime中选择<code>Tools -> Build System -> New Build System</code>,系统会创建一个JSON文件,输入以下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line"> "cmd": ["gnome-terminal -x bash -c \"matlab -nosplash -nodesktop -r ${file_base_name}; exec bash\""],</div><div class="line"> "selector":"source.m",</div><div class="line"> "shell":"true",</div><div class="line"> "working_dir": "$file_path"</div><div class="line">}</div></pre></td></tr></table></figure></p><p>命名并保存这个JSON文件到默认目录(将会出现在<code>Build System</code>菜单中)。</p><h4 id="启动matlab进行编译">启动Matlab进行编译</h4><p>在<code>Build System</code>中选择你所设置的<code>Matlab</code>编译名称。此时随便编辑一个.m文件,可以点击<code>Tools -> Build</code>或者使用快捷键<code>Ctrl+B</code>,这时Sublime就会打开终端并编译当前文件。 但每次<code>Build</code>都会产生一个新的命令行界面,每次都重新启动了一次MATLAB,很耗费时间。所以在Sublime修改程序保存后,通过已开启的控制台窗口输入脚本名来运行。 ___ 欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2017/09/19/配置sublime为Matlab的编辑器/</p>]]></content>
<summary type="html">
<p>最近自己的Matlab的图形界面出现一些问题,一时间也没找到解决方法,于是就试图采用Sublime Text编辑器+Matlab命令行的环境来运行自己的程序。</p>
<li>
Matlab R2015a(Liunx平台,Ubuntu 16.04)
</li>
<li>
<a href="https://www.sublimetext.com/3" target="_blank" rel="external">Sublime 3</a>
</li>
</summary>
<category term="others" scheme="http://cequn.wang/categories/others/"/>
<category term="Sublime" scheme="http://cequn.wang/tags/Sublime/"/>
<category term="Matlab" scheme="http://cequn.wang/tags/Matlab/"/>
</entry>
<entry>
<title>Landscape主题的修改优化</title>
<link href="http://cequn.wang/2017/09/16/Landscape%E4%B8%BB%E9%A2%98%E7%9A%84%E4%BF%AE%E6%94%B9%E4%BC%98%E5%8C%96/"/>
<id>http://cequn.wang/2017/09/16/Landscape主题的修改优化/</id>
<published>2017-09-15T21:01:00.000Z</published>
<updated>2018-08-28T06:44:25.498Z</updated>
<content type="html"><![CDATA[<p>继部署完Hexo博客平台后,进一步对默认的主题Landscape做一些修改优化。当然笔者对CSS,JQuery等等这些都不是很熟悉,所以大部分主题的定制都是通过google搜索,然后稍微修改来满足自己的需求。在网上查找的时候,发现<code>Hexo-landscape-f</code>这个主题优化的挺不错,基本上都符合笔者想要的结果。当然还基于此增加了文章打赏功能(估计也没人愿意这样做),以及使用<code>hexo-tag-cloud</code>,貌似看着较酷点的动态tag。在主题修改过程中还是花费了比较多时间,也收获不少,对Hexo的主题结构形式有了更深入点的了解。</p><a id="more"></a><h4 id="主题安装启用">主题安装、启用</h4><p>Hexo的主题放在根目录的<code>themes</code>下,主要将相应的主题文件夹放在这个目录下,并在根目录的<code>_config.yml</code>文件配置相应的名称即可。</p><h4 id="优化总结">优化总结</h4><h5 id="添加rss和sitemap">添加RSS和sitemap</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">npm install hexo-generator-feed --save</div><div class="line">npm install hexo-generator-sitemap --save</div></pre></td></tr></table></figure><p>根目录下的<code>_config.yml</code>文件添加: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">Plugins:</div><div class="line"> hexo-generator-feed</div><div class="line"> hexo-generator-sitemap</div><div class="line"></div><div class="line">#Feed Atom</div><div class="line">feed:</div><div class="line"> type: atom</div><div class="line"> path: atom.xml</div><div class="line"> limit: 20</div><div class="line"></div><div class="line">#sitemap</div><div class="line">sitemap:</div><div class="line"> path: sitemap.xml</div></pre></td></tr></table></figure></p><h5 id="返回顶部按钮">返回顶部按钮</h5><h5 id="添加disqus评论">添加Disqus评论</h5><p>Landscape里默认的使用Disqus评论,网上有类似的多说,但已经关闭了。首先在<a href="https://disqus.com/" target="_blank" rel="external">Disuqs</a>网站注册个帐号,进行相应配置,记住你的shortname,然后在根目录下的<code>_config.yml</code>文件添加: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">disqus_shortname: your_shortname</div></pre></td></tr></table></figure></p><h5 id="修改分享工具增加微信和微博">修改分享工具增加微信和微博</h5><p>原分享链接支持的是twitter,facebook等,在<code>landscape\source\js\script.js</code>中,其中<code><div class="article-share-links"></code>下面的四个链接就是这些社交网站的分享链接,这里只修改掉了两项: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">'<a href="http://service.weibo.com/share/share.php?&title=好东西就要一起分享&language=zh_cn&url=' + encodedUrl + '" class="article-share-sina" target="_blank" title="微博"></a>',</div><div class="line">'<a href="http://qr.liantu.com/api.php?text=' + encodedUrl + '" class="article-share-wechat" target="_blank" title="微信"></a>',</div></pre></td></tr></table></figure></p><p>当然还需要替换相应的图标。下载最新版 Font Awesome,替换掉 <code>source\css\fonts</code>中相关文件,并在<code>source\css\_variables.styl</code>中的<code>font-icon-version</code>这行修改为最新的Font Awesome版本号。(发现Font Awesome真的是个很酷的东西)</p><p>然后,在 <code>source\css\_partial\article.styl</code> 中,找到四段以 <code>.article-share-***</code>开头的代码,添加如下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">.article-share-sina</div><div class="line"> @extend $article-share-link</div><div class="line"> &:before</div><div class="line"> content: "\f18a"</div><div class="line"> &:hover</div><div class="line"> background: color-sina</div><div class="line"> text-shadow: 0 1px darken(color-sina, 20%)</div><div class="line">.article-share-wechat</div><div class="line"> @extend $article-share-link</div><div class="line"> &:before</div><div class="line"> content: "\f1d7"</div><div class="line"> &:hover</div><div class="line"> background: color-wechat</div><div class="line"> text-shadow: 0 1px darken(color-wechat, 20%)</div></pre></td></tr></table></figure></p><h5 id="侧边栏和文章中显示文章目录">侧边栏和文章中显示文章目录</h5><h5 id="动态tag-cloud">动态tag cloud</h5><p>这里安装了 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-tag-cloud --save</div></pre></td></tr></table></figure></p><p>另外需要在<code>layout/_widget/tagcloud.ejs</code>文件中替换成以下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><% if (site.tags.length) { %></div><div class="line"> <script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script></div><div class="line"> <script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script></div><div class="line"> <div class="widget-wrap"></div><div class="line"> <h3 class="widget-title"><%= __('tagcloud') %></h3></div><div class="line"> <div id="myCanvasContainer" class="widget tagcloud"></div><div class="line"> <canvas width="250" height="250" id="resCanvas" style="width=100%"></div><div class="line"> <%- tagcloud() %></div><div class="line"> </canvas></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"><% } %></div></pre></td></tr></table></figure></p><h5 id="日历">日历</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install --save git://github.com/howiefh/hexo-generator-calendar.git</div></pre></td></tr></table></figure><p>未完 ##### 添加打赏 首先我们得获取自己的微信和支付宝的收款二维码,然后进行写简单的ps,保存在主题目录下<code>source/imgs/</code>下,之后对主题目录下的<code>_config.yml</code>文件中添加: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">donate: </div><div class="line"> donate: true</div><div class="line"> donate_text: 欣赏此文?求鼓励,求支持!</div><div class="line"> alipay: /imgs/alipay.png</div><div class="line"> wechat: /imgs/wechat.png</div></pre></td></tr></table></figure></p><p>在<code>layout/_partial</code>下新建donate.ejs输入如下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line"><div class ="post-donate"></div><div class="line"> <div id="donate_board" class="donate_bar center"></div><div class="line"> <br></div><div class="line"> ------------------------------------------------------------------------------------------------------------------------------</div><div class="line"> <br></div><div class="line"> <a id="btn_donate" class="btn_donate" href="javascript:;" title="打赏"></a></div><div class="line"> <span class="donate_txt"></div><div class="line"> ↑<br></div><div class="line"> <%=theme.donate.donate_text%></div><div class="line"> </span></div><div class="line"> <br></div><div class="line"> </div> </div><div class="line"></div><div class="line"> <div id="donate_guide" class="donate_bar center hidden" ></div><div class="line"> <br></div><div class="line"> ------------------------------------------------------------------------------------------------------------------------------</div><div class="line"> <br></div><div class="line"> <a class="fancybox" rel="group" href="<%= theme.donate.wechat %>"><img src="<%= theme.donate.wechat %>" alt="微信打赏" height="190px" /></a></div><div class="line"> &nbsp;&nbsp;</div><div class="line"> <a class="fancybox" rel="group" href="<%= theme.donate.alipay %>"><img src="<%= theme.donate.alipay %>" alt="支付宝打赏" height="190px"/></a></div><div class="line"> </div></div><div class="line"> <script type="text/javascript"></div><div class="line"> document.getElementById('btn_donate').onclick = function() {</div><div class="line"> $('#donate_board').addClass('hidden');</div><div class="line"> $('#donate_guide').removeClass('hidden');</div><div class="line"> }</div><div class="line"></div><div class="line"> function donate_on_web(){</div><div class="line"> $('#donate').submit();</div><div class="line"> }</div><div class="line"></div><div class="line"> var original_window_onload = window.onload;</div><div class="line"> window.onload = function () {</div><div class="line"> if (original_window_onload) {</div><div class="line"> original_window_onload();</div><div class="line"> }</div><div class="line"> document.getElementById('donate_board_wdg').className = 'hidden';</div><div class="line"> }</div><div class="line"> </script></div><div class="line"></div></div></pre></td></tr></table></figure></p><p>在<code>source/css/_partial</code>下新建donate.styl输入如下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"> .center {</div><div class="line"> text-align: center;</div><div class="line"> }</div><div class="line"> .hidden {</div><div class="line"> display: none;</div><div class="line"> }</div><div class="line">.donate_bar a.btn_donate{</div><div class="line"> display: inline-block;</div><div class="line"> width: 82px;</div><div class="line"> height: 82px;</div><div class="line"> background: url("http://7xsl28.com1.z0.glb.clouddn.com/btn_reward.gif") no-repeat;</div><div class="line"> _background: url("http://7xsl28.com1.z0.glb.clouddn.com/btn_reward.gif") no-repeat;</div><div class="line"> -webkit-transition: background 0s;</div><div class="line"> -moz-transition: background 0s;</div><div class="line"> -o-transition: background 0s;</div><div class="line"> -ms-transition: background 0s;</div><div class="line"> transition: background 0s;</div><div class="line">}</div><div class="line">.donate_bar a.btn_donate:hover{ background-position: 0px -82px;}</div><div class="line">.donate_bar .donate_txt {</div><div class="line"> display: block;</div><div class="line"> color: #9d9d9d;</div><div class="line"> font: 14px/2 "Microsoft Yahei";</div><div class="line">}</div><div class="line">.bold{ font-weight: bold; }</div></pre></td></tr></table></figure></p><p>将打赏代码整合至文章中,在<code>layout/_partial/article.ejs</code>中的<code><article> </article></code>标签内添加如下内容: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><% if (!index && theme.donate){ %></div><div class="line"> <%- partial('donate') %></div><div class="line"><% } %></div></pre></td></tr></table></figure></p><h5 id="mathjax插件">Mathjax插件</h5><p><code>npm install hexo-renderer-mathjax --save</code> <br>看看效果,来个简单的公式: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">简单:$a = b + c$</div></pre></td></tr></table></figure></p><p>效果: <br><span class="math inline">\(a = b + c\)</span> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">复杂点:$$\frac{\partial u}{\partial t}</div><div class="line">= h^2 \left( \frac{\partial^2 u}{\partial x^2} +</div><div class="line">\frac{\partial^2 u}{\partial y^2} +</div><div class="line">\frac{\partial^2 u}{\partial z^2}\right)$$</div></pre></td></tr></table></figure></p><p>效果:<span class="math display">\[\frac{\partial u}{\partial t}= h^2 \left( \frac{\partial^2 u}{\partial x^2} +\frac{\partial^2 u}{\partial y^2} +\frac{\partial^2 u}{\partial z^2}\right)\]</span></p><p>但会存在原markdown渲染引擎和mathjax冲突问题,这里建议替换掉: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">sudo apt-get install pandoc</div><div class="line">npm uninstall hexo-renderer-marked --save</div><div class="line">npm install hexo-renderer-pandoc --save</div></pre></td></tr></table></figure> ___ 欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2017/09/16/Landscape主题的修改优化/</p>]]></content>
<summary type="html">
<p>继部署完Hexo博客平台后,进一步对默认的主题Landscape做一些修改优化。当然笔者对CSS,JQuery等等这些都不是很熟悉,所以大部分主题的定制都是通过google搜索,然后稍微修改来满足自己的需求。在网上查找的时候,发现<code>Hexo-landscape-f</code>这个主题优化的挺不错,基本上都符合笔者想要的结果。当然还基于此增加了文章打赏功能(估计也没人愿意这样做),以及使用<code>hexo-tag-cloud</code>,貌似看着较酷点的动态tag。在主题修改过程中还是花费了比较多时间,也收获不少,对Hexo的主题结构形式有了更深入点的了解。</p>
</summary>
<category term="Hexo_blog" scheme="http://cequn.wang/categories/Hexo-blog/"/>
<category term="hexo" scheme="http://cequn.wang/tags/hexo/"/>
</entry>
<entry>
<title>Hexo建站</title>
<link href="http://cequn.wang/2017/09/15/First-post/"/>
<id>http://cequn.wang/2017/09/15/First-post/</id>
<published>2017-09-15T14:46:00.000Z</published>
<updated>2018-08-28T06:44:25.498Z</updated>
<content type="html"><![CDATA[<h4 id="写在前面的话">写在前面的话</h4><p>心血来潮,想搭建个人博客用于记录平时工作学习中包括健身等遇到的问题以及解决方法,这样不至于在下次碰到时还会花大量时间去找解决途径,同时也可以给身边的朋友一个参考。</p><p>开源的博客平台多如牛毛,而且不乏优秀之作,如 Hexo、Jekyll、Wordpress。因为之前的一个同事使用的Hexo的landscape主题,觉得挺喜欢,于是也就选择了Hexo来作为自己的博客平台。</p><p>最初的想法是想通过一台Ubuntu 16.04的阿里云服务器来部署Hexo,但因为域名暂时无法认证,也就作罢。转而使用Github Pages(因为免费的)。文章后面会顺便介绍下如何在云服务器上来部署。 <a id="more"></a></p><h4 id="github-pages配置">GitHub Pages配置</h4><p>创建Github Pages比较简单,首先你在这个全球最大的同性交友网站<code>Github</code>上注册有账号,然后去创建一个仓库就可以了,但是这个仓库是有规则的,其格式必须为<code>your_username.github.io</code> <br>接下来你可以通过这个地址去访问了,只不过现在是个404。</p><h4 id="本地hexo安装与配置">本地Hexo安装与配置</h4><p>Hexo 是用 Node.js 开发的一个静态站点生成器,我们会使用 Node.js 的包管理器 npm 安装 <code>hexo-cli</code> 和 <code>hexo-server</code>这两个核心组件。 <br>笔者使用的是一台ubuntu系统的机器,首先需要安装Node.js和Git: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"># Node.js</div><div class="line">curl https://raw.github.com/creationix/nvm/master/install.sh | sh</div><div class="line">nvm install stable</div><div class="line"># Git</div><div class="line">sudo apt-get install git</div></pre></td></tr></table></figure></p><p><code>Git</code>安装好后进行些配置,可以通过ssh来访问,具体可参考<a href="https://help.github.com/articles/connecting-to-github-with-ssh/" class="uri" target="_blank" rel="external">https://help.github.com/articles/connecting-to-github-with-ssh/</a></p><p>hexo-cli 是 Hexo 的命令行工具,可用于快速新建、发布、部署博客;hexo-server 是 Hexo 的内建服务器,可用于部署前的预览和测试。<code>-g</code> 选项,表示全局安装。 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-cli hexo-server -g</div></pre></td></tr></table></figure></p><p>相应的工具安装完之后,接下来进行一些配置,首先创建一个文件目录: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo init ~/hexo_blog</div></pre></td></tr></table></figure></p><p>该目录下的文件结构可参考<a href="https://hexo.io/zh-cn/docs/setup.html" target="_blank" rel="external">官方文档说明</a>, <code>_config.yml</code>为主配置文件, <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"># URL</div><div class="line">## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'</div><div class="line">url: http://your_username.github.io #填写你的服务器域名</div><div class="line">root: /</div><div class="line">permalink: :year/:month/:day/:title/</div><div class="line">permalink_defaults: en</div><div class="line">...</div><div class="line">...</div><div class="line"># Writing</div><div class="line">new_post_name: :title.md # File name of new posts</div><div class="line">default_layout: draft #表示每篇博文默认都是草稿,必须经过发布之后才能在博客站点上访问。原来的值是 post</div><div class="line">titlecase: false # Transform title into titlecase</div><div class="line">...</div><div class="line">...</div><div class="line"># Deployment</div><div class="line">## Docs: https://hexo.io/docs/deployment.html</div><div class="line">deploy:</div><div class="line"> type: git #通过 Git 将 Hexo 生成的静态内容推送到服务器。</div><div class="line"> repo: [email protected]:your_username/your_username.github.io.git #</div><div class="line"> branch: master</div></pre></td></tr></table></figure></p><p>之后,需要安装一个 Hexo 包,负责将博客所需的静态内容发送到设置好的 Git 仓库。 <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-deployer-git --save</div></pre></td></tr></table></figure></p><p>安装好后可以测试部署:(具体的可以参<a href="https://hexo.io/zh-cn/docs/commands.html" target="_blank" rel="external">官方文档指令</a>) <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">hexo generate && hexo deployer </div><div class="line"># 可以使用hexo server先本地预览</div></pre></td></tr></table></figure></p><p>这样你就可以通过<code>your_username.github.io</code>这个地址去访问你的博客网站了,默认的是landscape主题,个人还是比较喜欢的,当然Hexo上有着多种多样的主题风格。后续博客会继续记录自己对主题的一些修改优化。</p><h4 id="发布自己的第一篇博客">发布自己的第一篇博客</h4><p>Hexo使用的是Markdown,这里推荐一个插件<code>hexo-admin</code>(另一个叫做<code>hexo-hey</code>的也比较类似),可以同时显示预览效果,而且还可以进行创建草稿,发布以及推送至服务器: <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-admin --save</div></pre></td></tr></table></figure></p><p>我们运行<code>hexo s -g</code>,可以通过本地<code>http://localhost:4000/admin</code>进入该页面进行编辑。</p><h4 id="域名绑定">域名绑定</h4><p>笔者由于购买了阿里云的轻量级服务器,也就顺便在其网站上购买了一个域名,本来想找个性化点的<code>.me</code>,并没有看到,选择了<code>.cc</code>,价格也是十分便宜,第一年才不到20块(但居然暂停了<code>.cc</code>的认证,比较气愤),废话不多说了。在控制台的域名服务选项里面选择解析,增加三项:(看了很多网上教程,很多人用的是<a href="https://www.dnspod.cn/" target="_blank" rel="external">DNSpod</a>) <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">A@默认192.30.252.154</div><div class="line">A@默认192.30.252.153</div><div class="line">CNAMEwww默认your_username.github.io #笔者填写的是blog,作为自己的二级域名</div></pre></td></tr></table></figure></p><p>另外在source文件夹中新建一个CNAME文件(无后缀名),并在首行添加你的网站域名,如<code>xxxx.com</code>,当然这里笔者的是<code>blog.neurontech.cc</code></p><p>到这里,我们基本完成了部署工作,现在就请尽情享受自己的博客写作之路吧!</p><h4 id="后续补充">后续补充</h4><p>开始提到的在阿里云上部署Hexo博客平台,可参考在 <a href="https://www.qcloud.com/community/article/241080001487926962" target="_blank" rel="external">Ubuntu 14.04 服务器上部署 Hexo 博客</a>这篇文章,其中<code>nginx</code>的配置文件处需要增加一条命令, <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/</div></pre></td></tr></table></figure> ___ 欢迎转载,但转载请保持转载后文章内容的完整。</p><p>本文链接:http://cequn.wang/2017/09/15/First-post/</p>]]></content>
<summary type="html">
<h4 id="写在前面的话">写在前面的话</h4>
<p>心血来潮,想搭建个人博客用于记录平时工作学习中包括健身等遇到的问题以及解决方法,这样不至于在下次碰到时还会花大量时间去找解决途径,同时也可以给身边的朋友一个参考。</p>
<p>开源的博客平台多如牛毛,而且不乏优秀之作,如 Hexo、Jekyll、Wordpress。因为之前的一个同事使用的Hexo的landscape主题,觉得挺喜欢,于是也就选择了Hexo来作为自己的博客平台。</p>
<p>最初的想法是想通过一台Ubuntu 16.04的阿里云服务器来部署Hexo,但因为域名暂时无法认证,也就作罢。转而使用Github Pages(因为免费的)。文章后面会顺便介绍下如何在云服务器上来部署。
</summary>
<category term="Hexo_blog" scheme="http://cequn.wang/categories/Hexo-blog/"/>
<category term="hexo" scheme="http://cequn.wang/tags/hexo/"/>
<category term="github" scheme="http://cequn.wang/tags/github/"/>
</entry>
</feed>