Linux

浏览模式: 标准 | 列表 | 图文
ubuntu下最简单的更改时区

ubuntu下最简单的更改时区

  一般情况下,我们刚装好的ubuntu时区都是US(默认语言为英文时),而且,它本身就是使用UTC格式作为标准时间格式,如果在Linux下运行程序,且在程序中指定了与系统不一样的时区的时候,可能会造成时间错误。 如果是Ubuntu的桌面版,可以直接在图形模式下修改时区信息,如果是Server版呢,则需要通过tzconfig来修改时区信息了。只是这样的方式会相对比较麻烦,
使用方式 (如将时区设置成Asia/Chongqing):
sudo tzconfig
然后按照提示选择 Asia对应的序号,选完后会显示一堆新的提示—输入城市名,如Shanghai或Chongqing,最后再用 sudo date -s “” 来修改本地时间。

但事实上,并不需要这么复杂的处理,一个偷懒的方法就是,直接:cp /usr/share/zoneinfo/Asia/ShangHai /etc/localtime,用shanghai的时区文件覆盖localtime。灰常方便,这时候看一下date,时间是不是正确了?

转:apache一个优化小技巧

转:apache一个优化小技巧

determine the MaxClient

決定 web server 效能一個最重要的因素就是記憶體的量,而藉由調整 MaxClient,可以避免 Apache 產生過多無用的 child process。這個數字到底要調到多少,老實說也沒有一個標準答案,網路上大家比較建議的算法都是用機器有的記憶體和每個 child process 的 size 去做粗估。但事實上,要估計 apache child process 的 size 也不是一件容易的事,如果你用 ps aux 這個指令去看,出來的 VSZ or RSS value,其實都會把 shared memory 重覆記算(詳細內容請參考: Understanding memory usage on Linux , Memory usage determination with the ps command ),所以後來我採用的作法是:先將 MaxClent 設成一個比較小的值 (e.g. 30),然後再定期去看 error log 是否有 run out of clients 的情形,如果有的話,就再幫 MaxClients 加個 5。

原文来自:http://brooky.cc/2011/06/30/practical-guide-on-setup-wordpress-on-amazon-ec2-free-tier/

disable “AllowOverride”

理論上,AllowOverride 會造成 Apache 在路徑的每一層去找找看是否有 .htaccess 這個 file。
例如說:如果 virtual host 的設定是:

DocumentRoot /www/htdocs AllowOverride all

那任何一個 /index.html 的 request, Apache 都會試著去找 /.htaccess, /www/.htaccess, and /www/htdocs/.htaccess.
所以除非必要,是可以將 AllowOverride 設成 None.

但如果你用了 wordpress Pretty Permalinks”這個功能,那就會需要 rewrite rule 的功能。在這種情況下,可以考慮將 AllowOverride 的設定直接寫在 config 檔裡。

----------
上文中的链接:Memory usage determination with the ps command

The ps command can also be used to monitor memory usage of individual processes.

The ps v PID command provides the most comprehensive report on memory-related statistics for an individual process, such as:

  • Page faults
  • Size of working segment that has been touched
  • Size of working segment and code segment in memory
  • Size of text segment
  • Size of resident set
  • Percentage of real memory used by this process
The following is an example:
# ps v 
PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND
36626 pts/3 A 0:00 0 316 408 32768 51 60 0.0 0.0 ps v

The most important columns on the resulting ps report are described as follows:

PGIN
Number of page-ins caused by page faults. Since all I/O is classified as page faults, this is basically a measure of I/O volume.
SIZE
Virtual size (in paging space) in kilobytes of the data section of the process (displayed as SZ by other flags). This number is equal to the number of working segment pages of the process that have been touched times 4. If some working segment pages are currently paged out, this number is larger than the amount of real memory being used. SIZE includes pages in the private segment and the shared-library data segment of the process.
RSS
Real-memory (resident set) size in kilobytes of the process. This number is equal to the sum of the number of working segment and code segment pages in memory times 4. Remember that code segment pages are shared among all of the currently running instances of the program. If 26 ksh processes are running, only one copy of any given page of the ksh executable program would be in memory, but the ps command would report that code segment size as part of the RSS of each instance of the ksh program.
TSIZ
Size of text (shared-program) image. This is the size of the text section of the executable file. Pages of the text section of the executable program are only brought into memory when they are touched, that is, branched to or loaded from. This number represents only an upper bound on the amount of text that could be loaded. The TSIZ value does not reflect actual memory usage. This TSIZ value can also be seen by executing the dump -ov command against an executable program (for example, dump -ov /usr/bin/ls).
TRS
Size of the resident set (real memory) of text. This is the number of code segment pages times 4. This number exaggerates memory use for programs of which multiple instances are running. The TRS value can be higher than the TSIZ value because other pages may be included in the code segment such as the XCOFF header and the loader section.
%MEM
Calculated as the sum of the number of working segment and code segment pages in memory times 4 (that is, the RSS value), divided by the size of the real memory in use, in the machine in KB, times 100, rounded to the nearest full percentage point. This value attempts to convey the percentage of real memory being used by the process. Unfortunately, like RSS, it tends the exaggerate the cost of a process that is sharing program text with other processes. Further, the rounding to the nearest percentage point causes all of the processes in the system that have RSS values under 0.005 times real memory size to have a %MEM of 0.0.
Note: The ps command does not indicate memory consumed by shared memory segments or memory-mapped segments. Because many applications use shared memory or memory-mapped segments, the svmon command is a better tool to view the memory usage of these segments.
-----------
第二篇:http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html

这篇文章来自blogspot,一般情况下打不开,所幸我用Read it later,直接用广本模式,让他帮我打开了。HOHO,有点长,慢慢看:

This entry is for those people who have ever wondered, "Why the hell is a simple KDE text editor taking up 25 megabytes of memory?" Many people are led to believe that many Linux applications, especially KDE or Gnome programs, are "bloated" based solely upon what tools like ps report. While this may or may not be true, depending on the program, it is not generally true -- many programs are much more memory efficient than they seem.

What ps reports
The ps tool can output various pieces of information about a process, such as its process id, current running state, and resource utilization. Two of the possible outputs are VSZ and RSS, which stand for "virtual set size" and "resident set size", which are commonly used by geeks around the world to see how much memory processes are taking up.

For example, here is the output of ps aux for KEdit on my computer:


USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
dbunker 3468 0.0 2.7 25400 14452 ? S 20:19 0:00 kdeinit: kedit

According to ps, KEdit has a virtual size of about 25 megabytes and a resident size of about 14 megabytes (both numbers above are reported in kilobytes). It seems that most people like to randomly choose to accept one number or the other as representing the real memory usage of a process. I'm not going to explain the difference between VSZ and RSS right now but, needless to say, this is the wrong approach; neither number is an accurate picture of what the memory cost of running KEdit is.

Why ps is "wrong"
Depending on how you look at it, ps is not reporting the real memory usage of processes. What it is really doing is showing how much real memory each process would take up if it were the only process running. Of course, a typical Linux machine has several dozen processes running at any given time, which means that the VSZ and RSS numbers reported by ps are almost definitely "wrong". In order to understand why, it is necessary to learn how Linux handles shared libraries in programs.

Most major programs on Linux use shared libraries to facilitate certain functionality. For example, a KDE text editing program will use several KDE shared libraries (to allow for interaction with other KDE components), several X libraries (to allow it to display images and copy and pasting), and several general system libraries (to allow it to perform basic operations). Many of these shared libraries, especially commonly used ones like libc, are used by many of the programs running on a Linux system. Due to this sharing, Linux is able to use a great trick: it will load a single copy of the shared libraries into memory and use that one copy for every program that references it.

For better or worse, many tools don't care very much about this very common trick; they simply report how much memory a process uses, regardless of whether that memory is shared with other processes as well. Two programs could therefore use a large shared library and yet have its size count towards both of their memory usage totals; the library is being double-counted, which can be very misleading if you don't know what is going on.

Unfortunately, a perfect representation of process memory usage isn't easy to obtain. Not only do you need to understand how the system really works, but you need to decide how you want to deal with some hard questions. Should a shared library that is only needed for one process be counted in that process's memory usage? If a shared library is used my multiple processes, should its memory usage be evenly distributed among the different processes, or just ignored? There isn't a hard and fast rule here; you might have different answers depending on the situation you're facing. It's easy to see why ps doesn't try harder to report "correct" memory usage totals, given the ambiguity.

Seeing a process's memory map
Enough talk; let's see what the situation is with that "huge" KEdit process. To see what KEdit's memory looks like, we'll use the pmap program (with the -d flag):


Address Kbytes Mode Offset Device Mapping
08048000 40 r-x-- 0000000000000000 0fe:00000 kdeinit
08052000 4 rw--- 0000000000009000 0fe:00000 kdeinit
08053000 1164 rw--- 0000000008053000 000:00000 [ anon ]
40000000 84 r-x-- 0000000000000000 0fe:00000 ld-2.3.5.so
40015000 8 rw--- 0000000000014000 0fe:00000 ld-2.3.5.so
40017000 4 rw--- 0000000040017000 000:00000 [ anon ]
40018000 4 r-x-- 0000000000000000 0fe:00000 kedit.so
40019000 4 rw--- 0000000000000000 0fe:00000 kedit.so
40027000 252 r-x-- 0000000000000000 0fe:00000 libkparts.so.2.1.0
40066000 20 rw--- 000000000003e000 0fe:00000 libkparts.so.2.1.0
4006b000 3108 r-x-- 0000000000000000 0fe:00000 libkio.so.4.2.0
40374000 116 rw--- 0000000000309000 0fe:00000 libkio.so.4.2.0
40391000 8 rw--- 0000000040391000 000:00000 [ anon ]
40393000 2644 r-x-- 0000000000000000 0fe:00000 libkdeui.so.4.2.0
40628000 164 rw--- 0000000000295000 0fe:00000 libkdeui.so.4.2.0
40651000 4 rw--- 0000000040651000 000:00000 [ anon ]
40652000 100 r-x-- 0000000000000000 0fe:00000 libkdesu.so.4.2.0
4066b000 4 rw--- 0000000000019000 0fe:00000 libkdesu.so.4.2.0
4066c000 68 r-x-- 0000000000000000 0fe:00000 libkwalletclient.so.1.0.0
4067d000 4 rw--- 0000000000011000 0fe:00000 libkwalletclient.so.1.0.0
4067e000 4 rw--- 000000004067e000 000:00000 [ anon ]
4067f000 2148 r-x-- 0000000000000000 0fe:00000 libkdecore.so.4.2.0
40898000 64 rw--- 0000000000219000 0fe:00000 libkdecore.so.4.2.0
408a8000 8 rw--- 00000000408a8000 000:00000 [ anon ]
... (trimmed) ...
mapped: 25404K writeable/private: 2432K shared: 0K

I cut out a lot of the output; the rest is similar to what is shown. Even without the complete output, we can see some very interesting things. One important thing to note about the output is that each shared library is listed twice; once for its code segment and once for its data segment. The code segments have a mode of "r-x--", while the data is set to "rw---". The Kbytes, Mode, and Mapping columns are the only ones we will care about, as the rest are unimportant to the discussion.

If you go through the output, you will find that the lines with the largest Kbytes number are usually the code segments of the included shared libraries (the ones that start with "lib" are the shared libraries). What is great about that is that they are the ones that can be shared between processes. If you factor out all of the parts that are shared between processes, you end up with the "writeable/private" total, which is shown at the bottom of the output. This is what can be considered the incremental cost of this process, factoring out the shared libraries. Therefore, the cost to run this instance of KEdit (assuming that all of the shared libraries were already loaded) is around 2 megabytes. That is quite a different story from the 14 or 25 megabytes that ps reported.

What does it all mean?
The moral of this story is that process memory usage on Linux is a complex matter; you can't just run ps and know what is going on. This is especially true when you deal with programs that create a lot of identical children processes, like Apache. ps might report that each Apache process uses 10 megabytes of memory, when the reality might be that the marginal cost of each Apache process is 1 megabyte of memory. This information becomes critial when tuning Apache's MaxClients setting, which determines how many simultaneous requests your server can handle (although see one of my past postings for another way of increasing Apache's performance).

It also shows that it pays to stick with one desktop's software as much as possible. If you run KDE for your desktop, but mostly use Gnome applications, then you are paying a large price for a lot of redundant (but different) shared libraries. By sticking to just KDE or just Gnome apps as much as possible, you reduce your overall memory usage due to the reduced marginal memory cost of running new KDE or Gnome applications, which allows Linux to use more memory for other interesting things (like the file cache, which speeds up file accesses immensely).

vsftp + mysql的架设文档

vsftp + mysql的架设文档

上次介绍的vsftpd的配置是官方文档,这次是COPY来的,相对也是比较方便的,而且改动也很少。
只是需要libpam-mysql,mysql-dev等包。如果是基于ubuntu,那就实在是方便多了。都可以apt回来。。
OK,还是来原文吧,内容有点长,慢慢看就OK了:http://www.extmail.org/forum/thread-5427-1-1.html

VSFTP+MySQL虚拟用户配置

参考
[url]http://www.mysql-china.com/bbs/archiver/?tid-114.html[/url]
[url]http://blog.chinaunix.net/u1/39544/showart_310591.html[/url]
VSFTPD是一种在UNIX/Linux中非常安全且快速的FTP服务器,目前已经被许多大型站点所采用。VSFTPD支持将用户名和口令保存在数据库文件或数据库服务器中。VSFTPD称这种形式的用户为虚拟用户。相对于FTP的本地(系统)用户来说,虚拟用户只是FTP服务器的专有用户,虚拟用户只能访问FTP服务器所提供的资源,这大大增强系统本身的安全性。相对于匿名用户而言,虚拟用户需要用户名和密码才能获取FTP服务器中的文件,增加了对用户和下载的可管理性。对于需要提供下载服务,但又不希望所有人都可以匿名下载;既需要对下载用户进行管理,又考虑到主机安全和管理方便的FTP站点来说,虚拟用户是一种极好的解决方案。
环境:
操作系统: centos 4
流程图: user --> vsftpd-2.0.1 --> pam_mysql-0.71 --> mysql-server-4.1

1,初始化centos升级服务器.
# vi /etc/yum.repos.d/CentOS-Base.repo
=============== 代码 { ================================================
[base]
name=CentOS-4 - Base
baseurl=http://mirror.be10.com/centos/4/os/i386/
gpgcheck=1

#released updates
[update]
name=CentOS-4 - Updates
baseurl=http://mirror.be10.com/centos/4/updates/i386/
gpgcheck=1

#packages used/produced in the build but not released
[addons]
name=CentOS-4 - Addons
baseurl=http://mirror.be10.com/centos/4/addons/i386/
gpgcheck=1

#additional packages that may be useful
[extras]
name=CentOS-4 - Extras
baseurl=http://mirror.be10.com/centos/4/extras/i386/
gpgcheck=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-4 - Plus
baseurl=http://mirror.be10.com/centos/4/centosplus/i386/
gpgcheck=1
enabled=0

#contrib - packages by Centos Users
[contrib]
name=CentOS-4 - Contrib
baseurl=http://mirror.be10.com/centos/4/contrib/i386/
gpgcheck=1
enabled=0

#packages in testing
[testing]
name=CentOS-4 - Testing
baseurl=http://mirror.be10.com/centos/4/testing/i386/
gpgcheck=1
enabled=0
=============== 代码 } =================================================

# rpm -import [url]http://mirror.be10.com/centos/RPM-GPG-KEY-CentOS-4[/url]

2.安装所要软件包:
# yum -y install mysql-server*
# yum -y install vsftpd
# yum -y install vim*

3.建立系统用户,用户ftp登录时访问目录权限.但用户不允许登录.
# useradd vsftpdguest
# vi /etc/passwd
============= 代码 { =====================================
vsftpdguest:x:501:501::/home/vsftpdguest:/bin/nologin
============= 代码 } =====================================

4.将虚拟用户保存在MySQL数据库服务器中
建立数据库vsftpdvu,表users,字段name和passwd用于保存虚拟用户的用户名和口令,增加两个虚拟用户q和ftp1。
# service mysqld start
# mysql
mysql> create database vsftpdvu;
mysql> use vsftpdvu;
mysql> create table users(name char(16) binary,passwd char(16) binary);
mysql> insert into users (name,passwd) values ('q','q');
mysql> insert into users (name,passwd) values ('ftp1','success8');
mysql> quit

授权vsftpdguest可以读vsftpdvu数据库的users表。执行以下命令:
# mysql -u root mysql -p
mysql> grant select on vsftpdvu.users to vsftpdguest@localhost identified by 'i52serial0';
mysql> quit;

验证刚才的操作是否成功可以执行下面命令:
# mysql -u vsftpdguest -pi52serial0 vsftpdvu
mysql> select * from users;

5.设置MySQL的PAM验证(pam_mysql.so)
利用mysql进行pam验证的开源项目([url]http://sourceforge.net/projects/[/url]),主要目的是生成 pam_mysql.so文件
# tar xvzf pam_mysql-0.5.tar.gz
# cd pam_mysql
# make
# make install
make install这一步可能会出现错误,那只好手动将该目录下生成的pam_mysql.so复制到/lib/security目录下。

设置vsftpd的PAM验证文件。打开/etc/pam.d/vsftpd文件,修改内容:
# vi /etc/pam.d/vsftpd
======================== 代码 { ======================================
#%PAM-1.0
#auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd.ftpusers onerr=succeed
#auth required pam_stack.so service=system-auth
#auth required pam_shells.so
#account required pam_stack.so service=system-auth
#session required pam_stack.so service=system-auth
auth required pam_mysql.so user=vsftpdguest passwd=i52serial0 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=0
account required pam_mysql.so user=vsftpdguest passwd=i52serial0 host=localhost db=vsftpdvu table=users usercolumn=name passwdcolumn=passwd crypt=0
======================== 代码 { ======================================  
上面涉及到的参数,只要对应前面数据库的设置就可以明白它们的含义。这里需要说明的是crypt参数。crypt表示口令字段中口令的加密方式:crypt=0,口令以明文方式(不加密)保存在数据库中;crypt=1,口令使用UNIX系统的DES加密方式加密后保存在数据库中;crypt=2,口令经过MySQL的password()函数加密后保存,但是使用了crypt=2时会出错,可能是pam_mysql.so文件问题.

6.设置vsftpd 登录模式:
# vi /etc/vsftpd/vsftpd.conf
======================= 代码 { ==============================
local_enable=yes <--本地用户登录权限,要开启
pam_service_name=vsftpd <--验证文件/etc/pam.d/目录下
anonymous_enable=NO <--取消匿名登录
guest_enable=YES <--除了匿名用户外的所有用户都是guest
guest_username=vsftpdguest <--初了匿名用户外的所有用户使用vsftpdguest
======================= 代码 } ==============================
7.重启mysql、vsftpd数据库,进行测试:
# service mysqld restart
# service vsftpd restart

8.进一步的虚拟用户设置
首先,介绍虚拟用户的权限设置。
   新添了virtual_use_local_privs参数,当该参数激活(YES)时,虚拟用户使用与本地用户相同的权限。当此参数关闭(NO)时,虚拟用户使用与匿名用户相同的权限,这两者种做法相比,后者更加严格一些,特别是在有写访问的情形下。默认情况下此参数是关闭的(NO)。
 当virtual_use_local_privs=YES时,只需设置write_enable=YES,虚拟用户就可以就拥有写权限。
当virtual_use_local_privs=NO时,对虚拟用户权限的设置就更多一些更严格一些。
控制虚拟用户浏览目录:如果让用户不能浏览目录,但仍可以对文件操作,那么需要执行以下二个步骤:
第一步骤:配置文件中:
anon_world_readable_only=YES
允许虚拟用户上传文件: write_enable=YES
anon_upload_enable=YES
允许虚拟用户修改文件名和删除文件: anon_other_write_enable=YES
第二步骤:虚拟用户目录的权限改为只能由vsftpdguest操作:
# chown vsftpdguest.vsftpdguest /home/vsftpdguest
# chmod 700 /home/vsftpdguest
由于以上选项的设置同样会对匿名用户生效。如果不想匿名用户趁机拥有同样的权限,最好是禁止匿名用户登录。

  其次,由于虚拟用户在系统中是vsftpdguest身份,所以可以访问到系统的其他目录。为了更加安全,我们可以将虚拟用户限制在自家目录下。有两种做法:
   第一种做法:在配置文件中修改
chroot_local_user=YES。
第二种做法:在配置文件中增加以下选项
 chroot_local_user=NO
 chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
然后,在/etc/vsftpd.chroot_list文件中加入虚拟用户名q和ftp1。
经过修改后,虚拟用户登录后其根目录就限制在/home/vsftpdguest下,无法访问其他目录。

9.虚拟用户个人目录(没有测试)
登录后所在的目录都是/home/vsftpdguest,即都是guest_username用户的自家目录。为每个虚拟用户建立自家目录。
首先,在主配置文件中加入以下选项:
# vi /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/vsftpd_user_conf
然后,生成/etc/vsftpd/vsftpd_user_conf目录,并在该目录下建立与特定虚拟用户同名的文件:
# mkdir /etc/vsftpd/vsftpd_user_conf
# cd /etc/vsftpd/vsftpd_user_conf
# touch q
以上操作为虚拟用户q建立了个人配置文件/etc/vsftpd/vsftpd_user_conf/q.
接下来,在q的个人配置文件中将 q虚拟用户的自家目录修改为/home/q,配置选项为:
local_root=/home/q
最后,新建q目录,并将权限设为vsftpdguest:
# mkdir /home/q
# chown vsftpdguest.vsftpdguest /home/q
# chmod 600 /home/q
  经过以上设置,q登录VSFTPD后,用“pwd”指令就可以发现被自己被定位到自己的“/home/q”目录。
从文件系统层次来看,由于“/home/q”目录的权限是属于vsftpdguest的,所以其他的虚拟用户同样也可以访问q的自家目录。
解决这个问题也很简单,只需要让VSFTPD负责将虚拟用户限制在其自家目录,就可以避免虚拟用户的互相访问。具体做法参照前面第8步中所述。经过以上设置后,虚拟用户就可以拥有属于自己的目录了。
使用user_config_dir参数,在每个用户独立的配置文件里设定不同的权限和local_root参数就可以了

帮助:
在第5步处可以对程序进行调整:
# vi /etc/vsftpd/vsftpd.conf 查看ftp连接情况
log_ftp_protocol=YES
dual_log_enable=YES
syslog_enable=YES
# vi /etc/pam.d/vsftpd 调试pam_mysql连接情况
auth required /usr/local/lib/security/pam_mysql.so user=root passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=passwd crypt=2 verbose=1
account required /usr/local/lib/security/pam_mysql.so user=root passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=passwd crypt=2 verbose=1

---------
最后,你在上传的时候会发现,文件权限都是600,看vsftpd.conf里,有一个local_umask,上面还有注释,如果要改改成022,大多数Ftpd都是这么配置的。
关于umask为什么是022,可以查看老王的文章:Umask补习班
里面有这么一句:注:权限计算实际上是二进制位的与操作,参考All About the umask and Permissions。

apache 404转发

apache 404转发

平时我们用apache的404转发,大多数是:
ErrorDocument 404 /404.html
但这样其实也只能做到404的提示信息,会更加人性化一一点,但事实上我们要做到几件事情
比如我的图片不存在,我转发后,会根据图片的URL自动生成一张,这一点行不行呢?
于是乎,利用404转发就势在必行了
ErrorDocument 404 /xxx.php
在PHP里写上
<?php
header("Location:http://xxx.xxx.com".$_SERVER['REQUEST_URI']);
?>
或许有人说,为什么我的不起作用呢?
嗯,在ErrorDocument中,如果用其他域名就不行了
比如说我ErrorDocument 404 http://xxx.xxx.com/xxx.php
在其他域名下的Xxx.php不要说$_SERVER['REQUEST_URI']取不到,连HTTP_REFERER也没有的。
所以,还是在自己当前的项目写一下文件 ,利用header转发一下才是最OK的

新浪微博API更换

新浪微博API更换

纠结,新浪微博的接口更新到V2了
不知道以后的项目中还能不能使用目前的方法了。
不管怎么样,先看起来再说吧。TNND

自11月1日起,新浪微博开放平台将启用新版接口,新版接口采用api.weibo.com的URL,更加高效,规范,也为开发者带来更多功能。


更高效:

1. 微博、评论、用户等接口返回值增加了trim开关,可屏蔽返回值字段。

2. 支持数据过滤与应用隔离,新增feature参数可以按“全部、原创、图片、视频、音乐”过滤输出微博;base_app参数可以设置是否只输出基于当前应用产生的微博内容;


更规范:

1. 使用OAuth2.0授权机制。

2. 重新梳理了URI里资源类的概念,比如:statuses/comments 改为 comments/show;

3. 统一参数、返回值字段,全新的错误返回值格式。

4. 放弃REST风格URI,采用域+版本号+资源类+接口名+返回值格式+参数


更多功能:

新增100多个新接口,其中包含:增强的关系接口、推荐接口、搜索推荐接口 、短链接接口、热门微博接口、帐号接口,陆续还会有更多新接口开放。


其中,OAuth2.0授权更安全,更简单


更安全:

Access Token不再永久有效,约定回调页,接口使用https,对用户和开发者都更加安全。


更简单:

授权流程更简单,签名机制大大简化,不再需要特殊的编码处理和对参数排序。


注:需要说明的是,新版接口只能使用OAuth2.0授权机制,建议大家近期逐渐开始迁移工作,以保证应用的正常使用;但短时间内旧的授权接口依旧可以使用,具体下线日期另行通知。


如您在迁移工作中有任何疑问,请发邮件至weibo_app@vip.sina.com,或者私信@微博api,会有专人为您解答问题。


新版接口WIKI文档:http://t.cn/aF4zI1

OAuth2.0开发指南:http://t.cn/aF4we8

----------------
短时间内可用旧接口,哎,怎么办
这是官网的地址:http://open.weibo.com/wiki/OAuth2/access_token#OAuth2.2Faccess_token

转:Linux操作系统下Screen命令的使用方法

转:Linux操作系统下Screen命令的使用方法

Linux在操作的时候,不想等待当前的操作而关闭终端,那么要么在结尾加&,要么。。。就用这个screen了。
screen这个是最方便的。用法也简单,而且,还可以操作给别人看。所以,了解一下还是有好处的:

首先敲入命令screen,会创建一个跑着shell的单一窗口,在这里面你可以跑你所需要的程序
然后Ctrl+a d退出刚创建的窗口(回到进入screen前的环境)
然后再敲入命令screen创建新的终端窗口,循环往复,你可以建立多个有shell的窗口(这些窗口里都可以跑你自己的应用),于是乎,即使你退出远程管理窗口(进入screen的环境),你的screen窗间的窗口都不会关闭,里面跑得应用自然也不会当掉
1、screen -ls可以看所有的screen sessions
2、screen -r sessionid可以进sessionid指定的特定的screen session

如果screen session不再使用的时候,用screen -r sessionid进去exit退出即可
------------------------------------
参考资料:
Unix/Linux 工具: Screen 命令使用
screen使用
使用screen非常简易.只需在SHELL键入screen,便可打开一个screen session。
而在每个screen session 下,所有命令都以 ctrl+a(C-a) 开始。现在让我来简单介绍基本的命令C-a c -> Create,开启新的 window
C-a n -> Next,切换到下个 window
C-a p -> Previous,前一个 window

C-a C-a -> Other,在两个 window 间切换
C-a w -> Windows,列出已开启的 windows 有那些
C-a 0 -> 切换到第 0 个 window
C-a 1..9 -> 切换到第 1..9 个windowC-a a -> 发出 C-a,在 emacs, ve, bash, tcsh 下可移到行首C-a t -> Time,显示当前时间,和系统的 load
C-a K(大写) -> kill window,强行关闭当前的 windowC-a [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、
复制就像用使用 vi 一样C-b Backward,PageUp
C-f Forward,PageDown
H(大写) High,将光标移至左上角
L Low,将光标移至左下角
0 移到行首
$ 行末
w forward one word,以字为单位往前移
b backward one word,以字为单位往后移
Space 第一次按为标记区起点,第二次按为终点
Esc 结束 copy mode
C-a ] -> Paste,把刚刚在 copy mode 选定的内容贴上C-a ? -> Help,显示简单说明C-a d -> detach,将目前的 screen session (可能含有多个 windows)
丢 到后台执行 当按了 C-a d 把 screen session detach 掉后,会回到还没进 screen 时的状态,此时在 screen session 里每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。 下次 login 进来时:screen -ls -> 显示所有的 screen sessions
screen -r [keyword] -> 选择一个screen session 恢复对话若 screen -ls 里有 Attached sessions:
screen -d [keyword] -> 强制 detach,以便「接手」过来 实例
说明看了那么多,让我们用一个实际例子来结束我们今天的学习。在我们开启一个screen后,然后使用joe编辑一个文件,之后因为临时需要离开这时就可以运行Ctrl+a d,显示如下:[becks@ec-base becks]$ screen
[detached]这个时候当我们运行ps -e 可以看到pts/2这个我刚刚运行的screen正在运行joe
6264 pts/2 00:00:00 bash
6354 pts/2 00:00:00 joe而当我们回来后想恢复这个session,只需要键入screen -r,而当你有多个session时候,系统将提示你选择一个,如下:
[becks@ec-base becks]$ screen -r
There are several suitable screens on:
6263.pts-1.ec-base (Detached)
6382.pts-1.ec-base (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.输入该session的pid进行恢复
[becks@becks becks]$ screen -r 6263想退出screen的session,和退出shell一样,只需要键入exit命令,成功退出后将有以下提示
[screen is terminating]

原文来自:http://www.souzz.net/html/server/Linux/33280.html

deleted inode has zero dtime

deleted inode has zero dtime

Q: How do I get rid of lengthy Linux boot delays dealing with "deleted inode has zero dtime" messages?

Booting Linux on my laptop takes a long time. THis is because a message appears saying "deleted inode 6323 has zero dtime. Set dtime? yes". There are also two other deleted inodes with zero dtime — 229543 and 229544. Should I just ignore these messages and be patient, or is something wrong?

A: This shouldn`t happen every time you boot. It is a result of not having cleanly turned the machine off the previous time you used it. To turn the machine off, you must type halt as root. (type man halt or man shutdown for more info.) To reboot, you must hit control-alt-delete or use the reboot command.

svn 切换源

svn 切换源

由于IT对整个公司的IP网段进行了更替,导致svn连接不上。
于是想到了用命令行切换源的IP。
在windows平台下是很方便的,直接用小乌龟relocate就OK了。可是mac下面没有,linux下面也没有这样的gui界面。所以就用命令行了
网上找到资料都是svn relocate,但运行了一下,发现没有这个命令,只有svn switch --relocate
嗯,于是发现命令就是这样的:
svn switch --relocate FROM TO 原来的svn地址 新的SVN地址

--------

郝老师说svn sw就可以了,没有试过,我先备一下

备份:最简单的pure-ftp配置搭建ftp服务器

备份:最简单的pure-ftp配置搭建ftp服务器

又是google来的一篇备份性的文章,经测试成功了。所以备份下来:http://hi.baidu.com/sunnynatinc/blog/item/bd50e5ced55ed80e93457e38.html
OK,上原文:

使用pure-ftp最头疼的估计是要使用mysql做数据库和使用web管理了
其实就算没有装或不使用mysql也一样可以顺利且简便的使用pure-ftp搭建ftp服务器
下面介绍一下简单配置的经过


1、当然是取得pure-ftp了,直接在线安装,命令:
$ sudo apt-get install pure-ftpd 即可安装。


2、测试:当安装好以后没有进行配置的时候,ftp指向的默认目录是/home文件夹,如果使用ftp客户端软件链接127.0.0.1:21,提示你输入用户名和密码,则ftp已经安装好了。

3、配置:

1)了解pure-ftpd调用配置文件的方式。pure-ftp不是调用某一个配置文件,而是调用/etc/pure-ftpd/conf/中的一堆文 件进行配置加载,这和samba,apache配置有所区别。每一个配置文件其实只有一行,要么yes,要么no,或者1,0等等,比较方便定义。

2)开始进行基本配置。
进入到/etc/pure-ftpd/conf中,这里记下目录和目录中文件的权限,分别是755和644。
列目录为以下情况,只有 AltLog MinUID NoAnonymous PAMAuthentication PureDB UnixAuthentication等文件,这些文件都是配置文件。光有这些还不够,因此自己还要添加其他配置文件。

编辑基本配置,如监听21端口,使用某IP地址:
$ su #切换到root
(如果没有设置root账号是没有办法切换的,可以不切换,回到上层菜单将conf/的(包含子目录)权限设置为777,$ sudo chmod -R 777 conf/ 即可使用nano编写,编写完毕之后恢复目录755及文件644的属性),或者对shell脚本熟悉的可以使用sudo sh -c “echo 'xxx' > XXX" 来编写添加配置文件。以下均使用root权限编写。

监听端口
# echo ,21 > Bind ****添加bind 21端口监听 如果没有root权限则可以这样 $ sudo nano Bind 然后在其中编辑,21后保存退出,或 $ sudo sh -c "echo ',21' > Bind" 来添加
# echo 192.xx.xx.22 > ForcePassiveIP ****添加IP
# echo 4500 4600 > PassivePortRange ****添加端口范围

字符编码及文件设置
文件FSCharset中设定为UTF-8,这样有的在使用浏览器ftp的时候会出现中文乱码,增加一个客户端字符编码文件就可以解决
# echo gbk > ClientCharset ****(或gbk2132) 都可以
# echo yes > KeepAllFiles ****保留所有文件,用户不能删除文件
# echo yes > AutoRename ****自动更名,防止文件被覆盖

推荐的安全配置
#
echo yes > ChrootEveryone ****限制用户root权限
# echo yes > ProhibitDotFilesRead ****可以读取以.开头的文件
# echo yes > ProhibitDotFilesWrite
****可以写以.开头的文件
# echo yes > NoChmod ****不允许更改权限
# echo yes > BrokenClients
Compatibility ****多种兼容性客户端

网络设置
# echo 4 > MaxClientsPerIP ****每个IP最大连接数
# echo 20 > MaxClientsNumber ****客户端同时链接最大数

3)设置认证方式,将unix和PAM认证都设置为“no“,这一步中本身目录中就有这两个文件,只要修改其字符就可以了,unix原来就是no,用nano将PAM中的yes改为no就可以。如果没有这两个文件,则自己添加。
# echo no > PAMAuthentication
# echo no > UnixAuthentication
# echo /etc/pure-ftpd/pureftpd.pdb > PureDB ****建立pure-ftp的认证文件 这句可以使用nano建立PureDB文件,其内容为
/etc/pure-ftpd/pureftpd.pdb
# ln -s /etc/pure-ftpd/conf/PureDB ../auth/50pure ****建立认证链接文件

创建用户和指定ftp目录
# groupadd -g 2001 ftpgroup ****增加GID为2001的ftpgroup组
# useradd -u 2001 -s /bin/false -d /dev/null -c "pureftpd user" -g ftpgroup ftpuser ****增加ftpuser用户,切没有/bin的shell操作与/dev的设备操作权
使用pure-pw命令添加虚拟用户
# pure-pw useradd yourname -u ftpuser -d /yourname/ftp/ ****增加(yourname)用户并指定ftp目录为
/yourname/ftp/ 这里根据实际情况自行修改
回车后就提示输入密码(输入2次)
# pure-pw mkdb ****添加进认证数据文件

最后重启pure-ftpd
# /etc/init.d/pure-ftpd restart

如果仅仅是单位或定向ftp,则只添加一个账户就可以了,便于管理。如果使用所账户或可以匿名登录的,那就需要使用mysql的数据库来管理,配置也不繁 琐。 如果觉得还不够安全可以使用openssl来添加TLS/SSL支持,激活一个私有证书,这样传输内容经过加密,就更安全。

4)“关于ssl“
安装: # apt-get install openssl
# echo 1 > TLS ****打开TLS加密
# openssl req -x509 -nodes -newkey rsa:1024 -keyout /etc/ssl/private/pure-ftpd.pem -out
/etc/ssl/private/pure-ftpd.pem ****生成加密文件
# chmod 600 /etc/ssl/private/pure-ftpd.pem ****更改加密文件权限
重启pure-ftpd生效

5)“关于FXP协议“
如果只是内网或认证用户使用ftp,则可以打开FXP协议。由于FXP协议很不安全,不建议外网或允许匿名访问的ftp服务器打开FXP协议支持。

4、至此一个完整的ftp服务器就架构好了,可以使用任何一种ftp客户端登录使用。多用户还可以分别指定其目录或自动生成目录,设置目录UMASK等等,总体来说 功能还是很强大的。

------------
果然是超级简单的FTP服务器
Vsftpd虚拟用户设置

Vsftpd虚拟用户设置

来自官方的wiki:http://wiki.ubuntu.org.cn/Vsftpd%E8%99%9A%E6%8B%9F%E7%94%A8%E6%88%B7%E8%AE%BE%E7%BD%AE
做个备份。简单配置vsftpd

目标

首先我们假定你已经安装了vsftpd,并在/home/vsftpd 目录下建立了以下3个子目录

  • dbzh1
  • dbzh2
  • dbzh3

下面,我们要建3个虚拟用户,密码分别是用户名后加"00"

  • db1
  • db2
  • db3

使得

  • 用户db1 的主目录为 dbzh1 ,在该目录下只有只读权限
  • 用户db2 的主目录为 dbzh2,在该目录下只有只读权限
  • 用户db3 的主目录为 dbzh3 ,在该目录下拥有所有权限

创建虚拟用户数据库

创建文本文件loguser.txt

格式如下:

user_id
password

于是,我们/home/loguser.txt文件的内容为

db1
db100
db2
db200
db3
db300

生成数据库

如果你以前没装过libdb4.6-util 或者你不清楚装没装,需先执行下面的命令

sudo apt-get install db4.6-util

然后,我们执行

sudo db4.6_load -T -t hash -f /home/loguser.txt /etc/vsftpd_login.db


最后设置一下数据库文件的访问权限

sudo chmod 600 /etc/vsftpd_login.db

配置PAM文件

编辑文件/etc/pam.d/vsftpd.vu 将以下内容增加的原文件前面两行:

auth required pam_userdb.so db=/etc/vsftpd_login
account required pam_userdb.so db=/etc/vsftpd_login
  • 我们上一步建立的数据库 vsftpd_login 在此处被使用
  • 我们建立的虚拟用户将采用PAM进行验证,这是通过/etc/vsftpd.conf文件中的 语句pam_service_name=vsftpd.vu来启用的,稍后你将发现。

为虚拟用户创建本地系统用户

新建一个系统用户vsftpd,用户家目录为/home/vsftpd, 用户登录终端设为/bin/false(即使之不能登录系统)

sudo useradd vsftpd -d /home/vsftpd -s /bin/false
sudo chown vsftpd:vsftpd /home/vsftpd

/etc/vsftpd.conf

根据需要创建/etc/vsftpd.conf,一般要确保含有以下设置:

listen=YES
anonymous_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
chroot_local_user=YES
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd_user_conf
pam_service_name=vsftpd.vu
local_enable=YES
secure_chroot_dir=/var/run/vsftpd

现在为止,我们的3个用户都可以工作了,可是它们的根目录现在都是/home/vsftpd,权限也都一样。 那么怎么才能完成我们预定的目标呢?

/etc/vsftpd_user_conf

在上面的配置中,有这么一行

user_config_dir=/etc/vsftpd_user_conf

现在,我们要把各个用户的配置文件放到目录/etc/vsftpd_user_conf中

sudo mkdir /etc/vsftpd_user_conf
cd /etc/vsftpd_user_conf
sudo touch db1 db2 db3

db1文件中的内容如下

local_root=/home/vsftpd/dbzh1

同样,db2文件中的内容

local_root=/home/vsftpd/dbzh2

那么,db3的内容呢? 其实也很简单

write_enable=YES anon_world_readable_only=NO  anon_upload_enable=YES  anon_mkdir_write_enable=YES  anon_other_write_enable=YES  local_root=/home/vsftpd/dbzh3

这里要注意不能有空格,不然登录的时候会提示出错。 我的这里面也有问题,

能成?

重启vsftpd我们就可以看到效果了^_^

/etc/init.d/vsftpd start|restart

500 OOPS: cannot change directory:

linux打开ftp遇到的问题 500 OOPS: cannot change directory:

google好多都是 执行这个就OK setsebool ftpd_disable_trans 1 service vsftpd restart

但是执行的时候遇到这个问题  Could not change active booleans: Invalid boolean

搜了好久终于解决

setsebool -P ftp_home_dir=1