参考资料: http://www.cnblogs.com/meteoric_cry/archive/2012/03/31/2426256.html
tty on ubuntu
缘起
ubuntu下按下 CTRL+ALT+F12 为什么黑屏?
参考资料: http://askubuntu.com/questions/277517/what-does-ctrl-alt-f12-do
docker 学习
参考资料: http://bg.biedalian.com/2014/11/20/docker-start.html
docker 入门: https://www.jayway.com/2015/03/21/a-not-very-short-introduction-to-docker/
docker各种文档: https://docs.docker.com/
知识点:
1. ctrl+P, ctrl+Q 退出容器,但不关闭容器,如果直接ctrl+D 则容器就关闭了
关于磁盘分区的对齐问题
缘起
安装完ubuntu后,不想把 /home 和 系统放在同一分区上,于是,重装了一遍,做了三个分区: / 、 /home 、 /data ; 安装完成之后,执行了一下 sudo fdisk -l ,结果如下:
明知道这不是大问题,但是还是膈应
解决办法:
参考资料: http://www.ibm.com/developerworks/cn/linux/l-linux-on-4kb-sector-disks/
虽然gpart做分区时有“对齐到柱面”的选项,但是尝试多次,似乎还是不行; 最后,索性都创建成主分区,果然就不再出现这样的提示了
nsq学习
摘一幅图:
注意点:
- -broadcast-address:
这个选项在nsqd和nsqlookupd中都有出现,这个不仅仅是一个名字,更是外部连入的一个地址,所以不能错了,如:nsqd向nsqlookupd注册的就是这个,而consumer从nslookupd查询到的需要连接的nsqd的地址也是这个
12$ curl "http://10.79.80.245:4161/lookup?topic=test"{"status_code":200,"status_txt":"OK","data":{"channels":["c1"],"producers":[{"remote_address":"10.79.80.245:47975","hostname":"luna245","broadcast_address":"luna245","tcp_port":4150,"http_port":4151,"version":"0.2.30"},{"remote_address":"10.79.80.245:47976","hostname":"luna245","broadcast_address":"luna245","tcp_port":5150,"http_port":5151,"version":"0.2.30"}]}}
注意: 上面的broadcast_address 就是由于启动nsqd的时候没有指定该选项导致的,consumer如果不能解析该地址的话就不能获取到消息 - -worker-id:
nsqd 会根据worker-id来命名数据文件,即: nsqd.${worker_id}.dat
如: /data1/nsq_data/nsqd.1.dat
如果涉及到 topic和channel的话,不同的nsqd示例就不能(?)使用相同的data目录了,因为topic和channel的meta存储文件名中没有worker-id,如下:
/data1/nsq_data/test:c1.diskqueue.meta.dat
/data1/nsq_data/test.diskqueue.meta.dat由此,也可以看出,每个channel并没有一份重复的存储,应该 - nsqd存储
启动nsq相关的一堆命令太麻烦,写一个脚本来start、stop:
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 |
#!/usr/local/bin/php <?php $type = $argv[1]; $ip = "10.10.10.110"; $worker_id = 1; if ($type == "start") { myexec("nsqlookupd -http-address=\"0.0.0.0:4161\" -tcp-address=\"0.0.0.0:4160\" -broadcast-address=\"$ip\" "); foreach(array(4150, 5150) as $tcp_port) { $http_port = $tcp_port + 1; $data_dir = "/data1/nsq_data/$tcp_port"; if(!file_exists($data_dir)) { mkdir($data_dir); } myexec("nsqd -data-path=$data_dir -http-address=\"0.0.0.0:$http_port\" -tcp-address=\"0.0.0.0:$tcp_port\" -broadcast-address=\"$ip\" -worker-id=$worker_id -lookupd-tcp-address=$ip:4160"); $worker_id++; } myexec("nsqadmin -http-address=\"0.0.0.0:4171\" -lookupd-http-address=localhost:4161"); myexec("nsq_pubsub -lookupd-http-address=localhost:4161 -http-address=:8181"); } if ($type == "stop") { mykill("nsqlookupd"); mykill("nsqd"); mykill("nsqadmin"); mykill("nsq_pubsub"); } if ($type == "show") { mygrep("nsqlookupd"); mygrep("nsqd"); mygrep("nsqadmin"); mygrep("nsq_pubsub"); } function mygrep($name) { echo `ps aux|grep $name|grep -v grep`; } function mykill($name) { system("ps aux|grep $name|grep -v grep | awk '{print $2}'|xargs -n 1 kill -9"); } function myexec($cmd) { $arr = explode(" ", $cmd); $name = $arr[0]; $pid = pcntl_fork(); if ($pid == 0) { system("nohup $cmd >$name.log 2>&1 &", $ret); if ($ret != 0) { die("exec cmd fail: $cmd\n"); } } } |
AWS
apicloud.com 是个有意思的东西
BaaS已有多家
http://baike.baidu.com/view/8488783.htm
BaaS服务的定义、发展以及未来
http://www.infoq.com/cn/articles/the-definition-development-and-future-of-baas-services
*aaS 系列
SaaS: 软件即服务
PaaS:平台即服务
IaaS: 基础设施即服务
BaaS: 后端即服务
REST-API 设计
学习API的设计是系统设计的重要部分。
学习一下twitter的开发文档、facebook的开发文档
https://developers.facebook.com/
https://apigee.com/console 方便你调试一大堆的API, See:
GAE vs GCE
App Engine is a Platform-as-a-Service. It means that you simply deploy your code, and the platform does everything else for you. For example, if you app becomes very successful, App Engine will automatically create more instances to handle the increased volume.
Compute Engine is an Infrastructure-as-a-Service. You have to create and configure your own instances. It gives you more flexibility and generally costs much less than App Engine. The drawback is that you have to manage your deployment yourself.
Read more about Compute Engine
You can mix both App Engine and Compute Engine, if necessary. They both work well with the other parts of the Google Cloud Platform.
To put it simply: compute engine gives you a server which you have full control/responsibility for. You have direct access to the operating system, and you install all the software that you want, which is usually a web server, database, etc…
In app engine you don’t manage the operating system of any of the underlying software. You only upload code (Java, PHP, Python, or Go) and voila – it just runs…
App engine saves tons of headache, especially for inexperienced people but it has 2 significant drawbacks: 1. more expensive (but it does have a free quota which compute engine doesn’t) 2. you have less control, thus certain things are just not possible, or only possible in one specific way (for example saving and writing files).
Basic difference is that Google App Engine (GAE) is a Platform as a Service (PaaS) whereas Google Compute Engine (GCE) is an Infrastructure as a Service (IaaS).
To run your application in GAE you just need to write your code and deploy it into GAE, no other headache. Since GAE is fully sclable, it will automatically acquire more instances in case the traffic goes higher and decrease the instances when traffic decreases. You will be charged for the resources you really use, I mean, the Instance-Hours, Transferred Data, Storage etc. But the restriction is, you can create your application in only Python, PHP, Java and Go
On the other hand, GCE provides you full infrastructure in the form of Virtual Machine. You can write or install any program in GAE virtual machine. Actually GAE is the way to use Google Data Centers virtually. In GAE you have to manually configure your infrastructure to handle scalability by usingLoad Balancer.
google-cloud 探索
google-cloud: https://cloud.google.com
docs: https://cloud.google.com/docs/
gcloud工具: https://cloud.google.com/sdk/gcloud/
What is the difference between Google App Engine and Google Compute Engine? http://stackoverflow.com/questions/22697049/what-is-the-difference-between-google-app-engine-and-google-compute-engine
GCE- faq: https://cloud.google.com/compute/docs/faq
开发者控制台帮助文档: https://developers.google.com/console/help/new (先看看这个会为后续使用节省不少时间)
可能遇到的问题
- 无法访问: 请设置代理; 当执行: gcloud auth login 时,不设置代理可能会不行
- 执行完
GoogleCloudSDKInstaller.exe 后,似乎还是没有gcloud命令,需要手动执行 Google\Cloud SDK\google-cloud-sdk\install.bat
学习进度:
- 2015-02-03 : 部署了一个gitlab到 git.phpor.net
- 查看运行的实例:
- 修改默认的project,这样的话后续就不总需要使用 –project 选项了
- 添加ssh-key 为了方便ssh; 注意: 这里的登录名和google账户没有关系
可以通过web页面直接添加: https://cloud.google.com/compute/docs/console#sshkeys - 关于: C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\goapp.bat
- appengine 文档中的application 其实就是 project,曾经叫 application,现在叫 project
- 配置app.yaml 时写的是project id,如:
- 上传完通过: https://appengine.google.com/ 来访问部署好的project显得更加直观和方便,新的console中一定也能方便使用,只是还不太熟悉:
- C:\Program Files\Google\Cloud SDK\google-cloud-sdk\bin\appcfg.py 在windows上访问起来总不那么方便,于是在旁边添加了一个 appcfg.cmd , 从goapp.cmd 修改过来的,如下(注意: CLOUDSDK_ROOT_DIR 我给写死了):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051@echo offrem Copyright 2013 Google Inc. All Rights Reserved.SETLOCALrem <cloud-sdk-cmd-preamble>remrem CLOUDSDK_ROOT_DIR (a) installation root dirrem CLOUDSDK_PYTHON (u) python interpreter pathrem CLOUDSDK_PYTHON_ARGS (u) python interpreter argumentsrem CLOUDSDK_PYTHON_SITEPACKAGES (u) use python site packagesremrem (a) always defined by the preamblerem (u) user definition overrides preambleSET CLOUDSDK_ROOT_DIR=c:\progra~1\google\Clouds~1\google-cloud-sdkSET PATH=%CLOUDSDK_ROOT_DIR%\bin\sdk;%PATH%IF "%CLOUDSDK_PYTHON%"=="" (SET CLOUDSDK_PYTHON=python.exe)IF "%CLOUDSDK_PYTHON_SITEPACKAGES%" == "" (IF "%VIRTUAL_ENV%" == "" (SET CLOUDSDK_PYTHON_SITEPACKAGES=) ELSE (SET CLOUDSDK_PYTHON_SITEPACKAGES=1))IF "%CLOUDSDK_PYTHON_SITEPACKAGES%" == "" (IF "%CLOUDSDK_PYTHON_ARGS%" == "" (SET CLOUDSDK_PYTHON_ARGS=-S) ELSE (SET CLOUDSDK_PYTHON_ARGS=%CLOUDSDK_PYTHON_ARGS:-S=% -S)) ELSE IF "%CLOUDSDK_PYTHON_ARGS%" == "" (SET CLOUDSDK_PYTHON_ARGS=) ELSE (SET CLOUDSDK_PYTHON_ARGS=%CLOUDSDK_PYTHON_ARGS:-S=%)rem </cloud-sdk-cmd-preamble>%COMSPEC% /C "%CLOUDSDK_PYTHON% %CLOUDSDK_ROOT_DIR%\bin\appcfg.py %*"ENDLOCAL%COMSPEC% /C exit %ERRORLEVEL%
- go的开发、部署和php差别有些多,需要看文档哦
- go开发、部署:
goapp serve dir_of_app
goapp deploy dir_of_app - php开发、部署:
appcfg update dir_of_app
下载曾经部署过的代码: appcfg.py download_app -A root-micron-847 myphp (注意: -A 后面的project id 不能写成title哦)