Aug
24
:set formatoptions+=m "允许对multi_byte字符换行(否则默认只能空格或者英文标点,详见set breakat=)
:set textwidth=80 "换行的长度
ggVG "选中全文
gq "应用到选中文本
p.s. 最后两句也可以缩写成 gggpG (少一个字符)..
:set textwidth=80 "换行的长度
ggVG "选中全文
gq "应用到选中文本
p.s. 最后两句也可以缩写成 gggpG (少一个字符)..
Aug
17
对ssh用得比较多的同学应该知道通过建立信任关系来免除输入密码的麻烦:
在A机器上执行:
$ ssh-keygen -t rsa (各种回车)
$ ssh-copy-id -i ~/.ssh/id_rsa.pub USER@B_ip
然后在A机器上 ssh USER@B_ip 就可以免密码使用USER用户登录B机器了。
实际上第二步操作是将 A 机器该用户的公钥(id_rsa.pub)追加到B机器的 ~/.ssh/authorized_keys 文件末尾中去。
当A机器访问B时,如果B机器的sshd能够在/home/USER/.ssh/authorized_keys中找到对应的公钥,就认为A机器具有B机器的USER用户访问权限,于是就直接让A机器以USER身份登录。
但是上周在线上某台机器进行操作时却发现这一机制失效了。通过该机制,A=>B可登录,但是B=>A失败,甚至A=>A也失败(B=>B却成功)。虽然问题很奇怪,但说明问题出在A机器上。
首先是 diff 了A、B两台机器的 /etc/ssh ,发现完全相同,所以不是配置的问题。
然后查看 ssh -vv localhost
而在B机器上,we sent a public key packet, wait for reply 之后则是紧跟着"debug1: Server accepts key: pkalg ssh-rsa blen 279"。由此可以看出,是A机器的sshd不认可publickey。
至于为什么不认可,在google上查了许多,毫无头绪,直到使用类似“ssh publickey ignore debug diagnose”这样的关键词,发现这个页面,其中的第二条和第六条给出了解答:
通过执行 /usr/sbin/sshd -d -p 2222 (在2222端口启动一个带debug输出的sshd) ,然后 ssh -vv localhost -p 2222 ,可以看到sshd输出了一行
正好与那第六条相对应,再检查一下 /home/felix021 ,其权限是其他组可写。
最终解决方案:将用户home目录的权限改为0755,登录成功。
在A机器上执行:
$ ssh-keygen -t rsa (各种回车)
$ ssh-copy-id -i ~/.ssh/id_rsa.pub USER@B_ip
然后在A机器上 ssh USER@B_ip 就可以免密码使用USER用户登录B机器了。
实际上第二步操作是将 A 机器该用户的公钥(id_rsa.pub)追加到B机器的 ~/.ssh/authorized_keys 文件末尾中去。
当A机器访问B时,如果B机器的sshd能够在/home/USER/.ssh/authorized_keys中找到对应的公钥,就认为A机器具有B机器的USER用户访问权限,于是就直接让A机器以USER身份登录。
但是上周在线上某台机器进行操作时却发现这一机制失效了。通过该机制,A=>B可登录,但是B=>A失败,甚至A=>A也失败(B=>B却成功)。虽然问题很奇怪,但说明问题出在A机器上。
首先是 diff 了A、B两台机器的 /etc/ssh ,发现完全相同,所以不是配置的问题。
然后查看 ssh -vv localhost
引用
....
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/felix021/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/felix021/.ssh/id_dsa
debug1: Trying private key: /home/felix021/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/felix021/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/felix021/.ssh/id_dsa
debug1: Trying private key: /home/felix021/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
而在B机器上,we sent a public key packet, wait for reply 之后则是紧跟着"debug1: Server accepts key: pkalg ssh-rsa blen 279"。由此可以看出,是A机器的sshd不认可publickey。
至于为什么不认可,在google上查了许多,毫无头绪,直到使用类似“ssh publickey ignore debug diagnose”这样的关键词,发现这个页面,其中的第二条和第六条给出了解答:
引用
2. Debugging on the remote host by running sshd in debug mode: Run ‘/usr/sbin/sshd -d -p 2222′ on the remote host and connect to it. ’2222′ here is the port number of the sshd process you started on the remote host.
6. Check the permissions on your home directory, .ssh directory, and the authorized_keys file: If your ssh server is running with ‘StrictModes on’, it will refuse to use your public keys in the ~/.ssh/authorized_keys file. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600.
6. Check the permissions on your home directory, .ssh directory, and the authorized_keys file: If your ssh server is running with ‘StrictModes on’, it will refuse to use your public keys in the ~/.ssh/authorized_keys file. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600.
通过执行 /usr/sbin/sshd -d -p 2222 (在2222端口启动一个带debug输出的sshd) ,然后 ssh -vv localhost -p 2222 ,可以看到sshd输出了一行
引用
Authentication refused: bad ownership or modes for directory /home/felix021
正好与那第六条相对应,再检查一下 /home/felix021 ,其权限是其他组可写。
最终解决方案:将用户home目录的权限改为0755,登录成功。
Nov
5
不知道是支付宝的产品人员太牛比,还是开发人员太傻比,还是测试人员太装比呢。这尼玛玩用户啊?
Nov
2
$ tar zxf mysql-5.1.30.tar.gz
$ cd mysql-5.1.30
$ mkdir -p /home/fengmin/mysql
$ ./configure --prefix=/home/fengmin/mysql --with-plugins=all --with-pthread --with-charset=utf8 --with-extra-charsets=all
$ make -j4 &> make.log
$ make install
$ cd /home/fengmin/mysql
$ mkdir data
$ ./bin/mysql_install_db --datadir=/home/fengmin/mysql/data/
$ cp ./share/mysql/my-small.cnf my.cnf
$ vi my.cnf #修改各种配置
$ ./bin/mysqld_safe --defaults-file=/home/fengmin/mysql/my.cnf & #启动server
$ ./bin/mysqladmin -u root password 'newpassword' -h 127.0.0.1 -P 3306 #修改root密码
$ ./bin/mysql -h127.0.0.1 -P 3306 -u root -pnewpassword #连接mysql
$ ./bin/mysqladmin -h 127.0.0.1 -P 3306 -u root -pnewpassword shutdown #关闭server
$ cd mysql-5.1.30
$ mkdir -p /home/fengmin/mysql
$ ./configure --prefix=/home/fengmin/mysql --with-plugins=all --with-pthread --with-charset=utf8 --with-extra-charsets=all
$ make -j4 &> make.log
$ make install
$ cd /home/fengmin/mysql
$ mkdir data
$ ./bin/mysql_install_db --datadir=/home/fengmin/mysql/data/
$ cp ./share/mysql/my-small.cnf my.cnf
$ vi my.cnf #修改各种配置
$ ./bin/mysqld_safe --defaults-file=/home/fengmin/mysql/my.cnf & #启动server
$ ./bin/mysqladmin -u root password 'newpassword' -h 127.0.0.1 -P 3306 #修改root密码
$ ./bin/mysql -h127.0.0.1 -P 3306 -u root -pnewpassword #连接mysql
$ ./bin/mysqladmin -h 127.0.0.1 -P 3306 -u root -pnewpassword shutdown #关闭server
Oct
23
选项->设置->压缩->创建默认配置
[常规]
~压缩文件格式:
zip (方便分享,windows默认支持)
~压缩方式:
较好
[文件]
~ 要排除的文件:
*\Thumbs.db
~ 不压缩直接存储的文件
*.jpg *.jpeg *.png *.avi *.wmv *.rmvb *.rm *.gif *.mp4 *.mkv *.zip *.rar *.gz *.bz2 *.mp3 *.wma
[常规]
~压缩文件格式:
zip (方便分享,windows默认支持)
~压缩方式:
较好
[文件]
~ 要排除的文件:
*\Thumbs.db
~ 不压缩直接存储的文件
*.jpg *.jpeg *.png *.avi *.wmv *.rmvb *.rm *.gif *.mp4 *.mkv *.zip *.rar *.gz *.bz2 *.mp3 *.wma
Aug
24
rsync是个好东西,同步文件很方便,等啥时候有空了,可以考虑把内核提供的inotify功能结合起来,搞一个实时文件同步的应用 :D
回归主题,说说这个坑,线上的机器用rsync来进行文件的同步。
从昨天到今天这个问题一直出现,不管是2.6.8还是最新的3.0.8,看了N个使用例子,最后结果都是这样。Boluor同学的建议是配置信任关系(ssh-keygen -t rsa; ssh-copy-id user@remote_host),但是这样只是不需要输入密码,并没有解决问题。
于是RTFW,Google了一下,发现在 http://ss64.com/bash/rsync.html 的DIAGNOSTIC 一节有说明, .bashrc 等启动脚本的任何输出,都会影响rsync通过ssh同步时的数据流,导致协议不匹配。
以这个命令为例:
$ ssh user@remote_host /bin/true > out.txt
实际上所有的动作是
1. ssh 与 remote_host 的 sshd 交互
2. sshd fork出一个 user shell(一般是/bin/bash)
3. /bin/bash 载入 $USER/.bash_profile
4. .bash_profile一般会载入.bashrc
5. /bin/bash 执行/bin/true 并重定向stdin到out.txt
正常情况下,out.txt应该是一个空文件。如果在这个过程中有任何输出(比如我当时的.bashrc有一个echo),就会导致rsync在执行过程中的数据有额外的GARBAGE,出现问题。
OVER.
回归主题,说说这个坑,线上的机器用rsync来进行文件的同步。
$ rsync -az --delete /home/user/files/ user@remote_host:/home/user/files/
user@remote_host's password:
TERM environment variable not set.
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(174) [sender=3.0.8]
user@remote_host's password:
TERM environment variable not set.
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(174) [sender=3.0.8]
从昨天到今天这个问题一直出现,不管是2.6.8还是最新的3.0.8,看了N个使用例子,最后结果都是这样。Boluor同学的建议是配置信任关系(ssh-keygen -t rsa; ssh-copy-id user@remote_host),但是这样只是不需要输入密码,并没有解决问题。
于是RTFW,Google了一下,发现在 http://ss64.com/bash/rsync.html 的DIAGNOSTIC 一节有说明, .bashrc 等启动脚本的任何输出,都会影响rsync通过ssh同步时的数据流,导致协议不匹配。
以这个命令为例:
$ ssh user@remote_host /bin/true > out.txt
实际上所有的动作是
1. ssh 与 remote_host 的 sshd 交互
2. sshd fork出一个 user shell(一般是/bin/bash)
3. /bin/bash 载入 $USER/.bash_profile
4. .bash_profile一般会载入.bashrc
5. /bin/bash 执行/bin/true 并重定向stdin到out.txt
正常情况下,out.txt应该是一个空文件。如果在这个过程中有任何输出(比如我当时的.bashrc有一个echo),就会导致rsync在执行过程中的数据有额外的GARBAGE,出现问题。
OVER.
Jun
24
使用以下脚本来编译安装,需要把安装文件下载到 [ROOT]/src/ 下。
目录结构:
[ROOT]
/src
/php-5.2.17.tar.bz2
...
/httpd
/php
/fcgi-bin
目录结构:
[ROOT]
/src
/php-5.2.17.tar.bz2
...
/httpd
/php
/fcgi-bin
#!/bin/bash
set -x
ROOT="/home/felix021/lamp"
ROOT_E=${ROOT//\//\\\/} # escape for sed, / => \/
WWWROOT="/home/felix021/lamp/wwwroot"
WWWROOT_E=${WWWROOT//\//\\\/} # escape for sed, / => \/
HTTPD_PORT=80
FCGI_CHILDREN=4
FCGI_MAX_REQUESTS=1000
# 下载好的源码文件
fastcgi="mod_fastcgi-2.4.6" #.tar.gz
httpd="httpd-2.2.17" #.tar.bz2
php="php-5.2.17" #.tar.bz2
eaccelerator="eaccelerator-0.9.6.1" #.tar.bz2
SRCROOT=${ROOT}/src
mkdir -p $ROOT/{httpd,php,fcgi-bin}
mkdir -p $WWWROOT
# fcgi-bin (for apache + mod_fastcgi)
# 创建这个脚本可以用来包装php-cgi,可以控制启动的FCGI进程数量
if [ ! -e "${ROOT}/fcgi-bin/php.cgi" ]; then
> ${ROOT}/fcgi-bin/php.cgi echo "#!/bin/sh
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
### Set PATH ###
PHP_CGI=${ROOT}/php/bin/php-cgi
PHP_FCGI_CHILDREN=${FCGI_CHILDREN}
PHP_FCGI_MAX_REQUESTS=${FCGI_MAX_REQUESTS}
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec \$PHP_CGI
"
chmod +x ${ROOT}/fcgi-bin/php.cgi
fi
# php
cd $SRCROOT
if [ ! -d "${php}" ]; then
tar jxf ${php}.tar.bz2
cd $php
./configure --prefix=${ROOT}/php --with-gd --with-iconv \
--with-curl --enable-fastcgi --with-openssl --enable-mbstring #有需要的话自己再增加一些模块吧
echo Making... Please wait. "tail -f `pwd`/php.log" to view make output.
make -j4 &> php.log
make install
cp php.init-dist ${ROOT}/php/lib/php.ini
fi
# eaccelerator
if [ ! -d "${eaccelerator}" ]; then
tar jxf ${eaccelerator}.tar.bz2
cd $eaccelerator
export PHP_PREFIX=${ROOT}/php
$PHP_PREFIX/bin/phpize
./configure --enable-eaccelerator=shared \
--with-php-config=$PHP_PREFIX/bin/php-config
make -j4 &> eaccelerator.log
make install
echo Please edit php.ini to enable eaccelerator.so
fi
# httpd
cd $SRCROOT
if [ ! -d "${httpd}" ]; then
tar jxf ${httpd}.tar.bz2
cd ${httpd}
./configure --prefix=${ROOT}/httpd --enable-rewrite
echo Making... Please wait. "tail -f `pwd`/httpd.log" to view make output.
make -j4 &> httpd.log
make install
conf_path="${ROOT}/httpd/conf/httpd.conf"
# 下面这段sed脚本是把端口、DocRoot替换了,并允许目录下使用.htaccess来配置url rewrite
sed -i $conf_path \
-e "s/^Listen 80$/Listen ${HTTPD_PORT}/" \
-e "s/\/.*\/htdocs\>/${WWWROOT_E}/" \
-e "s/AllowOverride None/AllowOverride FileInfo/"
fcgi_path="${ROOT}/fcgi-bin/"
# 在配置中加入FastCgi相关的内容
echo "
LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiServer \"${fcgi_path}php.cgi\"
AddHandler php-fastcgi .php
ScriptAlias /fcgi-bin/ \"${fcgi_path}\"
Action php-fastcgi "/fcgi-bin/php.cgi"
AddType application/x-httpd-php .php
<Directory \"${fcgi_path}\">
SetHandler fastcgi-script
Options FollowSymlinks +ExecCGI
Order Allow,Deny
Allow from All
</Directory>
" >> $conf_path
fi
# mod_fastcgi for httpd
cd $SRCROOT
if [ ! -d "${fastcgi}" ]; then
tar zxf ${fastcgi}.tar.gz
cd ${fastcgi}
cp Makefile.AP2 Makefile
make top_dir=${ROOT}/httpd -j4 &> fastcgi.log
make top_dir=${ROOT}/httpd install
fi
echo Done. Please run "${ROOT}/httpd/bin/apachectl start"
set -x
ROOT="/home/felix021/lamp"
ROOT_E=${ROOT//\//\\\/} # escape for sed, / => \/
WWWROOT="/home/felix021/lamp/wwwroot"
WWWROOT_E=${WWWROOT//\//\\\/} # escape for sed, / => \/
HTTPD_PORT=80
FCGI_CHILDREN=4
FCGI_MAX_REQUESTS=1000
# 下载好的源码文件
fastcgi="mod_fastcgi-2.4.6" #.tar.gz
httpd="httpd-2.2.17" #.tar.bz2
php="php-5.2.17" #.tar.bz2
eaccelerator="eaccelerator-0.9.6.1" #.tar.bz2
SRCROOT=${ROOT}/src
mkdir -p $ROOT/{httpd,php,fcgi-bin}
mkdir -p $WWWROOT
# fcgi-bin (for apache + mod_fastcgi)
# 创建这个脚本可以用来包装php-cgi,可以控制启动的FCGI进程数量
if [ ! -e "${ROOT}/fcgi-bin/php.cgi" ]; then
> ${ROOT}/fcgi-bin/php.cgi echo "#!/bin/sh
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
### Set PATH ###
PHP_CGI=${ROOT}/php/bin/php-cgi
PHP_FCGI_CHILDREN=${FCGI_CHILDREN}
PHP_FCGI_MAX_REQUESTS=${FCGI_MAX_REQUESTS}
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec \$PHP_CGI
"
chmod +x ${ROOT}/fcgi-bin/php.cgi
fi
# php
cd $SRCROOT
if [ ! -d "${php}" ]; then
tar jxf ${php}.tar.bz2
cd $php
./configure --prefix=${ROOT}/php --with-gd --with-iconv \
--with-curl --enable-fastcgi --with-openssl --enable-mbstring #有需要的话自己再增加一些模块吧
echo Making... Please wait. "tail -f `pwd`/php.log" to view make output.
make -j4 &> php.log
make install
cp php.init-dist ${ROOT}/php/lib/php.ini
fi
# eaccelerator
if [ ! -d "${eaccelerator}" ]; then
tar jxf ${eaccelerator}.tar.bz2
cd $eaccelerator
export PHP_PREFIX=${ROOT}/php
$PHP_PREFIX/bin/phpize
./configure --enable-eaccelerator=shared \
--with-php-config=$PHP_PREFIX/bin/php-config
make -j4 &> eaccelerator.log
make install
echo Please edit php.ini to enable eaccelerator.so
fi
# httpd
cd $SRCROOT
if [ ! -d "${httpd}" ]; then
tar jxf ${httpd}.tar.bz2
cd ${httpd}
./configure --prefix=${ROOT}/httpd --enable-rewrite
echo Making... Please wait. "tail -f `pwd`/httpd.log" to view make output.
make -j4 &> httpd.log
make install
conf_path="${ROOT}/httpd/conf/httpd.conf"
# 下面这段sed脚本是把端口、DocRoot替换了,并允许目录下使用.htaccess来配置url rewrite
sed -i $conf_path \
-e "s/^Listen 80$/Listen ${HTTPD_PORT}/" \
-e "s/\/.*\/htdocs\>/${WWWROOT_E}/" \
-e "s/AllowOverride None/AllowOverride FileInfo/"
fcgi_path="${ROOT}/fcgi-bin/"
# 在配置中加入FastCgi相关的内容
echo "
LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiServer \"${fcgi_path}php.cgi\"
AddHandler php-fastcgi .php
ScriptAlias /fcgi-bin/ \"${fcgi_path}\"
Action php-fastcgi "/fcgi-bin/php.cgi"
AddType application/x-httpd-php .php
<Directory \"${fcgi_path}\">
SetHandler fastcgi-script
Options FollowSymlinks +ExecCGI
Order Allow,Deny
Allow from All
</Directory>
" >> $conf_path
fi
# mod_fastcgi for httpd
cd $SRCROOT
if [ ! -d "${fastcgi}" ]; then
tar zxf ${fastcgi}.tar.gz
cd ${fastcgi}
cp Makefile.AP2 Makefile
make top_dir=${ROOT}/httpd -j4 &> fastcgi.log
make top_dir=${ROOT}/httpd install
fi
echo Done. Please run "${ROOT}/httpd/bin/apachectl start"
Feb
23
$ sudo apt-get install subversion
$ mkdir ~/svn/repo
$ cd ~/svn
$ svnadmin create repo
#配置
$ vi repo/conf/svnserve.conf
把一下几行前面的#去掉(行首不能有空格)
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = Repository
保存
$ vi repo/conf/passwd
格式很简单,在[users]后面,一个用户一行,格式为
用户名 = 密码
比如 felix021 = 123456
保存
$ vi repo/conf/authz
控制各个用户的权限,比较繁琐,最简单的是在[aliases]这一节【前面】加上这两行
[/]
*=rw
保存。
#运行服务
$ svnserve --daemon --root /home/feilx021/svn/
//可以在svn目录下创建多个项目的repository。
#--分割线--
#客户端
$ svn chechout svn://server_name/repo
Checked out revision 0.
$ mkdir ~/svn/repo
$ cd ~/svn
$ svnadmin create repo
#配置
$ vi repo/conf/svnserve.conf
把一下几行前面的#去掉(行首不能有空格)
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = Repository
保存
$ vi repo/conf/passwd
格式很简单,在[users]后面,一个用户一行,格式为
用户名 = 密码
比如 felix021 = 123456
保存
$ vi repo/conf/authz
控制各个用户的权限,比较繁琐,最简单的是在[aliases]这一节【前面】加上这两行
[/]
*=rw
保存。
#运行服务
$ svnserve --daemon --root /home/feilx021/svn/
//可以在svn目录下创建多个项目的repository。
#--分割线--
#客户端
$ svn chechout svn://server_name/repo
Checked out revision 0.