之前博客运行在BuyVM OpenVZ 128m的vps上,运行环境是lnmp.org提供的一键安装包,版本0.8。昨天把博客换到BuyVM KVM的vps上面,并且把一键安装包升级到了0.9。今天重启vps之后mysql死活起不来,执行/etc/init.d/mysql start,错误信息为:

Couldn’t find MySQL manager (/usr/bin/mysqlmanager) or server (/usr/bin/mysqld_safe) Continue reading »

Centos修改SSH端口号

Posted by 冰河 at 03:12 2 Responses » 28,221 Views
072012

1.添加端口

vim /etc/ssh/sshd_config

将#Port 22的注释去掉并且换行加入Port 443

如果是不是增加,而是修改端口的话,建议先保留22端口,等新端口可以登录再去掉。

443其实是https使用的端口,3128是squid使用的端口。建议使用大端口,比如10000~65535以上。

重启SSH服务 /etc/init.d/sshd restart
或者
Centos:service sshd restart
Debian:service ssh restart

2.防火墙开启443端口
vi /etc/sysconfig/iptables

加入-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

或者

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
service iptables save

重启防火墙 /etc/init.d/iptables restart

#ClientAliveInterval 60
#ClientAliveCountMax 3

128MB小内存VPS安装LNMP

Posted by 冰河 at 18:59 2 Responses » 44,839 Views
302012

买了个128MB内存的VPS,想装WordPress折腾下。软件当然首选LNMP,系统尝试了几次还是选Debian。话说高配置的机器还是推荐Centos,文档多,出了问题也好解决。但是像128MB内存的机器还是Debian省资源。

从lnmp.org下了一键安装包。可是尝试无数次都失败。最后看log发现是mysql安装失败。nginx和php都编译并安装,唯独mysql编译的时候out of memory了。于是想用一键安装包的脚本安装nginx和php等软件,mysql用apt-get安装。研究下了一键安装脚本,发现过于繁琐,虽然lnmp.org提供的一键安装包省事而且也能提高网站的访问体验,但是系统开销是很大的。

找来找去无意中看到了一个很神奇的脚本lowendbox的lowendscript。研究下了果断决定用这个脚本安装。

下面是LEB脚本包含的软件和对系统的修改
安装/替换的软件

dropbear to replace openssh. Invoked from xinetd.
inetutils-syslogd to replace rsyslog.
exim4 to replace sendmail (if installed). Re-configured to allow Internet delivery.
cron
nginx
mysql. Re-configured to remove innodb support, remove query cache and reduce key buffer size.
php with built-in FastCGI interface. Running only 1 child process and respawn after 5,000 requests.

对系统/软件的修改:

Removing some commonly bundled applications that should not be there in the first place for a minimal distro (apache2, sendmail, bind9, samba, nscd, etc).
MySQL root is given a new password (which can be found in ~root/.my.cnf)
Installing each WordPress site under /var/www/. It will create appropriate database, users and password for the site. Continue reading »

282012

安装OpenVPN需要主机支持tun,安装PPTP需要主机支持tun和ppp。

首先要检测你的VPS是否开启了TUN和PPP,联系你的服务器提供商,直接询问。如果没有开启,可以要求他们开启。

自行检测的方法:

检测TUN

cat /dev/net/tun

返回:

cat: /dev/net/tun: File descriptor in bad state 说明正常

检测是支持PPP模块

cat /dev/ppp

返回:

cat: /dev/ppp: No such device or address 说明正常 Continue reading »

222011

public class Test {

public  static  void  encode(byte[]  in,  byte[]  out,  int  password)
{
int  len  =  in.length;

int  seed  =  password  ^  0×3810860;
for  (int  i  =  0  ;  i  <  len;  ++i)  {
/**
*因为JVM中涉及byte、short、char类型的运算操作首先会把这些值转换成int类型,
* 然后对int类型的值进行运算,所以需要把运算结果强制转换成byte类型
*/
byte  a  =  (byte)(  (  in[i]  ^  seed  )  >>>  5  );//把异或后的值存放在a的低3位
byte  b  =  (byte)(  (  (  ((int)in[i])  <<  20 )  ^  seed  )  >>>  (20-3)  );//把异或后的值存放在b的高5位
a  &=  0×7;//0×7:0000 0111;将a中未存储有效数的位清零
b  &=  0xf8;//0xf8:1111 1000;将b中未存储有效数的位清零
out[i]  =  (byte)(a  |  b);
seed  =  ((seed  ^  out[i])  *  7321  +  out[i]);
}
}

public  static  void  decode(byte[]  in,  byte[]  out,  int  password)
{
int  len  =  in.length;

int  seed  =  password  ^  0×3810860;
for  (int  i  =  0  ;  i  <  len;  ++i)  {
//  fill  the  code  here
}
}
public  static  void  main(String  []  args)  throws  Exception
{
int  password  =  0x808d0625;
byte[]  buf1  =  {-36,  -108,  -73,  95,  56,  80,  -103,  -49,  59,  -52,  -30,  70,  -93,  88,  110,  -128,  88,  -42,  1,  114,  -117,  -67,  -84,  55,  24,  -107,  -97,  -51,  60,  -117,  113,  38,  110,  -103,  -70,  100,  54,  -126,  };
byte[]  buf2  =  new  byte[buf1.length];
decode(buf1,  buf2,  password);
System.out.println(new  String(buf2,  “GBK”));
}
} Continue reading »

JAVA中使用LDAP进行用户认证

Posted by 冰河 at 11:18 1 Response » 20,001 Views
302011

转篇文章自用

LDAP的英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP。它是基于X.500标准的,但是简单多了并且可以根据需要定制。与X.500不同,LDAP支持TCP/IP,这对访问Internet是必须的。LDAP的核心规范在RFC中都有定义,所有与LDAP相关的RFC都可以在LDAPman RFC网页中找到。现在LDAP技术不仅发展得很快而且也是激动人心的。在企业范围内实现LDAP可以让运行在几乎所有计算机平台上的所有的应用程序从 LDAP目录中获取信息。LDAP目录中可以存储各种类型的数据:电子邮件地址、邮件路由信息、人力资源数据、公用密匙、联系人列表,等等。通过把 LDAP目录作为系统集成中的一个重要环节,可以简化员工在企业内部查询信息的步骤,甚至连主要的数据源都可以放在任何地方。
Continue reading »

中位数查找问题

Posted by 冰河 at 17:55 3 Responses » 19,363 Views
292011

1.有两个已排好序的数组A和B,长度均为n,找出这两个数组的中间元素。要求时间代价为O(logn)。

然后再论证平均时间复杂度(要不就是最坏时间复杂度)为O(logn)。

大牛给的解法:

Say the two arrays are sorted and increasing, namely A and B.
It is easy to find the median of each array in O(1) time.
Assume the median of array A is m and the median of array B is n.
Then,
1′ If m=n, then clearly the median after merging is also m, the algorithm holds.
2′ If m<n, then reserve the half of sequence A in which all numbers are greater than
m, also reserve the half of sequence B in which all numbers are smaller than n.
Run the algorithm on the two new arrays.
3′ If m>n, then reserve the half of sequence A in which all numbers are smaller than
m, also reserve the half of sequence B in which all numbers are larger than n.
Run the algorithm on the two new arrays.

Time complexity: O(logn)

2.查找一个数列的中位数

我们算法导论上定义的选择问题(selection problem):

输入:一个包含n个不同数的集合A和一个数i,1≤i≤n。

输出:元素x∈A,它恰大于A中其他的i-1个元素。

解决选择问题是使用以快速排序算法为模型的分治算法。中位数问题其实就是选择问题的特例,即i=n/2。算法思想如下:

1.抽取数组的第一个元素作为主元,用快速排序的思想进行一次调整,将比主元小的放在左边,比主元大的放在右边。

2.如果主元的索引等于数组长度的一半,那么就找到了。

3.如果主元的索引比数组长度的一半小的话,那么在主元到数组的结尾这个期间内找第(数组长度的一半-主元的索引)大的数。

4.否则在数组的开始到中间值的索引这段期间内找第(数组长度的一半大)大的数。

递归的调用上面的几步,就可以解决问题。复杂度是O(n)

292011

写一段程序,找出数组中第k大小的数,输出数所在的位置。

Continue reading »

百度2011校园招聘笔试题

Posted by 冰河 at 20:45 4 Responses » 13,836 Views
072011

研发工程师_核心研发方向(BJ)场

1.extern “C”{}的含义及解决的问题

2.说明两种设计模式及应用场景

3.TCP中time_wait是什么状态,有什么优缺点?

1.任务分配问题,任务之间有依赖关系。给出算法及时间、空间复杂度。

2.给英文分句。文章由大小写字母、逗号和点号组成。句子以点号结束,至少包含一个字母。要求写一段完整的程序,程序在完成功能的前提下尽可能简洁

某系统每天有1000亿条记录,存储url,ip,时间。

设计一个系统存储查询这些记录。实习记录,并能按以下要求查询:

(1)给出某时间段(精确到分钟),能查询某url的访问次数
(2)给出某时间段(精确到分钟),能查询某ip的访问次数

Young氏矩阵问题及算法

Posted by 冰河 at 17:48 No Responses » 8,304 Views
042011

百度某年的笔试题就考过Young氏矩阵的存在问题,所以这里把Young氏矩阵问题及算法贴一下

一个 m*n 的 Young 氏矩阵(Young tableau) 是一个 m*n 的矩阵,其中每一行的数据都从左到右排序,每一列的数据都从上到下排序.Young 氏矩阵中可能会有一些  ∞ 数据项,表示不存在的元素.所以,Young 氏矩阵可以用来存放 r<= mn 个有限的元素.
a).画一个包含{9,16,3,2,4,8,5,14,12} 的4*4 的 Young 氏矩阵.

b).给出一个在非空 m*n 的 Young  氏矩阵上实现 EXTRACT-MIN 算法,使其运行时间为O(m+n).

c).说明如何在O(m+n)时间内,将一个新元素手入到一个未满的 m*n Young 氏矩阵中.

d).给出一个时间复杂度为 O(n^3) 的对 n*n Young 氏矩阵排序的算法.

e).给出一个运行时间为O(m+n) 的算法,来决定一个给定的数是否存在于一个给定的 m*n  的 Young 氏矩阵当中. Continue reading »

© 2009 - 2024 冰河的博客