博文

目前显示的是 三月, 2013的博文

Understand the SSH key (Z)

我们知道使用ssh的keygen来创建private 和 public key, 之后通过拷贝public key到指定的host,之后当我们需要从创建key的主机上登录指定的host时我们就可以不再需要输入password了。步骤如下: 首先在source machine(可以是local machine, 也可以是已经远程等率或者ssh到的machine)执行: ssh-keygen -t rsa 这样在用户目录下的.ssh folder 就会创建这么几个文件: id_rsa 里面有刚刚产生的private key id_rsa.pub 里面有用来copy到其他host的public key 然后我们执行: ssh-copy-id remoteuser@hostmachine 或者 cat ./ssh/id_rsa.pub | ssh remoteuser@hostmachine "cat >> ~/.ssh/authorized_keys" 把刚刚产生的public key复制到target host. 执行时我们需要输入remote user在host machine的密码。 这样我们就建立了一个从source machine到target machine的秘密约定: local machine                                                                    remote machine user A's private key         ----------------------------       remote user B's ssh knows           ...

How to change only case of filename when using git on windows

1. If you need to rename a file and also change its content, do it in two steps: A. change its name B. modify its content 2. On non-FAT file system use following command: git mv -f name.java Name.java 3. On FAT system, follow these steps: A. rename name.java to something.java B. rename something.java to Name.java 4. There is a config parameter in git might help in case problem with case of filenames: git config core.ignorecase Use git config -l  to list config parameter and check core.ingorecase parameter setting

远程使用mysqldump以及正确理解ssh tunnel

在我的remote_server上安装有mysql服务,其使用3306端口。 使用mysqldump命令可以backup数据库到sql文件。比如: mysqldump -P 3310 -h 127.0.0.1 -u root -p database_name > dump_file.sql 这段命令的意思是,登陆到host(-h)127.0.0.1(本地?没错,通常我们使用mysqldump会登陆到远程mysql服务然后将备份文件dump到远程服务器。但是在这里,我们不想将文件放在远程服务器,我们想直接将文件传送回本地client。)并将mysqldump命令使用于127.0.0.1 的3310端口,进行数据的备份。 我们之所以可以这么做,是因为在执行这个命令之前我们使用了 ssh -f -L3310:localhost:3306 username@remote_server -N 这个命令来建立一个ssh 通道。这段命令的意思是,我从client来使用ssh建立到remot_server的连接,并且(-L)请将相对于remote_server来说的localhost以及localhost的3306端口映射到我client的3310端口。(-f 参数是要ssh连接后进入到后台,然后再client的命令行上就不会显示username@remote_server>) (-N 参数是说在ssh连接这时没有命令要执行了,即“只是用来forward port”) Aha, 这样当我们在client的3310端口上执行mysqldump命令时,我们就相当于在"相对于remote_server来说的localhost的3306端口", 其实就是remote_server的3306端口执行mysqldump命令。而且mysqldump会返回数据到client的3310端口。 这样我们就实现了直接将remote database的备份直接拷贝到client了。 关于更多ssh tunnel的讨论见: http://chamibuddhika.wordpress.com/2012/03/21/ssh-tunnelling-explained

在本地服务器测试你的Google Analytics设置

Google Analytics 允许你自定义你的tracking code。 如果你在你的本地服务器localhost上测试GA你会发现你的tracking event 没有被发送到Google。那么如何在你的设置发布到Production服务器之前测试你的GA设置呢? 最简单的办法莫过于增加以下代码到你的tracking代码: var _gaq = _gaq || [ ] ; _gaq. push ( [ "_setAccount" , "UA-1234-1" ] ) ; _gaq. push ( [ "_setDomainName" , "none" ] ) ; _gaq. push ( [ "_trackPageview" ] ) ; 其中关键的部分在第三行  _gaq. push ( [ "_setDomainName" , "none" ] ) ; 这样你就会发现tracking request被发送到google了。  需要注意的是在第一次设置好后GA通常需要大约24小时来接受你的数据。不过你可以使用real-time tracking 来确认你的GA设置在localhost上是正确的。