分类目录归档:LINUX

升级php-mysql到php-mysqlnd

最近在一次执行update时,发现了一个错误提示,说是更新安装的php-mysqlnd和php-mysql冲突。

原来是更新源将php-mysql更换成了php-mysqlnd,网上查了下mysqlnd是一种效率更高的php和mysql的连接方式。

1、先卸载php-mysql

yum remove php-mysql

2、安装php-mysqlnd

yum install php-mysqlnd
yum update

安装成功的验证方法是查看phpinfo(),在mysql和mysqli栏目中“Client API library version”变为了mysqlnd。
经测试原有的接口能正常使用。

wordpress屏蔽垃圾评论

大部分垃圾评论都是用自动化软件来发的,它会先GET一个页面,然后再往wp-comments-post.php文件POST内容。
例如:

"GET /archives/589.html HTTP/1.1" 200 8490
"POST /wp-comments-post.php HTTP/1.1" 302 26

垃圾评论当中80%以上都是福建莆田市IP发的,鄙视下。

1、使用插件
垃圾评论过滤:Akismet插件
wordpress评论滑动解锁:myQaptcha插件

发现效果不好,Akismet虽然能过滤垃圾评论但是阻止不了机器人提交评论,而且一来就是几百个连接,VPS负载直接飙到4点几,CPU占用率也很高,导致博客打开异常慢。上个月Akismet统计过滤了1,477,296条的垃圾评论怪不得会慢。
myQaptcha安装后没有起色,看日志里被绕过了。

2、直接屏蔽IP
网上找了一个类似功能修改下。先看下IP在日志里是第几个字段,第一个就填$1,第二个就填$2以此类推。
先从日志中过滤出IP:

awk '/wp-comments-post/ { printf $1 "\n"}' /var/log/httpd/live-in.org-access_log* | sort | uniq -d -c | awk '$1 > 10 {printf $2 "\n"}' >/tmp/iptables.txt 2>/dev/null

结果保存到/tmp/iptables.txt中。

iptables屏蔽:

awk '{system("iptables -I INPUT -s "$0" -j DROP")}' /tmp/iptables.txt
service iptables save

将/tmp/iptables.txt内的IP添加到iptables中并保存。

查看添加的内容:

iptables -n -L |less

说明:-n表示不做DNS解析

PS:如果效果不好,直接屏蔽IP段!
PS2:再次添加iptables时使用如下,先删除当前规则再添加避免重复

awk '{system("iptables -D INPUT -s "$0" -j DROP;iptables -I INPUT -s "$0" -j DROP")}' /tmp/iptables.txt
service iptables save

参考资料:
http://blog.csdn.net/windcxb/article/details/6547688
http://www.qingting.org/2012/iptables-block-ip-rule
http://www.ctohome.com/FuWuQi/0d/535.html

nginx防止空主机头域名指向

空主机头域名指向是指,比如我有个www.aaa.com的站点,别人用www.bbb.com域名指向了aaa.com的IP,这样访问www.bbb.com也能显示aaa.com的内容了。
在nginx的配置文件中已经定义了空主机头返回404页面。

vim /etc/nginx/nginx.conf

如下:

server {
        limit_conn addr 10;
        listen       80;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;

        location = /404.html {
            root   /usr/share/nginx/html;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
...后面省略
}


只要将定义网站的server段放在它的后面就能实现空主机头的域名都返回404页面。
继续阅读nginx防止空主机头域名指向

CentOS yum方式安装ffmpeg

系统为CentOS 6.4,自己编译ffmpeg和众多解码器太痛苦了,yum方式安装ffmpeg的解码器很全,先用用看。

1、安装所需软件

yum install -y automake autoconf libtool gcc gcc-c++

2、安装第三方更新源

rpm -ivh http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

3、安装ffmpeg

yum install ffmpeg ffmpeg-devel

会自动安装众多解码器,ffmpeg版本为0.6.5-1.el6.rf。看了下yum安装的解码器版本还不是很旧,但是ffmpeg版本较老。

4、测试一下
将一个.avi视屏转为.flv格式

ffmpeg -i Destination.avi -y -ab 56 -ar 22050 -r 15 -sameq test2.flv
继续阅读CentOS yum方式安装ffmpeg

mysql升级为了mariadb

今天在一台CentOS6.4的vps上执行了yum update -y,由于用第三方软件源结果mysql自动升级为了mariadb。
网上查了一下,mariadb是mysql的分支版本,开发小组的一些成员就是mysql开发小组的成员,主要由社区在维护,采用GPL授权许可。同样支持MyISAM引擎和InnoDB引擎。感觉开源社区打算逐步用mariadb来代替mysql。
更新后,在/etc目录下会生成my.cnf.rpmnew。
由于使用以前的配置文件会报错,所以要手动修改新的配置文件。
1、

mv /etc/my.cnf /tmp
mv /etc/my.cnf.rpmnew /etc/my.cnf
vim /etc/my.cnf
继续阅读mysql升级为了mariadb

OpenShift使用方法介绍

OpenShift是Red Hat公司推出的PaaS(Platform as a Service,平台即服务)。开发人员可以直接在平台上部署应用进行运行、测试。
官网:https://www.openshift.com/

一、注册及在Linux上配置命令行工具
1、首先注册帐号
每一个帐号可以创建三个免费的应用。
https://openshift.redhat.com/app/account/new
点击注册邮箱中的链接验证邮件地址。

2、设置namespace
登陆账号后,点击My Account下面的Create a domain for your applications设置帐号唯一公共URL访问地址。

输入后点击,Create。

继续阅读OpenShift使用方法介绍

[转+亲测]mysql常用命令

系统为CentOS6.4,mysql版本为5.1.67。

1、mysql服务的启动和停止
service mysqld start
service mysqld stop

2、登陆mysql
语法如下: mysql -u用户名 -p用户密码
键入命令mysql -u root -p, 回车后提示你输入密码,例如输入123456,然后回车即可进入到mysql中了。
mysql的提示符是:mysql>

3、显示数据库列表
show databases;

缺省有两个数据库:mysql和test。mysql库存放着mysql的系统和用户权限信息,我们改密码和新增用户,实际上就是对这个库进行操作。

4、显示库中的数据表
use mysql; //选中一个数据库
show tables;

5、显示数据表的结构
describe 表名;

显示该数据表由哪几个字段组成,数据类型分别是什么。
继续阅读[转+亲测]mysql常用命令

startssl免费ssl证书续期方法

startssl的免费ssl证书有一年的有效期(包括登录startssl的用户登录证书和域名ssl证书)。
续期步骤为:
1)更新用户登录证书
2)更新域名ssl证书

在用户证书过期前两星期注册邮箱会收到类似提示邮件:

This mail is intended for the person who owns a digital certificate issued by the StartSSL Certification Authority (http://www.startssl.com/).
The Class 1, client certificate for xxx@xxx.com and serial number xxxxxx (xxxxx) is about to expire in about two weeks. Please log into the StartSSL Control Panel at https://www.startssl.com/?app=12 and get a new certificate for this purpose. Failing to update your client certificate might result in the loss of your account.
Should you have lost the client certificate which was previously issued to you, please register once again – login without the client certificate installed into your browser will not work in that case.

1、浏览器访问https://www.startssl.com/?app=12,如果用户证书已过期只能重新注册一个帐号了。

2、点击Validations Wizard
选择Enter Email Address。

3、输入email地址,点击Continue。
继续阅读startssl免费ssl证书续期方法