1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
1 2 3 4 5 6 7 8 |
|
有了PID文件和pid之后,对应用的起停就可以使用这个PID来实现,以下是服务启停的脚本参考
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 |
|
1
|
|
1 2 3 4 5 6 7 |
|
1
|
|
1 2 3 |
|
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 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
利用walk还可以做很多其他的事情,例如对所有python源代码进行编译,以便发布打包的时候使用遍以后的二进制文件,而不是源代码。 可以使用如下代码:
1
|
|
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 |
|
linecount_1 43119
linecount_2 43119
linecount_3 43119
0.04646344717
0.0403758019525
0.0126613857348
]]>在Linux操作系统中,有一个系统软件包,它的功能类似于Windows里面的“添加/删除程序”,但是功能又比“添加/删除程序”强很多,它就是Red Hat Package Manager(简称RPM)。此工具包最先是由Red Hat公司推出的,后来被其他Linux开发商所借用。由于它为Linux使用者省去了很多时间,所以被广泛应用于在Linux下安装、删除软件。下面就给大家介绍一下它的具体使用方法。
1.我们得到一个新软件,在安装之前,一般都要先查看一下这个软件包里有什么内容,假设这个文件是:Linux-1.4-6.i368.rpm,我们可以用这条命令查看:
rpm -qpi Linux-1.4-6.i368.rpm
系统将会列出这个软件包的详细资料,包括含有多少个文件、各文件名称、文件大小、创建时间、编译日期等信息。
2.上面列出的所有文件在安装时不一定全部安装,就像Windows下程序的安装方式分为典型、完全、自定义一样,Linux也会让你选择安装方式,此时我们可以用下面这条命令查看软件包将会在系统里安装哪些部分,以方便我们的选择:
rpm -qpl Linux-1.4-6.i368.rpm
3.选择安装方式后,开始安装。我们可以用rpm-ivh Linux-1.4-6.i368.rpm命令安装此软件。在安装过程中,若系统提示此软件已安装过或因其他原因无法继续安装,但若我们确实想执行安装命令,可以在 -ivh后加一参数“-replacepkgs”:
rpm -ivh -replacepkgs Linux-1.4-6.i368.rpm
4.有时我们卸载某个安装过的软件,只需执行rpm-e <文件名>命令即可。
5.对低版本软件进行升级是提高其功能的好办法,这样可以省去我们卸载后再安装新软件的麻烦,要升级某个软件,只须执行如下命令:rpm -uvh <文件名>,注意:此时的文件名必须是要升级软件的升级补丁
6.另外一个安装软件的方法可谓是Linux的独到之处,同时也是RMP强大功能的一个表现:通过FTP站点直接在线安装软件。当找到含有你所需软件的站点并与此网站连接后,执行下面的命令即可实现在线安装,譬如在线安装Linux-1.4-6.i368.rpm,可以用命令:
rpm -i ftp://ftp.pht.com/pub/linux/redhat/…-1.4-6.i368.rpm
7.在我们使用电脑过程中,难免会有误操作,若我们误删了几个文件而影响了系统的性能时,怎样查找到底少了哪些文件呢?RPM软件包提供了一个查找损坏文件的功能,执行此命令:rpm -Va即可,Linux将为你列出所有损坏的文件。你可以通过Linux的安装光盘进行修复。
8.Linux系统中文件繁多,在使用过程中,难免会碰到我们不认识的文件,在Windows下我们可以用“开始/查找”菜单快速判断某个文件属于哪个文件夹,在Linux中,下面这条命令行可以帮助我们快速判定某个文件属于哪个软件包:
rpm -qf <文件名>
9.当每个软件包安装在Linux系统后,安装文件都会到RPM数据库中“报到”,所以,我们要查询某个已安装软件的属性时,只需到此数据库中查找即可。注意:此时的查询命令不同于1和8介绍的查询,这种方法只适用于已安装过的软件包!命令格式:
rpm -参数 <文件名>
]]>1
|
|
将以下内容写到该脚本中
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 |
|
1
|
|
1 2 |
|
1
|
|
修改 /usr/local/webserver/nginx/conf/nginx.conf 配置文件后,请执行以下命令检查配置文件是否正确:
1 2 |
|
1
|
|
将以下内容写到该脚本中
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 |
|
1
|
|
1 2 |
|
1
|
|
我的环境:RHEL6,python2.6.6,Nginx1.2.6,uWsgi1.4.4(都是从官方网站下载的最新版本)
先更新系统,并安装编译环境等等。
1 2 3 4 |
|
先到Nginx官网下载最新稳定版本的Nginx1.2.6,编译安装
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 |
|
更多的编译选项参考:http://wiki.nginx.org/NginxInstallOptions
1 2 |
|
1
|
|
1 2 |
|
进入uWsgi的官方网站,下载它的当前稳定版本,我这里下载的是1.4.4版本。
1 2 3 4 5 6 7 8 |
|
详细配置方式可以参考官网上的配置说明:http://projects.unbit.it/uwsgi/wiki/Quickstart 我以项目中的两个模块配置文件示例如下(web模块和api模块,分别走两个不同的端口)
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 |
|
简化的nginx.conf文件,增加一条include内容,见最后一行
1 2 3 4 5 6 7 8 9 10 11 12 |
|
然后在/etc/nginx/sites-enabled目录中增加单个的server配置内容,参考如下
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
重启服务后,通过http://localhost即可访问项目主页了,web的请求会直接转发给8081端口,而http://localhost/api的请求则会转发到8080端口
至此,我们的配置完成了,可以参考下一篇文章,将nginx和uwsgi配置为系统服务,并开机自动启动
]]>Run the last command as root
Useful when you forget to use sudo for a command. “!!” grabs the last run command.
Serve current directory tree at http://localhost:8000/
Save a file you edited in vim without the needed permissions
I often forget to sudo before editing a file I don’t have write permissions on. When you come to save that file and get the infamous “E212: Can’t open file for writing”, just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.
change to the previous working directory
Runs previous command but replacing
Really useful for when you have a typo in a previous command. Also, arguments default to empty so if you accidentally run:
1
|
|
you can correct it with
1
|
|
mtr, better than traceroute and ping combined
mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool. As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over?loaded) link.
Rapidly invoke an editor to write a long, complex, or tricky command
Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you’ve written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.
Execute a command without saving it in the history
Prepending one or more spaces to your command won’t be saved in history. Useful for pr0n or passwords on the commandline. Tested on BASH.
Empty a file
For when you want to flush all content from a file without removing it (hat-tip to Marc Kilgus).
Copy ssh keys to user@host to enable password-less ssh logins.
Salvage a borked terminal
If you bork your terminal by sending binary data to STDOUT or similar, you can get your terminal back using this command rather than killing and restarting the session. Note that you often won’t be able to see the characters as you type them.
Capture video of a linux desktop
Place the argument of the most recent command on the shell
When typing out long arguments, such as:
1
|
|
You can put that argument on your command line by holding down the ALT key and pressing the period ‘.’ or by pressing
1
|
|
would put ‘/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing ‘ALT+.’ to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.
currently mounted filesystems in nice layout
Particularly useful if you’re mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting.
start a tunnel from some machine’s port 80 to your local post 2001
now you can acces the website by going to http://localhost:2001/
Execute a command at a given time
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.
Query Wikipedia via console over DNS
Query Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.You can also write a little shell script like:
1 2 3 |
|
and run it like
1
|
|
were your first option ($1) will be used as search term.
Lists all listening ports together with the PID of the associated process
The PID will only be printed if you’re holding a root equivalent ID.
output your microphone to a remote computer’s speaker
This will output the sound from your microphone port to the ssh target computer’s speaker port. The sound quality is very bad, so you will hear a lot of hissing.
Update twitter via curl
Runs previous command replacing foo by bar every time that foo appears
Very useful for rerunning a long command changing some arguments globally. As opposed to ^foo ^bar, which only replaces the first occurrence of foo, this one changes every occurrence.
Mount a temporary ram partition
Makes a partition in ram which is useful if you need a temporary working space as read/write access is fast.
Be aware that anything saved in this partition will be gone after your computer is turned off.
Quick access to the ascii table.
Mount folder/filesystem through SSH
Install SSHFS from http://fuse.sourceforge.net/sshfs.html
Will allow you to mount a folder security over a network.
Get your external IP address
curl ifconfig.me/ip -> IP Adress
curl ifconfig.me/host -> Remote Host
curl ifconfig.me/ua ->User Agent
curl ifconfig.me/port -> Port
curl ifconfig.me/all -> All
thanks to ifconfig.me
]]>创建本地分支
切换分支到sager-profile
切换分支回master
推送本地分支sager-profile到远程
查看本地分支
查看远程分支
删除本地分支
删除远程分支,语法同推送分支到远程, 只是将一个空分支推送到远程指定分支,也就是删掉远程分支
如果上面的语句执行失败,可以使用这个删除远程分支
]]>将当前的修改保存在暂存堆栈
将最新暂存堆栈的内容恢复到工作区
将指定序号的暂存堆栈的内容恢复到工作区
查看当前暂存堆栈中有哪些内容
清空暂存堆栈的内容
]]>于是我就马不停蹄地下载了Dropbox的安装包然后装到Ubuntu上,装完一打开,弹出这么个提示:“Trouble connecting to Dropbox server.Maybe your internet connection is down,or you need to set your http_proxy environment variable”,主要意思就说无法连接上dropbox的服务器。
然后我把hosts改了,问题依旧…,只有祭出google大神了
原来装了那个deb包还不算装完,第一次启动时还要下载一个.tar.gz的包,明显这个包的地址在墙外了。
所以需要到这个地址 http://www.getdropbox.com/download?plat=lnx.x86 下载这个.tar.gz包,当然要先爬墙。(我把这个文件传到了华为网盘 http://dl.vmall.com/c0sgq6m4m6 ,无法爬墙的同学如果信得过我的话可以下载)
然后在下载到的dropbox-lnx.x86-1.2.52.tar.gz文件解压到主文件夹,是个隐藏文件夹.dropbox-dist, 按“Ctrl + h”显示隐藏文件
最后打开dropbox即可正常使用啦~
]]>由于测试需要搭建局域网环境,需要两台虚拟机同时运行。当我安装完一个虚拟系统时,我将虚拟磁盘文件复制一份重新创建虚拟系统时提示打开虚拟硬盘 windowsxp.vdi 失败。
Cannot register the hard disk 'windowsxp.vdi' with UUID {24eb969f-8c98-470d-b2dd-35318f2b8860}
because a hard disk 'windowsxp.vdi' with UUID {24eb969f-8c98-470d-b2dd-35318f2b8860} already exists
in the media registry ('/home/sager/VirtualBox VMs/windowsxp/windowsxp.vid').
往Google里找寻了一番,原来Virtualbox也是有VBoxManage命令的,于是我决定给复制的vdi文件重新分配uuid。
1 2 |
|
接着就可以使用拷贝的vdi文件正常的创建第二台虚拟机了。
当然如果你没有直接复制vdi文件,那么直接用Virtualbox自带的克隆vdi文件命令。
1
|
|
Virualbox的快照功能非常不错,可以即时恢复到快照时的状态,做试验就不用重新配环境了。
]]>例如我们有账号a和账号b,对应的ssh key文件分别是id_rsa_a和id_rsa_b,首先修改/etc/hosts文件,设置两个本地域名指向github.com
1 2 |
|
修改用户的ssh配置文件~/.ssh/config,示例如下:
1 2 3 4 5 6 7 8 9 10 |
|
然后在你的git仓库的远程地址中,将对应的a.github.com和b.github.com替换原来的github.com,参考下面的变化:
1
|
|
进入到Fedora 16的安装引导界面,按TAB键,在后面追加数字3,Enter,
然后系统引导,弹出一个登录,使用root直接登录即可。
2.运行如下命令
/usr/sbin/anaconda –liveinst –method=livecd:///dev/mapper/live-osimg-min
然后提示完成安装即可。
3.最后需要修改一个默认启动到文本界面
cd /etc/systemd/system
ln -s /lib/systemd/system/multi-user.target default.target
4.参考
http://www.linuxreaders.com/2010/09/08/install-fedora-from-live-cd-cli/#.T1YF74da6G4
]]>按从小到大的顺序显示根目录下除proc目录以外的所有文件及目录大小(须在根目录下执行该命令)
2、dpkg -l |grep ^rc |awk ‘{print $2}’ |xargs dpkg –purge
删除已删除包的残留配置文件(Debian分支)
3、find . -type f -print |xargs du -sb |sort -h
查找当下目录及其子目录下面的所有文件,并按文件大小,由小到大排序
]]>1 2 3 4 5 |
|
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 |
|
We made 1 million dollars this year
rake new_post[“My New Post”]
edit my-new-post.markdown with text editor
jekyll markup
1 2 3 |
|
1 2 3 |
|
Bacon ipsum dolor sit amet exercitation ball tip consectetur tempor. Biltong exercitation aliqua, ribeye consequat veniam consectetur.
Aliquip nulla do tempor, ball tip dolore anim esse strip steak nisi nostrud. Tri-tip mollit deserunt ut duis, commodo brisket short loin est hamburger sunt consequat rump meatloaf. Exercitation enim aliqua tempor dolore. Non eu venison, officia boudin tri-tip enim beef ribs flank cupidatat in aute. Tail voluptate fugiat aute flank, venison sint.
Brisket quis velit bresaola. Pork loin pork chop beef duis. Short loin fugiat officia short ribs magna. Ullamco eu proident jerky, fugiat chuck nostrud ham rump meatloaf eiusmod adipisicing. Qui et reprehenderit, magna biltong consequat short ribs pancetta. Tail tenderloin sausage, hamburger corned beef drumstick ad. Eu labore enim velit.
Filler text courtesy of Bacon Ipsum, Images courtesy of Place Kitten.
Last night I lay in bed looking up at the stars in the sky and I thought to myself, where the heck is the ceiling.
那么一个极客眼中的博客应该具备哪些要素?
1. 基于文本的编辑
作为极客,你必须很在意 Vim, Emacs 之流,你应该鄙视一切在 Office,Web 里的文字工作,Office 之流很方便使用,但是实在没有什么效率。即便在我们这个行业里,很多人至今没有弄清楚方便不等于高效这个道理。所以我个人只认同使用 Vim 方式处理任何文本工作,包括代码和博客。
2. 方便的书写和阅读格式
假设你承认上述第一点的理念,那么我们还是在写博客,仍然需要格式化的文字使得文字本身在网络上更富表现力,方便读者阅读。但是 html 是一种很冗余的格式存在,既不方便书写也不方便对编辑的源码直接阅读。同时纯文本的格式又走上了另一个极端,书写和阅读基本没有任何代价,坏处在于纯文本几乎又没有任何表现力,除了可以分出段落,它不能粗体,不能斜体,不能更改字号,不能列表。所以结论是:我们需要一种介于 html 和纯文本之间的格式来书写博客,它有不那么大的书写和阅读的成本,又兼顾一定的文字表现力。答案就是 Markdown,再送一份红利就是在线的 Markdown Editor。
3. 灵活的备份和恢复
这是一条足以放弃 WordPress 的重要理由。我们无非是在码字而已,没有理由引入数据库,基于文本的保存是最安全的保存,它便于检索(grep),容易导入,导出,不依赖于任何第三方软件或者操作系统。几百年后,这篇文档仍然可以被那时的计算机打开,这很重要,好比我们今天仍然有机会看到前人的青铜器,但是我们的后人只能从图片上看看今天的各类一次性制品。如果要求更高一些,我们还希望有类似管理代码的方式来管理我们的博客,同样是文本,Version Control System 不应该是代码的专有权利。中央服务器也可以保证在任何地方,任何时候检出,更新,提交你的博客,并且也不妨碍除你以外的人这么做。
4. 基于命令行的操作方式
极客的重要特征是远离 Windows,所以我们甚至应该幻想一个 Windows 不友好的方式来写博客。它应该尽量基于命令行,在 Linux 系统上运行良好,羞啥那些 Windows 上的普通青年和 Mac 上的文艺青年,这不是说我很大度的表示我就是2B青年,只是我实在不愿意诸君承担2B青年的包袱,只好自己大度的承担罢了。
5. 支持代码片段的显示
偶尔想秀个小代码也是装2的内在诉求和外在表现之一,所以我们的博客应该是可以这样子的:
1 2 3 4 5 |
|
6. 最后的最后,不缩水的博客
好处不能都被你这个2B青年占完了不是吗?你要这个要那个,都满足你了,末了扔给你一个缩水的博客,你不由自主的和那些个不入你法眼的新浪博客,不讨巧的 WordPress 做比较了,于是你又开始不满意了。好吧,我们折中一下,RSS 导出不能少,分享到 Facebook,Twitter,甚至于新浪微博也不能落下,还要能访客留言,搜索过往,提示最近的博客,标注 tag。于是是除了你那些个蛋疼的特殊癖好,别人有的也全都要满足。。。
1. 真的没什么
2. 其实有意思的
Mou, the missing Markdown
editor for web developers
.
1 2 |
|
1 2 |
|
1 2 |
|
echo $SHELL
tar cvfz /home/sager/bakup/etc.tar.gz /etc/ *
]]>