Linux迷+Python粉//blog.pythonwood.com/2018-12-05T15:00:00+08:00Linux释放磁盘空间——系统日志systemd-journal清理2018-12-05T15:00:00+08:002018-12-05T15:00:00+08:00pythonwoodtag:blog.pythonwood.com,2018-12-05:/2018/12/Linux释放磁盘空间——系统日志systemd-journal清理/<h2 id="varlogjournal">/var/log/journal 目录占用空间很大<a class="headerlink" href="#varlogjournal" title="Permanent link">&para;</a></h2> <p>原因systemd系统通过systemd-journald.service记录日志.&nbsp;默认以二进制写入/var/log/journal/目录中的日志文件,系统安装久了发现磁盘空间逐渐变小。</p> <p>ubuntu18.04,&nbsp;centos7等新系统都使用新型系统systemd,就可能需要清理。</p> <div class="highlight"><pre><span></span>$ du -sh /var/log …</pre></div><h2 id="varlogjournal">/var/log/journal 目录占用空间很大<a class="headerlink" href="#varlogjournal" title="Permanent link">&para;</a></h2> <p>原因systemd系统通过systemd-journald.service记录日志.&nbsp;默认以二进制写入/var/log/journal/目录中的日志文件,系统安装久了发现磁盘空间逐渐变小。</p> <p>ubuntu18.04,&nbsp;centos7等新系统都使用新型系统systemd,就可能需要清理。</p> <div class="highlight"><pre><span></span>$ du -sh /var/log/journal/ <span class="m">2</span>.2G /var/log/journal/ </pre></div> <h2 id="_1">手动命令行清理 单次生效 可临时救急<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2> <p>删除数天以前旧日志</p> <div class="highlight"><pre><span></span># journalctl --vacuum-time=7d Vacuuming done, freed 2.1G of archived journals from /var/log/journal/1095e22a7289463f9f4fdd6d10e3da34. </pre></div> <p>删除到只保留100M日志量的状态</p> <div class="highlight"><pre><span></span># journalctl --vacuum-size=100M Vacuuming done, freed 2.0G of archived journals from /var/log/journal/1095e22a7289463f9f4fdd6d10e3da34. </pre></div> <h2 id="systemd-journaldservice">配置systemd-journald.service 永久生效<a class="headerlink" href="#systemd-journaldservice" title="Permanent link">&para;</a></h2> <p>systemd-journald 的配置文件为 /etc/systemd/journald.conf&nbsp;中,将SystemMaxUse=这行去掉注释,修改为SystemMaxUse=1G,将日志总量限制在1G内。</p> <p>预计下次启动生效,但我测试暂没有效果,不知原因。</p> <h2 id="_2">参考<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2> <p>clear up systemd-journal&nbsp;https://ma.ttias.be/clear-systemd-journal/</p> <p>使用journalctl查看systemd日志&nbsp;https://lujun9972.github.io/blog/2018/08/08/使用journalctl查看systemd日志/</p>网络检测ping脚本——搬瓦工CN2机房PING测试2018-11-25T20:00:00+08:002018-11-27T16:00:00+08:00pythonwoodtag:blog.pythonwood.com,2018-11-25:/2018/11/网络检测ping脚本——搬瓦工CN2机房PING测试/<h2 id="vps">项目起源:搬瓦工vps快过期<a class="headerlink" href="#vps" title="Permanent link">&para;</a></h2> <p>为决定是否upgrade到cn2机房,需要先验证<span class="caps">CN2</span>机房网络是不是更好。一直没有一个适合自己的ping工具,自己写一个。</p> <h3 id="openwrt5ping">部署在openwrt路由,定时任务每5分钟启动ping一次<a class="headerlink" href="#openwrt5ping" title="Permanent link">&para;</a></h3> <p>脚本兼容新旧版本ping(输出内容不同),使用sh标准达到最大linux兼容。已兼容openwrt。</p> <div class="highlight"><pre><span></span># ping 50次,不超过90s,丢包率每字符表示2%,延迟每字符表示10ms */5 …</pre></div><h2 id="vps">项目起源:搬瓦工vps快过期<a class="headerlink" href="#vps" title="Permanent link">&para;</a></h2> <p>为决定是否upgrade到cn2机房,需要先验证<span class="caps">CN2</span>机房网络是不是更好。一直没有一个适合自己的ping工具,自己写一个。</p> <h3 id="openwrt5ping">部署在openwrt路由,定时任务每5分钟启动ping一次<a class="headerlink" href="#openwrt5ping" title="Permanent link">&para;</a></h3> <p>脚本兼容新旧版本ping(输出内容不同),使用sh标准达到最大linux兼容。已兼容openwrt。</p> <div class="highlight"><pre><span></span># ping 50次,不超过90s,丢包率每字符表示2%,延迟每字符表示10ms */5 * * * * /path/to/20181119_host_ping.sh 23.252.103.101 50 90 2 10 &gt;&gt;/tmp/ping.DC3.txt 2&gt;/dev/null */5 * * * * /path/to/20181119_host_ping.sh 65.49.131.102 50 90 2 10 &gt;&gt;/tmp/ping.DC9.txt 2&gt;/dev/null */5 * * * * /path/to/20181119_host_ping.sh vps.old 50 90 2 10 &gt;&gt;/tmp/ping.vps.old.txt 2&gt;/dev/null */5 * * * * /path/to/20181119_host_ping.sh vps.new 50 90 2 10 &gt;&gt;/tmp/ping.vps.new.txt 2&gt;/dev/null </pre></div> <h2 id="host">最终版本的脚本,单host版<a class="headerlink" href="#host" title="Permanent link">&para;</a></h2> <h3 id="_1">脚本使用与输出字段意义<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3> <div class="highlight"><pre><span></span>$ ./20181119_host_ping.sh 请参考文档使用: ./20181119_host_ping.sh &lt;host<span class="p">|</span><span class="m">163</span>.com&gt; &lt;pkgcn<span class="p">|</span><span class="m">10</span>&gt; &lt;maxtime<span class="p">|</span><span class="m">30</span>&gt; &lt;lost_step<span class="p">|</span><span class="m">2</span>&gt; &lt;rt_step<span class="p">|</span><span class="m">5</span>&gt; ./20181119_host_ping.sh <span class="m">163</span>.com <span class="m">10</span> <span class="m">30</span> <span class="m">1</span> <span class="m">5</span> <span class="o">(</span>测10次ping,不超过30s,丢包率每字符表示1%,延迟每字符表示5ms<span class="o">)</span> 时间 出包 入包 丢包 min avg max <span class="p">|</span>图形化丢包率,最长25字符 <span class="p">|</span>图形化延迟avg,最多50字符 <span class="m">2018</span>-11-20_10:08:55 <span class="m">3</span> <span class="m">3</span> <span class="m">2</span>% <span class="m">166</span> <span class="m">167</span> <span class="m">169</span> <span class="p">|</span>xx <span class="p">|</span>**************** </pre></div> <h2 id="_2">比较结果<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2> <p>搬瓦工<span class="caps">CN2</span> <span class="caps">GIA</span>质量非常稳定,土豪随意;对于移动用户访问,<span class="caps">CN2</span>比一般机房提升不大。</p> <p>一天之中2-10点网络最好,晚上6点至凌晨1点最差</p> <div class="highlight"><pre><span></span>root@Gargoyle:/tmp# tail ping.DC9.txt ping.DC3.txt ping.vps.old.txt -n 50 ==&gt; ping.DC9.txt &lt;== 16:00:01 50 50 0% 163 166 170 | |**************** 16:05:01 51 50 1% 163 177 301 | |***************** 16:10:01 50 50 0% 162 166 170 | |**************** 16:15:01 50 50 0% 164 166 171 | |**************** 16:20:01 50 50 0% 164 166 169 | |**************** 16:25:01 50 50 0% 162 166 171 | |**************** 16:30:02 50 50 0% 164 166 171 | |**************** 16:35:01 50 50 0% 163 167 174 | |**************** 16:40:02 50 50 0% 164 167 172 | |**************** 16:45:01 50 50 0% 164 168 173 | |**************** 16:50:01 50 50 0% 163 166 171 | |**************** 16:55:01 50 50 0% 163 166 170 | |**************** 17:00:01 51 50 1% 163 166 174 | |**************** 17:05:01 50 50 0% 164 167 178 | |**************** 17:10:01 50 50 0% 163 166 171 | |**************** 17:15:01 50 50 0% 163 166 170 | |**************** 17:20:01 50 50 0% 163 166 169 | |**************** 17:25:01 50 50 0% 163 166 169 | |**************** 17:30:01 50 50 0% 163 166 171 | |**************** 17:35:01 50 50 0% 163 166 170 | |**************** 17:40:01 50 50 0% 164 167 172 | |**************** 17:45:01 50 50 0% 164 167 169 | |**************** 17:50:01 50 50 0% 164 166 169 | |**************** 17:55:01 50 50 0% 162 166 171 | |**************** 18:00:01 50 50 0% 164 166 170 | |**************** 18:05:01 50 50 0% 164 167 170 | |**************** 18:10:01 50 50 0% 163 165 168 | |**************** 18:15:01 50 50 0% 164 166 170 | |**************** 18:20:01 50 50 0% 164 166 170 | |**************** 18:25:01 50 50 0% 164 166 169 | |**************** 18:30:01 50 50 0% 164 166 169 | |**************** 18:35:01 50 50 0% 164 166 171 | |**************** 18:40:01 50 50 0% 164 167 171 | |**************** 18:45:01 50 50 0% 163 166 170 | |**************** 18:50:01 50 50 0% 164 166 171 | |**************** 18:55:01 50 50 0% 164 166 171 | |**************** 19:00:01 50 50 0% 164 167 188 | |**************** 19:05:01 50 50 0% 164 168 188 | |**************** 19:10:01 50 50 0% 163 166 171 | |**************** 19:15:01 50 50 0% 164 169 174 | |**************** 19:20:01 50 50 0% 163 168 183 | |**************** 19:25:01 50 50 0% 164 167 180 | |**************** 19:30:01 50 50 0% 164 168 187 | |**************** 19:35:01 50 50 0% 163 169 193 | |**************** 19:40:01 50 50 0% 162 168 196 | |**************** 19:45:01 50 50 0% 163 166 169 | |**************** 19:50:01 50 50 0% 163 167 169 | |**************** 19:55:01 50 50 0% 163 166 170 | |**************** 20:00:01 50 50 0% 163 167 192 | |**************** 20:05:01 50 50 0% 162 166 171 | |**************** ==&gt; ping.DC3.txt &lt;== 16:00:01 59 50 15% 234 283 333 |xxxxxxx |**************************** 16:05:01 56 50 10% 174 241 318 |xxxxx |************************ 16:10:01 52 50 3% 188 246 264 |x |************************ 16:15:01 51 50 1% 179 229 255 | |********************** 16:20:02 50 50 0% 189 245 261 | |************************ 16:25:01 51 50 1% 188 246 267 | |************************ 16:30:02 52 50 3% 187 245 265 |x |************************ 16:35:02 50 50 0% 212 249 262 | |************************ 16:40:02 52 50 3% 181 249 264 |x |************************ 16:45:01 53 50 5% 191 233 261 |xx |*********************** 16:50:01 53 50 5% 188 249 263 |xx |************************ 16:55:01 50 50 0% 174 241 263 | |************************ 17:00:01 50 50 0% 208 248 263 | |************************ 17:05:01 50 50 0% 204 242 262 | |************************ 17:10:01 54 50 7% 188 216 252 |xxx |********************* 17:15:01 51 50 1% 218 252 263 | |************************* 17:20:01 51 50 1% 205 249 265 | |************************ 17:25:01 51 50 1% 196 243 261 | |************************ 17:30:01 52 50 3% 197 249 265 |x |************************ 17:35:01 52 50 3% 224 249 262 |x |************************ 17:40:01 54 50 7% 213 251 266 |xxx |************************* 17:45:01 50 50 0% 221 247 265 | |************************ 17:50:01 52 50 3% 206 246 260 |x |************************ 17:55:01 53 50 5% 180 241 265 |xx |************************ 18:00:01 50 50 0% 207 243 262 | |************************ 18:05:01 52 50 3% 198 243 263 |x |************************ 18:10:01 52 50 3% 197 252 264 |x |************************* 18:15:01 51 50 1% 220 247 263 | |************************ 18:20:01 51 50 1% 205 245 263 | |************************ 18:25:01 50 50 0% 178 221 247 | |********************** 18:30:01 51 50 1% 178 237 262 | |*********************** 18:35:01 51 50 1% 161 187 261 | |****************** 18:40:01 51 50 1% 206 241 261 | |************************ 18:45:01 51 50 1% 165 188 209 | |****************** 18:50:01 50 50 0% 209 247 264 | |************************ 18:55:01 50 50 0% 196 236 261 | |*********************** 19:00:01 52 50 3% 167 200 222 |x |******************** 19:05:01 52 50 3% 170 200 238 |x |******************** 19:10:01 50 50 0% 225 248 263 | |************************ 19:15:01 51 50 1% 204 246 263 | |************************ 19:20:01 50 50 0% 226 248 263 | |************************ 19:25:01 51 50 1% 204 249 264 | |************************ 19:30:01 50 50 0% 212 253 265 | |************************* 19:35:01 52 50 3% 206 245 265 |x |************************ 19:40:01 50 50 0% 206 241 286 | |************************ 19:45:01 50 50 0% 180 236 262 | |*********************** 19:50:01 50 50 0% 197 241 264 | |************************ 19:55:01 51 50 1% 213 255 265 | |************************* 20:00:01 54 50 7% 204 254 264 |xxx |************************* 20:05:01 53 50 5% 216 250 265 |xx |************************* ==&gt; ping.vps.old.txt &lt;== 16:00:01 67 50 25% 240 285 338 |xxxxxxxxxxxx |**************************** 16:05:01 61 50 18% 183 247 325 |xxxxxxxxx |************************ 16:10:01 51 50 1% 219 254 270 | |************************* 16:15:02 55 50 9% 182 236 262 |xxxx |*********************** 16:20:01 51 50 1% 197 258 524 | |************************* 16:25:01 50 50 0% 193 276 1166 | |*************************** 16:30:02 52 50 3% 191 250 269 |x |************************* 16:35:02 51 50 1% 231 256 270 | |************************* 16:40:02 50 50 0% 190 254 269 | |************************* 16:45:01 51 50 1% 194 239 266 | |*********************** 16:50:01 50 50 0% 191 256 270 | |************************* 16:55:01 50 50 0% 179 247 266 | |************************ 17:00:01 51 50 1% 220 254 269 | |************************* 17:05:01 50 50 0% 211 248 267 | |************************ 17:10:01 51 50 1% 194 222 256 | |********************** 17:15:01 51 50 1% 213 258 271 | |************************* 17:20:01 52 50 3% 209 255 268 |x |************************* 17:25:01 50 50 0% 199 248 268 | |************************ 17:30:01 50 50 0% 198 255 270 | |************************* 17:35:01 51 50 1% 231 255 270 | |************************* 17:40:01 52 50 3% 220 257 270 |x |************************* 17:45:01 51 50 1% 225 252 267 | |************************* 17:50:01 50 50 0% 208 251 268 | |************************* 17:55:01 51 50 1% 186 248 269 | |************************ 18:00:01 51 50 1% 211 248 272 | |************************ 18:05:01 52 50 3% 207 249 267 |x |************************ 18:10:01 52 50 3% 199 258 269 |x |************************* 18:15:01 50 50 0% 223 252 269 | |************************* 18:20:01 50 50 0% 210 250 267 | |************************* 18:25:01 51 50 1% 184 227 254 | |********************** 18:30:01 50 50 0% 187 244 267 | |************************ 18:35:01 51 50 1% 169 194 268 | |******************* 18:40:01 51 50 1% 212 247 266 | |************************ 18:45:01 50 50 0% 170 193 213 | |******************* 18:50:01 51 50 1% 216 252 269 | |************************* 18:55:01 50 50 0% 201 242 267 | |************************ 19:00:01 50 50 0% 170 206 227 | |******************** 19:05:01 51 50 1% 175 208 261 | |******************** 19:10:01 50 50 0% 230 253 267 | |************************* 19:15:01 53 50 5% 210 253 268 |xx |************************* 19:20:01 50 50 0% 230 254 267 | |************************* 19:25:01 50 50 0% 211 254 268 | |************************* 19:30:01 50 50 0% 221 259 269 | |************************* 19:35:01 51 50 1% 213 252 269 | |************************* 19:40:01 50 50 0% 220 248 268 | |************************ 19:45:01 50 50 0% 187 241 267 | |************************ 19:50:01 50 50 0% 202 247 270 | |************************ 19:55:01 52 50 3% 216 261 268 |x |************************** 20:00:01 51 50 1% 212 258 269 | |************************* 20:05:01 52 50 3% 228 257 270 |x |************************* </pre></div> <h3 id="2018-11-27">2018-11-27后注:<a class="headerlink" href="#2018-11-27" title="Permanent link">&para;</a></h3> <p>作为搬瓦工多年老用户,随着去年以来ssh操作vps卡顿日渐严重,差点就因此粉转黑。&nbsp;不过对我来说,还是搬瓦工性价比高,操作熟悉。</p> <p>非常遗憾,错过史上最大促销(<span class="caps">CPU</span>:2 核 内存:2048 <span class="caps">MB</span> 硬盘:40 <span class="caps">GB</span> <span class="caps">SSD</span> 流量:1 <span class="caps">TB</span> <span class="caps">CN2</span>网络)相当于打3折。&nbsp;25号因为黑五优惠,买了普通cn2机房vps。</p> <p>让人满意的是,ping结果事实证明,新vps比老vps的网络环境好了小一倍。 老旧vps都安装了nginx,使用http播放mp4视频,新vps体验完胜老vps。 就算去掉部分优化的影响:新vps系统是ubuntu18.04并开启了<span class="caps">BBR</span>拥塞算法。</p> <p><strong>最终结果:cn2机房vps完胜老vps</strong></p> <div class="highlight"><pre><span></span>$ tail /tmp/ping.vps* -n <span class="m">40</span> <span class="p">|</span> sed <span class="s1">&#39;s/2018-11-27_//&#39;</span> <span class="p">|</span> sed <span class="s1">&#39;/^16:/d&#39;</span> <span class="o">==</span>&gt; /tmp/ping.vpsold.txt &lt;<span class="o">==</span> <span class="m">13</span>:30:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">180</span> <span class="m">221</span> <span class="m">267</span> <span class="p">|</span> <span class="p">|</span>********************** <span class="m">13</span>:35:01 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">216</span> <span class="m">271</span> <span class="m">518</span> <span class="p">|</span> <span class="p">|</span>*************************** <span class="m">13</span>:40:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">222</span> <span class="m">233</span> <span class="m">247</span> <span class="p">|</span> <span class="p">|</span>*********************** <span class="m">13</span>:45:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">195</span> <span class="m">236</span> <span class="m">269</span> <span class="p">|</span> <span class="p">|</span>*********************** <span class="m">13</span>:50:01 <span class="m">55</span> <span class="m">50</span> <span class="m">9</span>% <span class="m">235</span> <span class="m">246</span> <span class="m">265</span> <span class="p">|</span>xxxx <span class="p">|</span>************************ <span class="m">13</span>:55:01 <span class="m">56</span> <span class="m">50</span> <span class="m">10</span>% <span class="m">261</span> <span class="m">281</span> <span class="m">311</span> <span class="p">|</span>xxxxx <span class="p">|</span>**************************** <span class="m">14</span>:00:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">166</span> <span class="m">225</span> <span class="m">248</span> <span class="p">|</span> <span class="p">|</span>********************** <span class="m">14</span>:05:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">168</span> <span class="m">197</span> <span class="m">230</span> <span class="p">|</span> <span class="p">|</span>******************* <span class="m">14</span>:10:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">162</span> <span class="m">181</span> <span class="m">217</span> <span class="p">|</span> <span class="p">|</span>****************** <span class="m">14</span>:15:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">196</span> <span class="m">231</span> <span class="m">280</span> <span class="p">|</span> <span class="p">|</span>*********************** <span class="m">14</span>:20:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">212</span> <span class="m">239</span> <span class="m">265</span> <span class="p">|</span> <span class="p">|</span>*********************** <span class="m">14</span>:25:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">195</span> <span class="m">246</span> <span class="m">288</span> <span class="p">|</span> <span class="p">|</span>************************ <span class="m">14</span>:30:02 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">192</span> <span class="m">233</span> <span class="m">263</span> <span class="p">|</span> <span class="p">|</span>*********************** <span class="m">14</span>:35:02 <span class="m">52</span> <span class="m">50</span> <span class="m">3</span>% <span class="m">220</span> <span class="m">264</span> <span class="m">292</span> <span class="p">|</span>x <span class="p">|</span>************************** <span class="m">14</span>:40:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">178</span> <span class="m">211</span> <span class="m">259</span> <span class="p">|</span> <span class="p">|</span>********************* <span class="m">14</span>:45:02 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">172</span> <span class="m">204</span> <span class="m">234</span> <span class="p">|</span> <span class="p">|</span>******************** <span class="m">14</span>:50:01 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">245</span> <span class="m">281</span> <span class="m">321</span> <span class="p">|</span> <span class="p">|</span>**************************** <span class="m">14</span>:55:01 <span class="m">53</span> <span class="m">50</span> <span class="m">5</span>% <span class="m">231</span> <span class="m">296</span> <span class="m">337</span> <span class="p">|</span>xx <span class="p">|</span>***************************** <span class="m">15</span>:00:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">231</span> <span class="m">263</span> <span class="m">290</span> <span class="p">|</span> <span class="p">|</span>************************** <span class="m">15</span>:05:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">229</span> <span class="m">258</span> <span class="m">282</span> <span class="p">|</span> <span class="p">|</span>************************* <span class="m">15</span>:10:01 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">195</span> <span class="m">241</span> <span class="m">277</span> <span class="p">|</span> <span class="p">|</span>************************ <span class="m">15</span>:15:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">213</span> <span class="m">263</span> <span class="m">320</span> <span class="p">|</span> <span class="p">|</span>************************** <span class="m">15</span>:20:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">182</span> <span class="m">208</span> <span class="m">225</span> <span class="p">|</span> <span class="p">|</span>******************** <span class="m">15</span>:25:01 <span class="m">51</span> <span class="m">50</span> <span class="m">1</span>% <span class="m">227</span> <span class="m">268</span> <span class="m">313</span> <span class="p">|</span> <span class="p">|</span>************************** <span class="m">15</span>:30:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">218</span> <span class="m">288</span> <span class="m">340</span> <span class="p">|</span> <span class="p">|</span>**************************** <span class="m">15</span>:35:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">187</span> <span class="m">225</span> <span class="m">339</span> <span class="p">|</span> <span class="p">|</span>********************** <span class="m">15</span>:40:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">224</span> <span class="m">263</span> <span class="m">297</span> <span class="p">|</span> <span class="p">|</span>************************** <span class="m">15</span>:45:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">235</span> <span class="m">259</span> <span class="m">288</span> <span class="p">|</span> <span class="p">|</span>************************* <span class="m">15</span>:50:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">195</span> <span class="m">249</span> <span class="m">274</span> <span class="p">|</span> <span class="p">|</span>************************ <span class="m">15</span>:55:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">220</span> <span class="m">264</span> <span class="m">302</span> <span class="p">|</span> <span class="p">|</span>************************** <span class="o">==</span>&gt; /tmp/ping.vpsold.txt &lt;<span class="o">==</span> <span class="m">13</span>:30:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">159</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">13</span>:35:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">13</span>:40:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">160</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">13</span>:45:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">13</span>:50:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">13</span>:55:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">155</span> <span class="m">159</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">14</span>:00:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:05:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:10:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:15:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">14</span>:20:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:25:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:30:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">159</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">14</span>:35:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:40:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">14</span>:45:02 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">14</span>:50:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">163</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">14</span>:55:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:00:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">15</span>:05:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:10:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">15</span>:15:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:20:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">15</span>:25:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">164</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:30:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">166</span> <span class="m">192</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:35:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">160</span> <span class="m">190</span> <span class="m">201</span> <span class="p">|</span> <span class="p">|</span>******************* <span class="m">15</span>:40:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">160</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>**************** <span class="m">15</span>:45:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">155</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">15</span>:50:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">157</span> <span class="m">159</span> <span class="m">162</span> <span class="p">|</span> <span class="p">|</span>*************** <span class="m">15</span>:55:01 <span class="m">50</span> <span class="m">50</span> <span class="m">0</span>% <span class="m">156</span> <span class="m">160</span> <span class="m">176</span> <span class="p">|</span> <span class="p">|</span>**************** </pre></div>神奇的环境bug导致python3中出现udc开头字符串2018-11-07T15:30:00+08:002018-11-07T15:30:00+08:00pythonwoodtag:blog.pythonwood.com,2018-11-07:/2018/11/神奇的环境bug导致python3中出现udc开头字符串/<h2 id="langzh_cnutf-8langen_usutf-8">注意:<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8与<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8不可混淆!<a class="headerlink" href="#langzh_cnutf-8langen_usutf-8" title="Permanent link">&para;</a></h2> <p><strong><span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8与<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8有区别</strong> ,&nbsp;所以不可混淆!想之前在python2时代吃过坑,没想到到了统一unicode的python3 …</p><h2 id="langzh_cnutf-8langen_usutf-8">注意:<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8与<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8不可混淆!<a class="headerlink" href="#langzh_cnutf-8langen_usutf-8" title="Permanent link">&para;</a></h2> <p><strong><span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8与<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8有区别</strong> ,&nbsp;所以不可混淆!想之前在python2时代吃过坑,没想到到了统一unicode的python3,因环境不一致也能导致编码问题!</p> <h2 id="_1">当时环境与功能:<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h2> <p>vps系统是ubutnu 14.04, 相关软件python3.4, selenium3+, chrome66, chromedriver。使用crontab启动shell, shell中启动python脚本,&nbsp;脚本中selenium启动chrome,……</p> <h2 id="bug">出bug的运行流程:<a class="headerlink" href="#bug" title="Permanent link">&para;</a></h2> <ol> <li>crontab中的a.sh启动 <strong><span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8 bash&nbsp;a.sh</strong></li> <li>a.sh末尾调用&rdquo;b中文名.py&rdquo;,&nbsp;带中文参数&rdquo;《xxx》&rdquo;</li> <li>b中文.py 中print(参数1) 会异常显示字符串编码问题&rsquo;ascii&rsquo; codec can&rsquo;t encode&nbsp;characters</li> </ol> <h2 id="_2">调试发现:<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2> <ol> <li>print repr(中文参数1), 会打印\udc&nbsp;开头的而非\x开头的utf8型编码。</li> <li>比如&rdquo;《&rdquo; 正常编码是 <strong>&lsquo;\xe3\x80\x8a&rsquo;, 此处确是打印了&rsquo;\udce3\udc80\udc8a&rsquo;</strong>&nbsp;。</li> <li>改变逻辑,直接ssh到vps并执行 <strong>b中文.py 《xxx》</strong>&nbsp;没有问题!</li> </ol> <h2 id="_3">问题定位:<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2> <ol> <li>个人本机ubuntu系统测试不会出现bug,vps才出现,所以应该是shell环境或者是python环境问题。</li> <li>打印执行a.sh的shell环境,对比发现本机有<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8和<span class="caps">LANGUAGE</span>=zh_CN:zh,vps仅有<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8。</li> <li>把crontab中强加的环境变量<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8去掉,此时a.sh的环境变量为<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8,&nbsp;vps恢复正常。(2小时排查出结果了!)</li> <li>总结: 之前觉得<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8与<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8没什么不同,从此改观。</li> </ol> <h2 id="_4">问题解决:<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h2> <p>去掉<span class="caps">LANG</span>=zh_CN.<span class="caps">UTF</span>-8,之后执行过程中会自动变成默认<span class="caps">LANG</span>=en_US.<span class="caps">UTF</span>-8</p> <h2 id="_5">原因探究:<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h2> <p>待定</p> <h2 id="python-reprudc-print">python repr输出udc开头字符串, print(参数)导致异常<a class="headerlink" href="#python-reprudc-print" title="Permanent link">&para;</a></h2> <div class="highlight"><pre><span></span>&#39;/home/maskuser/path/to/ts/\udce3\udc80\udc8a\udce9\udc80\udc97.....mp4&#39; Traceback (most recent call last): File &quot;/home/maskuser/pathtodir/script/20181105\udce8\udca7\udc86\.....py&quot;, line 73, in &lt;module&gt; video_upload_testsite(*sys.argv[1:]) File &quot;/home/maskuser/pathtodir/script/20181105\udce8\udca7\udc86\.....py&quot;, line 29, in video_upload_testsite print (videopath) UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode characters in position 27-50: ordinal not in range(128) </pre></div>XUbuntu18.04(Bionic河狸)正式发布,系统安装升级记录2018-04-27T19:00:00+08:002018-04-27T19:00:00+08:00pythonwoodtag:blog.pythonwood.com,2018-04-27:/2018/04/XUbuntu18.04(Bionic河狸)正式发布,系统安装升级记录/<p>Ubuntu&nbsp;18.04发布时间是(美国)4月26号,彼时的中国已经是27号,就是今天。我花了一天时间折腾升级旧Ubuntu系统到刚发布的最新版。</p> <p>多年使用linux经验已经使得这个过程驾轻就熟,闲庭信步:)。为了不忘记,将有沉淀价值的部分,简要记录一下。</p> <h2 id="linuxubuntu">偶然得知Linux,成为Ubuntu多年用户<a class="headerlink" href="#linuxubuntu" title="Permanent link">&para;</a></h2> <h3 id="ubuntults">建议:只使用Ubuntu的<span class="caps">LTS</span>版本(长期维护 …</h3><p>Ubuntu&nbsp;18.04发布时间是(美国)4月26号,彼时的中国已经是27号,就是今天。我花了一天时间折腾升级旧Ubuntu系统到刚发布的最新版。</p> <p>多年使用linux经验已经使得这个过程驾轻就熟,闲庭信步:)。为了不忘记,将有沉淀价值的部分,简要记录一下。</p> <h2 id="linuxubuntu">偶然得知Linux,成为Ubuntu多年用户<a class="headerlink" href="#linuxubuntu" title="Permanent link">&para;</a></h2> <h3 id="ubuntults">建议:只使用Ubuntu的<span class="caps">LTS</span>版本(长期维护)<a class="headerlink" href="#ubuntults" title="Permanent link">&para;</a></h3> <p>我的Ubuntu升级之路是10.04 -&gt; 14.04 -&gt; 18.0,中间的<span class="caps">LTS</span>版本12.04和16.04因在升级后不满意而没用,回滚恢复降版本。如果升级前没有备份,就没法恢复。系统升级前备份旧系统的准备很重要,让你可以安心折腾走得更远。这次也是花了很长时间全备份的。如果失败需要恢复系统可参考<a href="//blog.pythonwood.com/2017/11/树莓派SD卡Linux系统盘复制,10分钟克隆新机/" title="树莓派SD卡Linux系统盘复制,10分钟克隆新机">关于linux系统备份与恢复的随笔</a></p> <h3 id="xubuntu1804bionic">期待已久的XUbuntu18.04(Bionic河狸)正式发布<a class="headerlink" href="#xubuntu1804bionic" title="Permanent link">&para;</a></h3> <p>新系统意味着更好的驱动,更好的软件版本,比如ubuntu14.04驱动<span class="caps">RTL8723BE</span>这种网卡会偶尔掉线。不幸,我的一台笔记本就是<span class="caps">RTL8723BE</span>网卡的。显然大版本升级 14.04 -&gt; 18.04 能巧妙地不折腾而解决很多旧问题(再比如http2支持)。因此,我是带着期待在等待Ubuntu18.04发布的,同时这次升级也没有退路(14.04太老了)。幸好,升级还算满意。已经用上了最新Ubuntu了,并且速度还可以,在换<span class="caps">SSD</span>盘后的酷睿I3老机上运行顺畅。</p> <h4 id="ubuntu-1804-xubutnu">Ubuntu 18.04 桌面截图(XUbutnu)<a class="headerlink" href="#ubuntu-1804-xubutnu" title="Permanent link">&para;</a></h4> <p><img alt="XUbutnu18.04桌面截图" src="//blog.pythonwood.com/uploads/2018/2018-04-27XUbutnu18.04桌面截图.jpg" title="XUbutnu18.04桌面截图"></p> <h2 id="ubutnu1804-xfce">Ubutnu18.04安装升级过程 (Xfce版本)<a class="headerlink" href="#ubutnu1804-xfce" title="Permanent link">&para;</a></h2> <h3 id="10-ubutnuxubuntu">1.0 选择并下载Ubutnu版本(XUbuntu)<a class="headerlink" href="#10-ubutnuxubuntu" title="Permanent link">&para;</a></h3> <p>旧系统是配搭Xfce桌面的<a href="//blog.pythonwood.com/2014/07/笔记本系统转换Linux一个半月——xubuntu14.04截图纪念里程碑/" title="xubuntu14.04截图纪念">XUbuntu14.04</a>,Xfce同时也是Linus本人选择<a href="https://linux.cn/article-202-1.html" title="Linus Torvalds 弃 GNOME 3 用 Xfce">Linus Torvalds 弃 <span class="caps">GNOME</span> 3 用 Xfce</a>。XUbuntu里面的好软件有很多,比如文件管理器Thunar,截图软件xfce4-screenshooter,网速提示器xfce4-netload-plugin,<span class="caps">CPU</span>内存提示器xfce4-systemload-plugin等等。同时Ubuntu18的Xfce比原版<span class="caps">ISO</span>文件轻量很多。 <img alt="Ubuntu18的Xfce比原版ISO文件轻量很多" src="//blog.pythonwood.com/uploads/2018/2018-04-27Ubuntu18的Xfce比原版ISO文件轻量很多.jpg"></p> <h3 id="20">2.0 升级前先备份<a class="headerlink" href="#20" title="Permanent link">&para;</a></h3> <h4 id="21-deb">2.1 备份已安装过的deb包名称列表<a class="headerlink" href="#21-deb" title="Permanent link">&para;</a></h4> <div class="highlight"><pre><span></span><span class="o">(</span> <span class="nt">zcat</span> <span class="o">/</span><span class="nt">var</span><span class="o">/</span><span class="nt">log</span><span class="o">/</span><span class="nt">apt</span><span class="o">/</span><span class="nt">history</span><span class="p">.</span><span class="nc">log</span><span class="o">*</span><span class="p">.</span><span class="nc">gz</span> <span class="o">|</span> <span class="nt">grep</span> <span class="nt">Commandline</span><span class="o">:</span> <span class="o">;</span> <span class="nt">zcat</span> <span class="o">/</span><span class="nt">var</span><span class="o">/</span><span class="nt">log</span><span class="o">/</span><span class="nt">apt</span><span class="o">/</span><span class="nt">history</span><span class="p">.</span><span class="nc">log</span><span class="o">*</span><span class="p">.</span><span class="nc">gz</span> <span class="o">|</span> <span class="nt">grep</span> <span class="nt">Commandline</span><span class="o">:</span> <span class="o">)</span> <span class="o">&gt;</span> <span class="o">~/</span><span class="nt">deb</span><span class="p">.</span><span class="nc">list</span><span class="p">.</span><span class="nc">txt</span> </pre></div> <h4 id="22-pythonrubyperl">2.2 备份已安装过的python包名称列表(无则忽略,ruby,perl等备份操作同理)<a class="headerlink" href="#22-pythonrubyperl" title="Permanent link">&para;</a></h4> <div class="highlight"><pre><span></span>( pip2 list ; pip3 list ) &gt; ~/pip.list.txt </pre></div> <h4 id="23-etcvar-rootetcvar">2.3 /etc,/var一些关键目录备份, root权限执行(/etc是配置文件仓库,/var包含各用户的定时任务)<a class="headerlink" href="#23-etcvar-rootetcvar" title="Permanent link">&para;</a></h4> <div class="highlight"><pre><span></span>cd /; sudo tar czf ~/etc.tar.gz etc var/spool/cron/crontabs </pre></div> <h4 id="24">2.4 繁重但强烈建议的全盘备份<a class="headerlink" href="#24" title="Permanent link">&para;</a></h4> <p>备份方法多种:rsync同步到安全盘备份 或 tar打包放到安全目录下 或&nbsp;dd复制分区为文件保存到安全目录下。</p> <h3 id="30">3.0 分区、格式化、安装<a class="headerlink" href="#30" title="Permanent link">&para;</a></h3> <h4 id="31-ubuntu1804">3.1 方式一:从新硬盘或空白分区安装ubuntu18.04<a class="headerlink" href="#31-ubuntu1804" title="Permanent link">&para;</a></h4> <p>linux分区不是越多越好的,推荐 / + /home 模式, 实用而不折腾,&nbsp;一个分区代表系统,一个分区代表用户数据空间。这样的好处就是为后续升级带来方便。</p> <p>根 / 分区给15G已经完全足够,绰绰有余了。&nbsp;把剩余空间都给/home,因为/分区使用量不会明显增加,/home分区放的东西却会成倍的增加。</p> <p>多年之后我目前用的分区方式,window与linux双系统共存的分区方式。msdos方式只能4主分区,刚好用完: <img alt="Ubuntu安装推荐分区" src="//blog.pythonwood.com/uploads/2018/2018-04-27Ubuntu安装推荐分区.jpg" title="Ubuntu安装推荐分区"></p> <h4 id="32-linux">3.2 方式二:从旧linux系统升级<a class="headerlink" href="#32-linux" title="Permanent link">&para;</a></h4> <p>告诫:不要尝试从命令<code>sudo apt-get dist-upgrade</code>升级,结局一般都是不能自动处理错误而中止升级,系统可能因此寿终正寝,只留下无辜的你。这和不要尝试用系统升级方法装windows是一样的。</p> <p>参考升级方法:</p> <ol> <li>之前已有linux分区是 / + /home 模式,先把 &ldquo;/&rdquo; 所在分区格式化,然后将整个ubuntu18.04安装 &ldquo;/&rdquo;&nbsp;所在区。</li> <li>系统安装后重启进入ubuntu18.04系统,原 &ldquo;/home&rdquo; 分区不会挂载。&nbsp;总过程已经完成一半了。</li> <li>再挂载并将原 &ldquo;/home&rdquo; 分区清理瘦身一下,删除家目录中.thumbnails,&nbsp;.cache这些可能冲突或不大重要的用户数据。</li> <li>将新/home目录内容rsync同步到旧 &ldquo;/home&rdquo;&nbsp;分区所在目录里。</li> <li>修改/etc/fstab,增加1行让系统重启后挂载原 &ldquo;/home&rdquo;&nbsp;盘。确认无误后重启就完成全部过程。</li> </ol> <p>这样的好处是家目录中的图片、视频、工作文件、工作目录等用户资料依然在那里,变了的只是系统部分,优雅完成升级。</p> <h3 id="40-ubuntu1804">4.0 安装Ubuntu18.04系统之后的优化<a class="headerlink" href="#40-ubuntu1804" title="Permanent link">&para;</a></h3> <h4 id="41-ubuntu1804">4.1 Ubuntu18.04修改源<a class="headerlink" href="#41-ubuntu1804" title="Permanent link">&para;</a></h4> <p>原来的url是cn.archive.ubuntu.com, 速度下载包时有<span class="caps">3MB</span>以上。其实不换也是可以的。</p> <p>如果要换, 以阿里举例, 修改/etc/apt/sources.list文件内容即可(修改前备份),&nbsp;改其他第三方的同理该域名即可。</p> <div class="highlight"><pre><span></span><span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic</span> <span class="kp">main</span> <span class="kp">restricted</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic-updates</span> <span class="kp">main</span> <span class="kp">restricted</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic</span> <span class="kp">universe</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic-updates</span> <span class="kp">universe</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic</span> <span class="kp">multiverse</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic-updates</span> <span class="kp">multiverse</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu/</span> <span class="kp">bionic-backports</span> <span class="kp">main</span> <span class="kp">restricted</span> <span class="kp">universe</span> <span class="kp">multiverse</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu</span> <span class="kp">bionic-security</span> <span class="kp">main</span> <span class="kp">restricted</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu</span> <span class="kp">bionic-security</span> <span class="kp">universe</span> <span class="k">deb</span> <span class="s">http://mirrors.aliyun.com/ubuntu</span> <span class="kp">bionic-security</span> <span class="kp">multiverse</span> </pre></div> <h3 id="42-ubuntu1804">4.2 Ubuntu18.04调整用户界面、桌面工具栏、安装字体、重新安装历史包等<a class="headerlink" href="#42-ubuntu1804" title="Permanent link">&para;</a></h3> <h4 id="421-xp">4.2.1 调整桌面工具栏到下面,下重上轻的风格看起来比较稳重。也是xp时代传下的习惯。<a class="headerlink" href="#421-xp" title="Permanent link">&para;</a></h4> <h5 id="xubutnu1804ubuntubionic-beaver"><strong>XUbutnu18.04截图(Ubuntu),这个版本别名&rdquo;Bionic Beaver&rdquo;仿生河狸</strong><a class="headerlink" href="#xubutnu1804ubuntubionic-beaver" title="Permanent link">&para;</a></h5> <p><img alt="XUbutnu18.04程序截图" src="//blog.pythonwood.com/uploads/2018/2018-04-27XUbutnu18.04程序截图.jpg" title="XUbutnu18.04程序截图"></p> <h4 id="422-cpu">4.2.2 在桌面地板面板工具栏上,添加自定义显示比如网速,<span class="caps">CPU</span>,内存等。<a class="headerlink" href="#422-cpu" title="Permanent link">&para;</a></h4> <p>添加网速提示器xfce4-netload-plugin,<span class="caps">CPU</span>内存提示器xfce4-systemload-plugin后的工具栏随时可获知负载网速这些计算机情况,用户体验比windows更赞! <img alt="XUbuntu已设置显示网速和CPU内存负载的工具栏" src="//blog.pythonwood.com/uploads/2018/2018-04-27XUbuntu已设置显示网速和CPU内存负载的工具栏.jpg" title="XUbuntu已设置显示网速和CPU内存负载的工具栏"></p> <h4 id="423">4.2.3 安装谷歌拼音,文泉驿字体,调整系统字体大小等<a class="headerlink" href="#423" title="Permanent link">&para;</a></h4> <p>Ubuntu18.04默认安装fcitx-sunpinyin也好用,用起来和googlepinyin差不多。所以……我还是选大款的好了。</p> <div class="highlight"><pre><span></span>sudo apt-get install fcitx-googlepinyin fonts-wqy* </pre></div> <h4 id="424">4.2.4 安装以前安装过的软件<a class="headerlink" href="#424" title="Permanent link">&para;</a></h4> <p>之前记录过旧系统安装的软件,现在按需安装回来。</p> <div class="highlight"><pre><span></span>apt-get install gedit gthumb tmux vim-gtk3 python-pip python3-pip ipython ipython3 iotop iftop sysstat nload iptraf virtualbox virtualbox-ext-pack gparted testdisk fcitx-googlepinyin smplayer vlc gpaint xpaint pinta pelican python-bs4 axel aria2 unzip apt-file gimp remmina retext potool curl geoip-bin phantomjs lynx vim-tiny gnome-disk-utility sqlite3 python-mysqldb python-pymysql kazam pitivi gsound-tools flowblade mp3splt-gtk mp3wrap mtp-tools adb cmake </pre></div> <h3 id="43-qqctrlaltalinuxxfce-screenshooterqq">4.3 实现<span class="caps">QQ</span>截图功能,快捷键Ctrl+Alt+A框选截屏。(linux下用xfce-screenshooter变身<span class="caps">QQ</span>截图神器)<a class="headerlink" href="#43-qqctrlaltalinuxxfce-screenshooterqq" title="Permanent link">&para;</a></h3> <p>不需安装额外软件xfce-screenshooter是XUbuntu自带的,只需操作如下步骤: 打开设置-&gt; 键盘 -&gt; 应用程序快捷键 -&gt; 添加。 然后命令框输入xfce4-screenshooter&nbsp;&ndash;region确认,再按住Ctrl+Alt+A,确认添加即可。</p> <p>xfce4-screenshooter这软件很赞,不需安装<span class="caps">QQ</span>就能有很好的截图体验。某些时候,linux用户体验可以比windows好,需要使用者本身已经对linux比较上手。 <img alt="在Linux下设置QQ截图功能" src="//blog.pythonwood.com/uploads/2018/2018-04-27在Linux下设置QQ截图功能.jpg" title="在Linux下设置QQ截图功能"></p> <h3 id="50-ubuntu1804">5.0 安装Ubuntu18.04系统之后的问题解决<a class="headerlink" href="#50-ubuntu1804" title="Permanent link">&para;</a></h3> <h4 id="51-ubuntu1804shadowsocks">5.1 Ubuntu18.04启动shadowsocks报错解决<a class="headerlink" href="#51-ubuntu1804shadowsocks" title="Permanent link">&para;</a></h4> <p>原因:openssl升级到1.1.0以上版本,导致shadowsocks启动报undefined symbol:&nbsp;EVP_CIPHER_CTX_cleanup错误</p> <p>解决:&nbsp;将py文件中所有的EVP_CIPHER_CTX_cleanup改为EVP_CIPHER_CTX_reset</p> <div class="highlight"><pre><span></span>sudo vim /usr/local/lib/python2.7/dist-packages/shadowsocks/crypto/openssl.py # 按实际路径改 </pre></div> <h4 id="52-ubuntu1804wpserror-while-loading-shared-libraries-libpng12so0">5.2 Ubuntu18.04安装wps(解决报错error while loading shared libraries: libpng12.so.0)<a class="headerlink" href="#52-ubuntu1804wpserror-while-loading-shared-libraries-libpng12so0" title="Permanent link">&para;</a></h4> <p>第一步下载wps-office_10.1.0.5672~a21_amd64.deb, libpng12-0_1.2.54-1ubuntu1_amd64.deb,&nbsp;wps_symbol_fonts.zip(window字体非必须)文件备用。</p> <p>第二步运行命令安装:</p> <div class="highlight"><pre><span></span>sudo dpkg -i wps-office_10.1.0.5672~a21_amd64.deb libpng12-0_1.2.54-1ubuntu1_amd64.deb </pre></div> <h4 id="53-panel">5.3 底部面板panel出现重复的网络图标解决<a class="headerlink" href="#53-panel" title="Permanent link">&para;</a></h4> <p><img alt="panel面板重复出现network图标" src="//blog.pythonwood.com/uploads/2018/2018-05-09面板显示重复网络图标.png" title="panel面板重复出现network图标"></p> <p>解决:设置 - 会话与启动 - 程序自启动 - 取消勾选network项。 注销,再登录,重新勾选,注销,再登录。&nbsp;图标恢复只有一个。</p> <h3 id="60-ubuntu1804">6.0 安装Ubuntu18.04总结提升<a class="headerlink" href="#60-ubuntu1804" title="Permanent link">&para;</a></h3> <p>升级过程比较有把握,遇到的问题都是典型缺so文件这些小问题,通过谷歌搜索就能解决。</p> <p>某些时候,linux用户体验可以比windows好,需要使用者本身已经对linux比较上手。</p>实测家庭电器电功率记录——节约用电支持环保2018-04-20T15:16:00+08:002018-04-20T15:16:00+08:00pythonwoodtag:blog.pythonwood.com,2018-04-20:/2018/04/实测家庭电器电功率记录——节约用电支持环保/<p>家用电器经常待机,手机插头不拔,长期旅行不清空冰箱不关总闸,我一直认为浪费电但没有具体量化的认知。最近下决心花36元来记录电器的耗电功率排行。具体就是买了个可以显示耗电快慢的<a href="https://s.click.taobao.com/t?e=m%3D2%26s%3DNYboi0mHsGQcQipKwQzePOeEDrYVVa64K7Vc7tFgwiHjf2vlNIV67rTJ9qRSwRX4jGYPrSmetxGs9V29auOuBOBgn3DwXo5fs9cRaxJdiKw3LnkA3bZiA5IdTsHekIOqQxPkL4fipmEcVFeZKQgm4n%2BucW%2B%2Fygb8cSpj5qSCmbA%3D&amp;pvid=10_120.239.178.83_3183_1524209142036" title="家用电功率计量插座">家用电功率计量插座</a>,然后花了些时间测量数据并记录下来。随用随测出结果,十分好用。</p> <h3 id="_1">实测过程<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3> <p><img alt="电功率插座显示插头纯消耗功率是0.5W" src="//blog.pythonwood.com/uploads/2018/电功率插座显示插头纯消耗功率是0.5W.jpg" title="电功率插座显示插头纯消耗功率是0.5W"></p> <p>插座本身很小,测试过程非常方便。插上就实时显示电功率,按上下可切换显示电压,频率,时间,功率因素等。</p> <p>孔位不多没有关系,可加一个排插测出总电功率就好 …</p><p>家用电器经常待机,手机插头不拔,长期旅行不清空冰箱不关总闸,我一直认为浪费电但没有具体量化的认知。最近下决心花36元来记录电器的耗电功率排行。具体就是买了个可以显示耗电快慢的<a href="https://s.click.taobao.com/t?e=m%3D2%26s%3DNYboi0mHsGQcQipKwQzePOeEDrYVVa64K7Vc7tFgwiHjf2vlNIV67rTJ9qRSwRX4jGYPrSmetxGs9V29auOuBOBgn3DwXo5fs9cRaxJdiKw3LnkA3bZiA5IdTsHekIOqQxPkL4fipmEcVFeZKQgm4n%2BucW%2B%2Fygb8cSpj5qSCmbA%3D&amp;pvid=10_120.239.178.83_3183_1524209142036" title="家用电功率计量插座">家用电功率计量插座</a>,然后花了些时间测量数据并记录下来。随用随测出结果,十分好用。</p> <h3 id="_1">实测过程<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3> <p><img alt="电功率插座显示插头纯消耗功率是0.5W" src="//blog.pythonwood.com/uploads/2018/电功率插座显示插头纯消耗功率是0.5W.jpg" title="电功率插座显示插头纯消耗功率是0.5W"></p> <p>插座本身很小,测试过程非常方便。插上就实时显示电功率,按上下可切换显示电压,频率,时间,功率因素等。</p> <p>孔位不多没有关系,可加一个排插测出总电功率就好。</p> <p>但很可惜,最想测试的电热水器因为插孔为非普标的,所以没能测试。</p> <h3 id="_2">电器功耗实测记录表<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h3> <table> <thead> <tr> <th>常用电器元件</th> <th>耗电功率</th> </tr> </thead> <tbody> <tr> <td>树莓派</td> <td>4.5W (开机过程8W)</td> </tr> <tr> <td>笔记本电脑</td> <td>10W (开机过程20W)</td> </tr> <tr> <td>手机充电器</td> <td>0W (充电时2W)</td> </tr> <tr> <td>排插</td> <td>0.5W</td> </tr> <tr> <td>低音音箱</td> <td>15W</td> </tr> <tr> <td>hp打印机</td> <td>1W (A4打印时10W)</td> </tr> <tr> <td>广电机顶盒</td> <td>7W</td> </tr> <tr> <td>tplink路由</td> <td>2.4W</td> </tr> <tr> <td>上网猫</td> <td>3W</td> </tr> <tr> <td>oye路由</td> <td>1.5W</td> </tr> <tr> <td>电风扇待机</td> <td>0W</td> </tr> </tbody> </table> <h3 id="_3">电功率综述<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h3> <ol> <li>插座本身通电下就要浪费0.5W。(和预测相反)</li> <li>手机充电器一直插着是0W,以后再不怕浪费电了。(和预测相反)</li> <li>猜测刷了openwrt的路由可能比很多厂商路由省电。比起功能复杂的路由,我更偏向选择功耗低的。</li> <li>猫、机顶盒确实是耗电大户,电费隐形杀手。(符合预测)</li> <li>笔记本电脑功耗甚至比台式电脑的单个组成部分音箱还低,所以买电脑选择笔记本重要原因之一是省电。按台式机60W估算一年下来,省下的电费是很可观的。</li> </ol> <h3 id="_4">附上原始笔记<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h3> <p><img alt="家用电器功率记录原始笔记" src="//blog.pythonwood.com/uploads/2018/家用电器功率记录原始笔记.jpg" title="家用电器功率记录原始笔记"></p> <h3 id="_5">总结<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h3> <p>最近物联网、智能家居很火,有很多商家向消费者推销产品只重功能不重功耗。典型例子就是路由器做了很多不应该做的事情,路由器功能越丰富,就越费电。另外一个例子是智能插座,插座变成微型电脑,连接wifi以便于手机远程开断插头电源。本身这个idea就比较有争议,而且耗电大增,我不看好其发展。现在提倡环保,资源越来越紧张,希望在选购商品时,为环境多考虑一分。能节约用电的地方尽量节约。</p> <h3 id="_6">参考<a class="headerlink" href="#_6" title="Permanent link">&para;</a></h3>