Mar 17, 2017
Technologyntp server
Configure an ntp server in ubuntu16.04, IP address is 192.168.0.221
:
$ sudo apt-get install -y openntp
$ sudo vim /etc/ntp.conf
The reference configuration file is listed as following:
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
#
#server 127.127.1.0 minpoll 4
#fudge 127.127.1.0 stratum 1
#restrict 127.0.0.1
# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Needed for adding pool entries
restrict source notrap nomodify noquery
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
restrict 192.168.1.0 mask 0.0.0.0 nomodify notrap
Then restart the ntp service via:
$ sudo systemctl restart ntp
Note the ubuntu16.04 machine should be online(could reach Internet), after a while it will sync the
time from the internet.
Windows Configuration
See following image:
Mar 15, 2017
TechnologyBackground
Moving a friend’s wordpress blog from DigitalOcean to a new cheap vps, here
are all of the tips and steps.
MySQL Password recovery
I forget the mysql password, recover it via following ways(Ubuntu14.04
Version):
Stop the mysql instance via:
$ sudo /etc/init.d/mysql stop
Start the mysqld daemon process use --skip-grant-tables
options:
$ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
Mysql steps are listed as:
$ mysql -u root
> FLUSH PRIVILEGES;
> SET PASSWORD FOR root@'localhost' = PASSWORD('password');
> FLUSH PRIVILEGES;
> \q
Now better you reboot the machine, thus you could login to the mysql using the
newly changed passwd.
MySQL database backup
Backup the existing running mysql via following command:
$ mysqldump -uroot -pxxxxxx wordpress>Yourbackup.sql
This Yourbackup.sql
will be used later for restoring the database to the
newly created database instance.
Docker Compose
The docker compose file is listed as:
version: '2'
services:
wordpress:
image: wordpress
volumes:
- ./www:/var/www/html
ports:
- 8093:80
environment:
WORDPRESS_DB_PASSWORD: Myexample250
mysql:
image: mariadb
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: Myexample250
Up/Down the service via following command:
### Up the wordpress website:
$ sudo docker-compose up -d
### Down the wordpress
$ sudo docker-compose down
Now open your browser http://localhost:8093
, you will see the wordpress
installation page, install it:
The username/password would be any characters, because we will use our dumped
wordpress database for restoring it.
Restoring Database
Create a new maria docker instance for restoring the mysql:
$ mv Yourbackup.sql ./restore
$ sudo docker run -it -v `pwd`/restore:/var/lib/mysql --link mariadb:mymariadb --net lili_default mariadb:latest /bin/bash
Now get the running mariadb’s IP address:
$ sudo docker ps | grep mariadb
f1233de46f3b mariadb:latest "docker-entrypoint.sh" About a minute ago Up About a minute 3306/tcp amazing_jang
52df3ac6298d mariadb "docker-entrypoint.sh" 9 minutes ago Up 9 minutes 3306/tcp lili_mysql_1
$ sudo docker exec -it 52df3ac6298d /bin/bash
root@52df3ac6298d:/# ip addr
....
Get the ip address , we know it’s 172.19.0.3/16
.
Now in the root@f1233de46f3b
, do following commands:
# mysql -h172.19.0.3 -P3306 -uroot -pMyexample250
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.1.20-MariaDB-1~jessie mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q
Bye
root@f1233de46f3b:/#
If you get the mysql shell, it hints that you could run following commands for
restoring the database:
# mysql -u root -pMyexample250 --host=172.19.0.3 wordpress<Yourbackup.sql
Now you won’t get any article, because the old domain name is not compatible
for the new domain name, suppose our old domain name is www.oldname.com
, the
new domain name is localhost:8093`, do following command for adjust to the
new domain name:
Run:
mysql -h172.19.0.2 -P3306 -uroot -pMyexample250
use wordpress;
UPDATE wp_options SET option_value = replace(option_value, 'www.oldname.com','localhost:8093');
UPDATE wp_posts SET post_content = replace(post_content, 'www.oldname.com','localhost:8093');
UPDATE wp_comments SET comment_content = replace(comment_content, 'www.oldname.com','localhost:8093');
UPDATE wp_comments SET comment_author_url = replace(comment_author_url, 'www.oldname.com','localhost:8093');
\q
Now the database has been restored, you could restart the docker instance, and
examing the result, 52df3ac6298d 096fdeaac08a
are the id for wordpress and
mariadb.
$ sudo docker restart 52df3ac6298d 096fdeaac08a
Now reopen the browser,this time you will see the page has been adjusted to
old website:
Ubuntu Env Preparation
scp the whole directory to remote machine(Ubuntu16.04).
Install docker via:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
$ curl -fsSL <DOCKER-EE-URL>/gpg | sudo apt-key add -
$ sudo add-apt-repository \
"deb [arch=amd64] <-DOCKER-EE-URL> \
$(lsb_release -cs) \
stable-17.03"
$ sudo apt-get install docker-ce
Install docker-compose via:
$ sudo pip install docker-compose
$ sudo docker-compose up -d
Mar 14, 2017
Life无网络后的生活
前几天折腾我两年已久的长城宽带终于到期了,长城宽带是假宽带,根本达不到宣称
的速度,一句话便宜无好货啊,好在它终于到期,我也终于可以不用再受丫的气了。
停机前长城宽带的人无数次电话骚扰了我,均被一一碾回。珍爱生命,远离垃圾宽带。
于是我过回了一种曾经很熟悉的无网络生活。
回想一下,在有网络的时候,我的业余生活是怎样度过的呢?中午时分我回到家里的时候,
吃点东西后就会躺在床上,然后顺手打开手机,刷几下微博或者看看朋友圈,再看看微信
里的消息,好了,1点到了,开始睡,然而,效果并不好。
或者,下班回家后,往电脑前一坐,驾上梯子,开始浏览推特或者刷墙外楼上的新闻,那些
新闻也许很有意思,所以不知不觉,一个晚上就这样过去了…………
而在没有了网络的家里,我再也找不到WIFI的标记。随手刷几下便是浪费我宝贵的流量。尽管
我有着1块钱800M的无敌电信卡,然而那毕竟是要通过开热点才能打开的功能。这个门槛
的设置
让网络不再触手可及,因而不知不觉之间,微博/朋友圈/微信等等那些可能谋杀生命的东西因为
门槛的设置被挡在了外面。
于是如今中午的生活我是这样的:
回家后,吃点东西,躺下,开始翻某本小说,或者过我前段时间买回来的技术类/语言类书籍。
到1点的时候,放开书本,哇,绝对的好梦。
其实也不用担心在离线的时候无法提升技能,这世界上有的是离线教程,或者书籍,似乎我离开
那种对着书本敲入代码运行的年代已经很远。有时候我想着,互联网的便利,似乎让我们失去了
长久以来养成的良好的学习习惯,我们不再依赖于技术文档而完成研发,我们似乎只是动用着搜索引擎
在网上找着现成的答案。我们似乎变成了临场考试时随手打小抄的学生,而不是平时认真积累凭借
自己的深入理解认真答题的学霸。
中午回家的时候在楼道里看到电信1000块钱两年的宽带,实在是实惠,小小动心。然而反思断网
后的自由,我深感断开网络后所获得的岂止是全身心的自由?
没有网络的家里,带来的是一种失去已久的我曾经很熟悉的求学求知模式。眼下看来,我打算延续这种难得的自由, 继续
无WIFI生存。。
有时我们费心所追求的东西,正是
把我们身心自由束缚上的那一道金制的枷锁。
无网络后的知识提升
1、 更多的依赖于纸质资料,凭借对问题的领悟找寻解决方案。
2、 利用公司网络下载学习资料和搭建开发环境,用自己的笔记本上班,以便同步工作。
3、 1块钱800M的电信卡,不到万不得已的时候不开作弊模式。
4、 破解邻居WIFI,你懂得。
5、 实在不行就装回来1000块钱两年的真电信宽带吧。
说实话,我也有点好奇这样下去我能挺多久?
Mar 9, 2017
Technology最近扫了扫一本知名书《程序员面试宝典》。众所周知国内的面试都得要靠扫书来的嘛。
然而这本书上的有些习题,答案也未必为对,这里列举一个:
CPU架构导致的sizeof
原题目如下:
#include <stdio.h>
#include <stdlib.h>
struct {
short a1;
short a2;
short a3;
}A;
struct {
long a1;
short a2;
}B;
int main(void)
{
char *ss1= "0123456789";
char ss2[]= "0123456789";
char ss3[100] = "0123456789";
int ss4[100];
char q1[]="abc";
char q2[]="a\n";
char *str1= (char*)malloc(100);
void *str2= (void*)malloc(100);
printf("Sizeof ss1 is %d\n", sizeof(ss1));
printf("Sizeof ss2 is %d\n", sizeof(ss2));
printf("Sizeof ss3 is %d\n", sizeof(ss3));
printf("Sizeof ss4 is %d\n", sizeof(ss4));
printf("Sizeof q1 is %d\n", sizeof(q1));
printf("Sizeof q2 is %d\n", sizeof(q2));
printf("Sizeof str1 is %d\n", sizeof(str1));
printf("Sizeof str2 is %d\n", sizeof(str2));
printf("Sizeof A is %d\n", sizeof(A));
printf("Sizeof B is %d\n", sizeof(B));
return 0;
}
在我的机器上的答案是:
Sizeof ss1 is 8
Sizeof ss2 is 11
Sizeof ss3 is 100
Sizeof ss4 is 400
Sizeof q1 is 4
Sizeof q2 is 3
Sizeof str1 is 8
Sizeof str2 is 8
Sizeof A is 6
Sizeof B is 16
而原文答案则有差距,例如ss1的大小为4, str/str2的结果为4, B的大小为8.
为什么?
我猜想是因为CPU架构的不同,64位系统与32位系统的不同而导致。
为了验证,我创建了一台virtualbox的32位Ubuntu16.04的机器, 验证结果:
root@ubuntu:~# uname -a
Linux ubuntu 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:06:14 UTC 2016 i686 i686 i686 GNU/Linux
root@ubuntu:~# ./test
Sizeof ss1 is 4
Sizeof ss2 is 11
Sizeof ss3 is 100
Sizeof ss4 is 400
Sizeof q1 is 4
Sizeof q2 is 3
Sizeof str1 is 4
Sizeof str2 is 4
Sizeof A is 6
Sizeof B is 8
由此可见,其答案局限于32位平台,不能单纯的盲从于参考答案。
sizeof(string)变化
例子:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string strArr1[] = {"Trend", "Micro", "Soft"};
string *pStrArr1 = new string[2];
pStrArr1[0] = "US";
pStrArr1[1] = "CN";
for(int i = 0; i<sizeof(strArr1)/sizeof(string); i++)
cout<<strArr1[i];
for(int j = 0; j<sizeof(pStrArr1)/sizeof(string); j++)
cout<<pStrArr1[j];
cout<<endl;
cout<<sizeof(pStrArr1)<<endl;
cout<<sizeof(string)<<endl;
return 0;
}
实际的输出应该为:
TrendMicroSoft
8
32
这是因为库函数发生了变化,sizeof(string)的大小已经调整为32, 因而书里说的TrendMicroSoftUS是永远不会打印出来的。
Mar 8, 2017
TechnologyQuestion
What is ES6? ES6的语法?
What is MVVM框架?
Tips
介绍
Website: cn.vuejs.org
三种组建组合到一个vue文件里:
.vue
是 vue.js中特有的一种文件,在打包中会被打包成浏览器可理解的html.
开发环境建立
Ubuntu为例:
$ sudo apt-get install -y npm
$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
$ sudo cnpm install -g vue-cli
$ vue init webpack my-project
$ cd my-project
$ cnpm install
前端项目的依赖很多,所以需要用cnpm install所有依赖
-g 代表安装到系统目录下
Understanding Code
First example.
### Html
<div id="demo">
<p>{{ message }}</p> //常用的模板渲染的方式, 此message对应的是
// 新建的Vue对象里的data里的mesage字段
<input v-model="message"> //
Vue.js指令,将message字段关联到input的value里
</div>
### JS
var demo = new Vue({
el: "#demo", // element is demo
data: {
message: 'Hello Vue.js!''
}
})
两者相加可以得到一个页面渲染, 双向绑定的一个实例。
双向绑定:在页面上进行的输入会绑定到JS输入里的message, Js
Message的变动会体现在调用message页面部分里,这就是所谓双向绑定。
重要选项
Vue的所有数据都是放在data里头的,data也是一个对象:
new Vue({
data: {
a: 1,
b: []
},
methods: {
doSomething: function() {
this.a ++
console.log(this.a)
}
},
watch: {
'a': function(val, oldVal) {
console.log(val, oldVal)
}
}
})
this.a, this.b也可以取得
methods: vue的方法
<p>{{ a }}</p>
watch字面上理解就是一个监听,监听了a, 数据里的a, a对应的是一个方法,监听所有a
的变化,doSomething()方法执行的结果。
模版指令
数据渲染: v-text, v-html, {{}}
<p>{{ a }}</p>
<p v-text="a"></p>
<p v-html="a"></p>
对应到Vue的data里的a
控制模板隐藏: v-if, v-show
<p v-if="isShow"></p>
<p v-show="isShow"></p>
new Vue({
data: {
isShow; true
}
})
差别在于v-if是直接不显示元素,而v-show则是根据css的displayline来对它进行隐藏。代码中可以看到dom元素的
渲染循环列表: v-for:
<ul>
<li v-for='item in items'>
<p v-text='item.label'></p>
</li>
</ul>
data: {
items: [
{
label: 'apple'
},
{
label: 'banana'
}
]
},
第一行是apple, 第二行是banana.
事件绑定v-on:
<button v-on:click="doThis"></button>
<button @click="doThis"></button> // 简写指令
methods: {
dothis: function (someThing) {
}
}
doThis是methods里的东西,而不是从data里取东西了,data针对固定的数据来操作的。
属性绑定: v-bind:
<img v-bind:src="imageSrc">
<div :class="{ red: isRed }"></div>
<div :class="[classA, classB]"></div>
<div :class="[classA, {classB: isB, classC: isC }]"></div>
注意简写方式.
Webpack框架
import就是ES6的语法.