leadscloud

Google SEO|外贸营销推广

一种是:

ls -l |grep “^-” | wc -l

说明:

ls -l 长列表输出该目录下文件信息(注意这里的文件,不同于一般的文件,可能是目录、链接、设备文件等)
grep ^- 这里将长列表输出信息过滤一部分,只保留一般文件,如果只保留目录就是 ^d
wc -l 统计输出信息的行数,因为已经过滤得只剩一般文件了,所以统计结果就是一般文件信息的行数,又由于一行信息对应一个文件,所以也就是文件的个数。

查看文件夹下的文件个数(当前目录的文件和子文件夹的文件数)

find ./ -type f | wc -l

或者

ls -lR|grep “^-”|wc -l

另外一种:

ls -alR dir_name | awk ‘{if(NF>2&&substr($1,1,1)!=”d”)print $0}’ |wc -l

奇怪的是这两种方法统计的文件数量略有差别,后一种统计略多于前一种,但差别不大,都可以作为参考。

LNMPA中Apache的/root/lnmpa status问题解决方法

高手请无视,小白可借鉴。

问题描述:

LNMP0.7升级到LNMPA后
运行命令/root/lnmpa status
Apache的status一项会出现错误提示:

/etc/init.d/httpd: line 112: lynx: command not found

或者

Error 403 Access forbidden!

解决方法:

出现lynx: command not found错误提示的需要完成Step1&Step2
出现Error 403 Access forbidden!错误提示的只需要完成Step2

Step1

安装lynx

1
yum install lynx -y

Step2

运行命令

vi /usr/local/apache/conf/extra/httpd-info.conf

1
2
3
4
5
6
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
</Location>

改成

1
2
3
4
5
6
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

重启Apache

service httpd restart

再用/root/lnmpa status或者service httpd status查看Apache状态就是正常的了

还可以用http://youripordomain/server-status访问通过Web查看

附: LNMPA 常见问题整理(不定期更新)

http://bbs.vpser.net/thread-2792-1-1.html

我的wordpress网站出问题了,访问一看,果然全屏报错,检查mysql日志,错误信息为:

Table '.\wp_posts' is marked as crashed and should be repaired

提示说cms的文章表dede_archives被标记有问题,需要修复。于是赶快恢复历史数据,上网查找原因。最终将问题解决。解决方法如下:

找到mysql的安装目录的bin/myisamchk工具,在命令行中输入:

./myisamchk -c -r /usr/local/mysql/data/wp\@002dsouthafricacrusher\@002dcom/wp_posts.MYI

然后myisamchk 工具会帮助你恢复数据表的索引。重新启动mysql,问题解决。

问题分析:

1、错误产生原因,有网友说是频繁查询和更新dede_archives表造成的索引错误,因为我的页面没有静态生成,而是动态页面,因此比较同意这种说法。还有说法为是MYSQL数据库因为某种原因而受到了损坏,如:数据库服务器突发性的断电、在提在数据库表提供服务时对表的原文件进行某种操作都有可能导致MYSQL数据库表被损坏而无法读取数据。总之就是因为某些不可测的问题造成表的损坏。

1
2
3
4
5
@echo off
echo 复制当前html到txt文件夹下,并且重命名为txt格式
ren *.html *.txt
md txt
copy *.html txt*.txt

把它保存为bat扩展的文件,放到当前目录下,运行即可。 把当前文件批量重命名为.txt

说明下:我的主机为 Centos 系统

vi apachemonitor.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

URL=”http://127.0.0.1/”
curlit()
{
curl –connect-timeout 15 –max-time 20 –head –silent “$URL” | grep ’200′
# 上面的15是连接超时时间,若访问localhost的HTTP服务超过15s仍然没有正确响应200头代码,则判断为无法访问。
}
doit()
{
if ! curlit; then
# 如果localhost的apache服务没有正常返回200头,即出现异常。执行下述命令:
sleep 20
top -n 1 -b &gt;&gt; /var/log/apachemonitor.log
# 上面将top命令内容写入日至文件备查
/usr/bin/killall -9 apache2 &amp;&amp; /usr/bin/killall -9 php5-cgi &amp;&amp; /usr/bin/killall -9 httpd &amp;&amp; /usr/bin/killall -9 http &amp;&amp; /usr/bin/killall -9 apache &amp;&amp; /usr/bin/killall -9 php-cgi &gt; /dev/null
# 兼容起见,杀死了各种apache的进程。可以根据自己apache服务的特点修改
sleep 2
/etc/init.d/apache2 start &gt; /dev/null
/etc/init.d/httpd start &gt; /dev/null
# 兼容起见,执行了两种apache重启命令,可根据需要自己修改。
echo $(date) “Apache Restart” &gt;&gt; /var/log/apachemonitor.log
# 写入日志
sleep 30
# 重启完成后等待三十秒,然后再次尝试一次
if ! curlit; then
# 如果仍然无法访问,则:
echo $(date) “Failed! Now Reboot Computer!” &gt;&gt; /var/log/apachemonitor.log
# 写入apache依然重启失效的日志
reboot
# 重启机器呗。实际上重启整个服务器是一种非常不得已的做法。本人并不建议。大家根据需要自己修改,比如短信、邮件报警什么的。
fi
sleep 180
fi
}
sleep 300
# 运行脚本后5分钟后才开始正式工作(防止重启服务器后由于apache还没开始启动造成误判)
while true; do
# 主循环体
doit &gt; /dev/null
sleep 10
done

然后执行: chmod +x apachemonitor.sh

添加开机启动项:

vi /etc/rc.d/rc.local

我的rc.local脚本内容为:

1
2
3
4
5
6
7
8
9

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/root/lampmonitor.sh

转载的,里面有些内容可以借用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
//curl类
class Curl
{
function Curl(){
return true;
}

function execute($method, $url, $fields='', $userAgent='', $httpHeaders='', $username='', $password=''){
$ch = Curl::create();
if(false === $ch){
return false;
}
if(is_string($url) && strlen($url)){
$ret = curl_setopt($ch, CURLOPT_URL, $url);
}else{
return false;
}
//是否显示头部信息
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($username != ''){
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
}
$method = strtolower($method);
if('post' == $method){
curl_setopt($ch, CURLOPT_POST, true);
if(is_array($fields)){
$sets = array();
foreach ($fields AS $key => $val){
$sets[] = $key . '=' . urlencode($val);
}
$fields = implode('&',$sets);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
}else if('put' == $method){
curl_setopt($ch, CURLOPT_PUT, true);
}
//curl_setopt($ch, CURLOPT_PROGRESS, true);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_MUTE, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);//设置curl超时秒数
if(strlen($userAgent)){
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
if(is_array($httpHeaders)){
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
}
$ret = curl_exec($ch);
if(curl_errno($ch)){
curl_close($ch);
return array(curl_error($ch), curl_errno($ch));
}else{
curl_close($ch);
if(!is_string($ret) || !strlen($ret)){
return false;
}
return $ret;
}
}

function post($url, $fields, $userAgent = '', $httpHeaders = '', $username = '', $password = ''){
$ret = Curl::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username, $password);
if(false === $ret){
return false;
}
if(is_array($ret)){
return false;
}
return $ret;
}

function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password = ''){
$ret = Curl::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);
if(false === $ret){
return false;
}
if(is_array($ret)){
return false;
}
return $ret;
}

function create(){
$ch = null;
if(!function_exists('curl_init')){
return false;
}
$ch = curl_init();
if(!is_resource($ch)){
return false;
}
return $ch;
}
}
?>

GET用法:

1
2
$curl = new Curl();
$curl->get('http://www.hdj.me/');

POST用法

1
2
$curl = new Curl();
$curl->get('http://www.hdj.me/', 'p=1&time=0');

原文:http://www.hdj.me/curl-class-php

自己手工安装的lamp,所以需要有个脚本来控制服务器的停止与启动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi

HOSTNAME=`hostname`
MYSQLPIDFILE=/usr/local/mysql/data/$HOSTNAME.pid
APACHENAME=httpd
APACHEPIDFILE=/usr/local/apache/logs/$APACHENAME.pid

function_start()
{
printf "Starting LAMP...\n"

/etc/init.d/httpd start

if [ -f $MYSQLPIDFILE ]; then
printf "MySQL is runing!\n"
else
/etc/init.d/mysqld start
printf "MySQL start successfully!\n"
fi
}

function_stop()
{
printf "Stoping LAMP...\n"

/etc/init.d/httpd stop

if [ -f $MYSQLPIDFILE ]; then
/etc/init.d/mysqld stop
printf "MySQL program is stop\n"
else
printf "MySQL program is not runing!\n"
fi
}

function_reload()
{
printf "Reload LAMP...\n"
/etc/init.d/mysqld reload
/etc/init.d/httpd restart
}

function_restart()
{
printf "Restart LAMP...\n"
/etc/init.d/mysqld restart
/etc/init.d/httpd restart
}
function_kill()
{
kill `cat $APACHEPIDFILE`
kill `cat $MYSQLPIDFILE`
}
function_status()
{
/etc/init.d/httpd status
/etc/init.d/mysqld status
}

case "$1" in
start)
function_start
;;
stop)
function_stop
;;
restart)
function_stop
function_start
;;
reload)
function_reload
;;
kill)
function_kill
;;
status)
function_status
;;
*)
printf "Usage: /root/lamp {start|stop|reload|restart|kill|status}\n"
esac
exit

LNMP一键安装包安装的MySQL默认是开启了日志文件的,如果数据操作比较频繁就会产生大量的日志,在/usr/local/mysql/var/下面产生mysql-bin.0000* 类似的文件,而且一般都在几十MB到几个GB,更甚会吃掉整个硬盘空间,从来导致mysql无法启动或报错,如vps论坛用户的反馈

如何关闭MySQL的日志功能:

删除日志:

 

执行:/usr/local/mysql/bin/mysql -u root -p

输入密码登录后再执行:reset master;

再输入:quit 退出mysql命令模式。

彻底禁用MySQL日志:修改/etc/my.cnf 文件,找到

log-bin=mysql-bin
binlog_format=mixed

再这两行前面加上**#**,将其注释掉,再执行/etc/init.d/mysql restart即可。

注意如果你只注释:#log-bin=mysql-bin 重启mysql会出错错误: You need to use –log-bin to make –binlog-format work.

所以请把这两行都注释掉。

本文以LNMP一件安装包安装的环境为例除MySQL重启命令和配置文件路径可能略有不同,其他一样。

原文:http://www.vpser.net/manage/delete-mysql-mysql-bin-0000-logs.html

其它关闭方法

编辑 /etc/my.cnf

[mysqld] 最下面添加:skip-log-bin

重启mysql

1
[root@localhost ~]# /etc/init.d/mysqld restart

查看是否成功

1
show variables like 'log_bin';

最近VPS上有个网站总是挂掉,应该是耗CPU太厉害了。因为是 wordpress mu 站。 但是重启httpd时,总是不成功。

提示 httpd dead but pid file exists

解决办法:

1
tails -n 20 /var/log/httpd/error_log

查看日志,看有什么错误 ,我的错误显示:

1
[Mon Jun 25 17:54:02 2012] [emerg] (28)No space left on device: Couldn't create accept lock (/usr/local/apache/logs/accept.lock.3610) (5)

解决办法:http://carlosrivero.com/fix-apache---no-space-left-on-device-couldnt-create-accept-lock

1
2
3
ipcs -s | grep apache | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

ipcs -s | grep apache | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

然后再试试: service httpd start 应该就没问题了

网站又被别人注入恶意代码,在Google站长工具里会有提示,说我的网站被重定向到一个恶意网站上。

分析了自己的网站以前被注入恶意代码的过程,可以帮助一些人更快的找到它,并清除这些恶意代码。

我的网站是wordpress的,以前因为使用了timthumb, 由于它本身的漏洞,导致网站代码被随意更改。修复后,已经很少出现文件被修改情况。

一般一个网站被提示恶意代码,可以按以下步骤操作:

了解恶意代码的几种类型:

*恶意脚本

*.htaccess 重定向

*隐藏的 iframes

先查看网页源代码,看看有没有奇怪的script代码,如果有删除它。

然后再下载你的.htaccess, 看看有没有被人修改。

我一般都在ftp里,看文件的最近修改时间,如果在最近一段时间被人修改了,自己又没动什么,就可以确定是被别人恶意修改的。

更多信息:

http://www.stopbadware.org/home/security

0%