苹果相关

浏览模式: 标准 | 列表 | 图文
tree

tree

看到标题不要以为是植树节,tree这个命令还是很爽的。
在windows下面,我们用tree命令可以将当前的目录结构打印出来方便工作交接和介绍项目,在linux下面。。。。默认没有这个tree命令。
因为我用ubuntu,所以直接apt-get install tree,就OK了。

用法很简单,如果你不愿意记参数,直接去要统计的目录下面执行一下,tree
然后就出来结构树了。最后还有一行:
952 directories, 4642 files

好吧,这是我的一个项目中的protected目录,嗯。主要是因为多了一个zend框架,如果没有它。我只有1000多个文件了。整个项目还不如一个框架。。。。

如果apt也回不来?这里有一篇文章可以参考一下:http://www.cnblogs.com/dekun_1986/archive/2011/09/04/2166146.html

我用busybox建的根文件系统,没有这个tree命令,可以下载此命令的源码,交叉编译一下,再放到根文件系统中的/bin目录中就好。

源码下载地址:ftp://mama.indstate.edu/linux/tree/

我是在arm平台下,所以把makefile 文件中的CC那行改为“CC=arm-linux-gcc”,再把生成的tree文件通过nfs弄到开发板的bin文件下就可以了

现在的最新版本是1.6.0,下载地址:

/Files/dekun_1986/tree-1.6.0.rar

---EOF---

上述的链接是在cnblogs的。如果你不放心,就去上面的ftp地址下载吧。

proftpd 问答

proftpd 问答

Frequently Asked Questions
Question: Why do I see the following when my proftpd starts up?

  getaddrinfo 'hostname' error: No address associated with hostname   warning: unable to determine IP address of 'hostname' 

Answer: This error is ProFTPD's way of reporting that it was unsuccessful in resolving hostname to an IP address. Fixing this is a matter of configuring DNS for that hostname: properly set up an IP address for that DNS name in your DNS server, use a DNS name that has an IP address, or (as a quick fix/last resort) add that DNS name to your /etc/hosts file. The proper solution depends largely on the circumstances.

Question: If proftpd resolves any DNS names to IP addresses when it starts up, and I am using dynamic IP addresses which change after my proftpd has started, will proftpd see my new IP addresses?
Question: Unfortunately not. ProFTPD has no easy way of handling dynamic IP addresses by itself. One way of dealing with this situation is to restart proftpd periodically, which will force it to re-parse its configuration and thus re-resolve all IP addresses.

Question: What if I do not want proftpd to use DNS to resolve the hostname to an IP address because I am in an environment where there is no DNS at all?
Answer: In ProFTPD 1.3.3rc1, support for a new -S command-line option was added. This option can be used to specify the IP address of the host machine. By default, proftpd attempts to resolve the host IP address by using DNS resolution of the hostname. However, in cases where DNS is not configured for the host machine, this approach does not work.

To specify the desired IP address, use -S when starting proftpd, e.g.:

  /usr/local/sbin/proftpd -S 1.2.3.4 ... 

And if you want proftpd to listen on all interfaces, you can specify a wildcard socket using an IP address of 0.0.0.0:

/usr/local/sbin/proftpd -S 0.0.0.0 ...

Note that will also mean that, in your proftpd.conf, any <VirtualHost> sections will need to use IP addresses, not DNS names.

aliyun 安装 ftp(proftpd)

aliyun 安装 ftp(proftpd)

有了服务器,怎么着都得装个Ftp吧,否则,必须得让人用ssh连接来上传文件 ?
于是我找了proftpd,因为比较简单vsftpd太麻烦了。proftpd的教程很简单

1、先apt-get update,apt-get upgrade
2、apt-get install proftpd-basic proftpd-mod-mysql
3、修改 /etc/proftpd/proftpd.conf
因为原内容都注释了,所以直接在文件的最后加上:

DefaultRoot ~
Include /etc/proftpd/sql.conf
RequireValidShell off

4、添加一个组,和一个用户:

groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

5、去mysql里增加一个用户,如proftpd/proftpdpass,建一个数据库,如:proftpd
6、插入表结构:

CREATE TABLE ftpgroup (
groupname varchar(16) NOT NULL default '',
gid smallint(6) NOT NULL default '2001',
members varchar(16) NOT NULL default '',
KEY groupname (groupname)
) ENGINE=MyISAM COMMENT='ProFTP group table';

CREATE TABLE ftpuser (
id int(10) unsigned NOT NULL auto_increment,
userid varchar(32) NOT NULL default '',
passwd varchar(32) NOT NULL default '',
uid smallint(6) NOT NULL default '2001',
gid smallint(6) NOT NULL default '2001',
homedir varchar(255) NOT NULL default '',
shell varchar(16) NOT NULL default '/sbin/nologin',
count int(11) NOT NULL default '0',
accessed datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id),
UNIQUE KEY userid (userid)
) ENGINE=MyISAM COMMENT='ProFTP user table';

7、修改/etc/proftpd/modules.conf,去掉两行注释:

LoadModule mod_sql.c
LoadModule mod_sql_mysql.c

8、修改/etc/proftpd/sql.conf

SQLBackend mysql
SQLAuthTypes Crypt
#下面一行就是用户名密码
SQLConnectInfo 数据库@localhost 用户名 密码
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members
# Update count every time user logs in
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "countcount=count+1, accessed=now() WHERE userid='%u'" ftpuser
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

9、插入用户:

INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 2001, 'ftpuser');
INSERT INTO `ftpuser` ( `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`, `count`) VALUES ( 'username', ENCRYPT('password'), 2001, 2001, '/var/www/www.example.com/', '/sbin/nologin', 0);

10、重启proftpd:/etc/init.d/proftpd restart
上面这段其实是来自:http://www.sysadminworld.com/2011/install-proftpd-with-mysql-backend-on-debian-ubuntu/

--------EOF---

至此,上面的内容基本上就能够登录成功了,如果还是失败,建议先停掉proftpd,然后运行proftpd -nd6,查看错误信息,比如我就看到了这个:

Mar 09 00:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): notice: unable to use '~/' [resolved to '/server/wwwroot/htdocs/']: Permission denied
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): Preparing to chroot to directory '~/'
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): chroot to '~/' failed for user 'xxxxxx': Operation not permitted
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): error: unable to set default root directory
Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): FTP session closed.

我靠,这个怎么办?

这时候我又请vampire帮忙了。他就帮我检查了一下,做了几个处理:

1、vim /etc/groups ,在www-data:x:33后面加了:www-data:x:33:ftpgroup ,表示权限跟着www-data,因为我们的ftp目录里的文件都是基于www-data的

2、修改/etc/proftpd/proftpd.conf,改其中的:user / group ,都改成www-data

3、还是/etc/proftpd/proftpd.conf ,改 Umask ,原来是Umask 022 022,去掉一个022

4、因为我的www-data是gid是33,所以刚才在数据库里插的gid统统换成33,而不是原来的2001,这时候再登录其实还是不正常。

5、最重要的一个,在刚才的sql.conf里面,加入:SQLMinID 33,这个玩意要参考:http://www.proftpd.org/docs/directives/linked/config_ref_SQLMinID.html,我晶,这个东西,居然在默认的sql.conf里是没有这一行的。果然还是vampire有经验。因为www-data的gid是33,所以sqlminid就是33了。

这时候,终于一切正常了。折腾了好久。。。

aliyun二三事

aliyun二三事

最近在试用阿里云,但是遇到了一些问题。
我在安装数据库的时候,是通过apt-get install mysql-server进行安装的,然而我安装完后,想将数据存储到额外挂载的磁盘时,却发现数据不能写入。。。
因为我老是启动失败。。所以看了下LOG,LOG是说写入目录失败。
于是请vampire帮忙看了一下,他测试了mysql_install_db,但是。。。

# mysql_install_db --datadir=/server/software/mysql_data
Installing MySQL system tables...
130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test
130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test
ERROR: 1005 Can't create table 'db' (errno: 13)
130308 16:14:25 [ERROR] Aborting

130308 16:14:25 [Note] /usr/sbin/mysqld: Shutdown complete


Installation of system tables failed! Examine the logs in
/server/software/mysql_data for more information.

You can try to start the mysqld daemon with:

shell> /usr/sbin/mysqld --skip-grant &

and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:

shell> /usr/bin/mysql -u root mysql
mysql> show tables

Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /server/software/mysql_data that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the /usr/scripts/mysqlbug script!

oh shit,还是安装不了。试了很多都没有用。最后从官方下载了5.6的包进行安装。居然就OK了。我靠,这个源是cn.ubuntu的源啊。。。苦逼了。
所幸问题解决了。

多谢vampire,同时各位朋友也注意下。如果真的不行,也可以尝试从网上直接下载源码编译,要么。就换成中科大的源,然后再upgrade。中科大的更新比较快。

但因为要修改内容和启动参数还是有点危险的。。。

为debian增加apt-add-repository功能

ubuntu下面有一个很不错的功能,它能够使你很方便 的添加ppa的源,那就是apt-add-repository
在我之前写的一篇博客里就有介绍此功能(关于gearman的),但在debian系统上就无法适用,因为debian下没有此功能
于是找了ubuntu下的apt-add-repository的代码,cp了一份到debian下面,但不能运行。所以google了一下,发现这么一段代码就OK了:

#!/bin/bash
if [ $# -eq 1 ]
then
ppa_name=`echo "$1" | cut -d":" -f2 -s`
if [ -z "$ppa_name" ]
then
echo "PPA name not found"
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
else
echo "$ppa_name"
echo "deb http://ppa.launchpad.net/$ppa_name/ubuntu lucid main" >> /etc/apt/sources.list
apt-get update >> /dev/null 2> /tmp/apt_add_key.txt
key=`cat /tmp/apt_add_key.txt | cut -d":" -f6 | cut -d" " -f3`
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
rm -rf /tmp/apt_add_key.txt
fi
else
echo "Utility to add PPA repositories in your debian machine"
echo "$0 ppa:user/ppa-name"
fi

将这段内容存成apt-add-repository,然后cp到/usr/bin目录下,并且chmod +x 这个文件,让它有可执行的权限。
再接着使用apt-add-repository 来添加源就OK了
这个自定义的版本,在添加完源后,还会将source.list进行了修改。比ubuntu还人性化。。
参考:
1.http://cptbtptp.blog.51cto.com/3228046/620036
2.http://jolin.2001.blog.163.com/blog/static/89912172011485354567/
两篇内容细看,其实就是一样的。。

svn: E220001: Unreadable path encountered; access denied

svn: E220001: Unreadable path encountered; access denied

发现svn的代码有更新,却忘了与上次对比。于是svn与上一版本对比的时候就出现了标题的错误:
svn: E220001: Unreadable path encountered; access denied

其实解决方法很简单,在conf/svnserve.conf中。找到anonaccess = read这一行,(默认是注释掉的)
加入一行 anonaccess = none

再试一下,就会发现正常了。

这应该算是svn的BUG了。拜托,就算你不支持anon这样的匿名用户,你好歹默认为NONE这种值你总要存在吧。不存在 就直接造成无法访问,没权限了。

ubuntu下安装gearman及扩展

ubuntu下安装gearman及扩展

Ubuntu下面安装gearman以及php的gearman扩展是需要注意一下的。
不是默认的安装就直接OK
apt-get install gearman
安装完gearman后。使用pecl install gearman安装。这时候会提示你安装新版 的libgearman
如果你直接搜索apt-cache search libgearman,会发现有很多,但其实一个都不是。。不用上当了

OK,怎么办?有人也问过这个问题:http://stackoverflow.com/questions/13312207/installing-gearman-php-extension-on-debian-6
有人这么回复 :

The reason that this doesn't work is that as the error message says, the most recent version of the PHP extension requires libgearman-1.0 (which is why the directory is named 1.0). You'll need to be at least on wheezy (which is the version after debian 6 / squeeze) to get libgearman-1.0.

It might also be a solution to compile libgearman from source, and then use checkinstall to create a debian package that you install afterwards, or use the gearman developer ppa available at https://launchpad.net/~gearman-developers/+archive/ppa. We've built libgearman, gearmand and the PHP extension on a wide variety of distributions (including Debian, Ubuntu, RHEL4 and SL6) and used checkinstall to get a proper package available.

嗯,打开这个网址。
在最上面有提醒你怎么将PPA将入源里:

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:gearman-developers/ppa to your system's Software Sources. (Read about installing)

OK,那我们开始吧:

apt-add-repository ppa:gearman-developers/ppa

然后,你根据你的版本,将源加到你的source.list文件里:
vim /etc/apt/source.list
加入:

deb http://ppa.launchpad.net/gearman-developers/ppa/ubuntu precise main  deb-src http://ppa.launchpad.net/gearman-developers/ppa/ubuntu precise main 

然后:apt-get update
apt-get upgrade
会提醒你需要升级gearman到最新版 本
这时候再:
pecl install gearman
然后就直接安装成功,会提示你怎么操作:
Build process completed successfully
Installing '/usr/lib/php5/20090626+lfs/gearman.so'
install ok: channel://pecl.php.net/gearman-1.1.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=gearman.so" to php.ini
按照提示操作完后,重启apache。
在命令行下执行:
# php -i |grep gearman
gearman
gearman support => enabled
libgearman version => 0.40
wow...安装成功。
就是这么简单
apache 限制IP访问

apache 限制IP访问

这是一个小笔记。以前也记过,只是后来忘了。其实就几行代码而已:

<directory xxx>
# 设置可以访问服务器的IP
Allow From 192.168.1.12 220.133.*.*/255.255.255.255
Order deny,allow
Deny from all
</directory>

上面的URL中更加详细 我这个只是一个简单的demo而已。

发发对84的牢骚

刚才看到群里有人在说84(burst)的VPS,我也发发牢骚吧
一年前买了个84的vps,那时候大家都说它便宜,不错。于是我就信了。
因为买一年会有一个优惠,所以我一下子就买了一年的。然后问题就来了

用了2个月,都还不错,但第三个月开始,有一天突然不能访问了。去控制面板一看,关机了。于是reboot
过两天发现又关机了。又reboot,然后当天晚上又关机了。

这TMD太让人纠结了。开始我想,可能是我的系统有问题吧?于是更新补丁,结果第二天还是关机了。难道ubuntu有漏洞?于是我装了一个gentoo,什么软件都没有装,就空着。2天后还是关机了。我晶啊。

今天我想上去看看。结果。。。控制面板也登录不了了,用户名和密码不都是后台自动提供的吗?为什么这也登录不了。
这年头。84真让人郁闷。

如果还有人让我推荐VPS,84我是绝对不会再推荐的了。价格其实现在看来相对于其他的VPS供应商,也没有便宜到哪里去。

busybox

busybox

最近买了一个UIS2000,也就是一个NAS设备了。因为内置了linux操作系统。所以就想着用它来做一些其他的事情,比如备份,比如做个小网站之类的。
但是功能确实不够强大,于是同事建议我下载一个最新的busybox,因为功能更强大。于是我查了一下busybox是干嘛的,用法怎么样,看了一下。哇塞,好方便啊。。。。。。

busybox是一个集成了一百多个最常用linux命令和工具的软件,他甚至还集成了一个http服务器和一个telnet服务器, 而所有这一切功能却只有区区1M左右的大小.我们平时用的那些linux命令就好比是分立式的电子元件,而busybox就好比是一个集成电路,把常用的 工具和命令集成压缩在一个可执行文件里,功能基本不变,而大小却小很多倍,在嵌入式linux应用中,busybox有非常广的应用,另外,大多数 linux发行版的安装程序中都有busybox的身影,安装linux的时候案ctrl+alt+F2就能得到一个控制台,而这个控制台中的所有命令都 是指向busybox的链接.
Busybox的小身材大作用的特性,给制作一张软盘的linux带来了及大方便.
---
关键,它真的很小,带的功能却不少,什么bzip,tar,cat,vi等等常用的都带了。。crontab 都有了。。。。ftpd,httpd,我晕啊。还有什么是它没有的?
----
安装软件也很方便,先./busybox --list,看看有多少功能。然后。。。
可以这样用busybox
#busybox ls
他的功能就相当运行ls命令
最常用的用法是建立指向busybox的链接,不同的链接名完成不同的功能.
#ln -s busybox ls
#ln -s busybox rm
#ln -s busybox mkdir

然后分别运行这三个链接:
#./ls
#./rm
#./mkdir

就可以分别完成了ls rm 和mkdir命令的功能.虽然他们都指向同一个可执行程序busybox
但是只要链接名不同,完成的功能就不同,busybox就是这么的神奇.
很多linux网站都提供busybox的源代码下载.

-----
下面的东东对我来说用不太倒,但我还是贴一下,供有心人做测试:
3,配置busybox

busybox的配置程序和linux内核菜单配置方式简直一模一样.熟悉用make menuconfig方式配置linux内核的朋友很容易上手.

#cp busybox-1.00.tar.gz /babylinux
#cd /babylinux
#tar xvfz busybox-1.00.tar.gz
#cd busybox-1.00
#make menuconfig

下面是需要编译进busybox的功能选项,其他的可以根据需要自选,但是同样不要太贪心.
General Configuration应该选的选项
Show verbose applet usage messages
Runtime SUID/SGID configuration via /etc/busybox.conf

Build Options
Build BusyBox as a static binary (no shared libs)
这个选项是一定要选择的,这样才能把busybox编译成静态链接的可执行文件,运行时才独立于其他函数库.否则必需要其他库文件才能运行,在单一个linux内核不能使他正常工作.

Installation Options
Don't use /usr
这个选项也一定要选,否则make install 后busybox将安装在原系统的/usr下,这将覆盖掉系统原有的命令.选择这个选项后,make install后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向他的链接.

其他选项都是一些linux基本命令选项,自己需要哪些命令就编译进去,一般用默认的就可以了.

配置好后退出并保存.

4,编译并安装busybox

#make
#make install

编译好后在busybox目录下生成子目录_install,里面的内容:
drwxr-xr-x 2 root root 4096 11月 24 15:28 bin
lrwxrwxrwx 1 root root 11 11月 24 15:28 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4096 11月 24 15:28 sbin
其中可执行文件busybox在bin目录下,其他的都是指向他的符号链接.
我编译出来的busybox可执行文件是935K,加上符号链接,整个_install目录是952K.加上845K的内核不是已经超过1440K了吗?别担心,我们将对整个根文件系统做大幅度的压缩.
-------上面的大部分内容都不是我写的,我只是做了一个简单的COPY。
不过我现在用的很爽。同事也编译了一个PHP,在我不会写bash的时候,我就准备用这个php来完成一些我的脚本了。只保留了两个文件:php和php-cgi。但我觉得php-cgi可能也用不到。。。一个纯php就足够了。黑黑
上面的大部分内容来自:http://hi.baidu.com/pylctstsddhistr/item/36cc0cbd3f44799d19469708