mysql修改配置参数innodb_log_file_size后不能正常工作,在phpmyadmin中innodb表状态为“使用中”

问题:修改mysql配置参数innodb_log_file_size 后,可能无法正常启用,或者innodb表将不能工作,在phpmyadmin中显示为“使用中”

解决方法:先停掉mysql,然后删掉旧innodb日志文件后,再启动mysqld就可以正常启用了.innodb旧日志文件位于mysql data 目录下的ib_logfile0, ib_logfile1 文件

innodb日志文件在linux下的典型位置为 /var/lib/mysql
在windows下则默认位于安装目录下的data子目录里。

原因:是旧的innodb日志文件,与改后的innodb_log_file_size不匹配,所以造成mysql不能正常工作。

redhat/centos 6 linux下mkinitrd 生成initramfs.img文件过大原因及dracut使用

centos 6下自己编译linux内核,完了创建initrd文件,依据以前的的经验mkinitrd

#mkinitrd -v ../initramfs-3.0.32.img 3.0.32

但是输出的消息却与以前的版本不太一样,好像打包进去了很多模块,生成花费时间也很长,完成后,看initramfs文件有100多M,OMG,这么大的文件 /boot目录可放不下(/boot挂在单独的分区下,该分区只有100M大小)。

经过N久的折腾,才发现原来redhat/centos6不再使用原来的mkinitrd,而是使用dracut代替了,mkinitrd实际上只是调用dracut的功能。研究dracut才弄明白,如果只是生成用于grub引导本地硬盘上的linux,需要使用一个参数--hostonly ,这样dracut就不会把过多不必要的模块加载到initramfs.img里,如下

dracut -f -v --hostonly -k '/lib/modules/3.0.32'  ../initramfs-3.0.32.img 3.0.32

这是通过查阅kernel 编译安装的 make install 使用是执行的以下脚本实现的:
sh /path/to/kernel-source/linux-3.0.32/arch/x86/boot/install.sh 3.0.32 arch/x86/boot/bzImage System.map "/boot"

查阅arch/x86/boot/install.sh 文件, 它调用/sbin/installkernel ,然后是/sbin/new-kernel-pkg ,接着是/sbin/dracut

通过分析 /sbin/new-kernel-pkg ,其中290行有如下代码

    if [ -n "$dracut" ]; then
        tool="/sbin/dracut $dracuthostonly -f $initrdfile $version"
    else
    tool="/sbin/mkinitrd --allow-missing -f $initrdfile $version"
    fi

其中变量$dracuthostonly的值是 -H ,在dracut参数里与 --hostonly 同义。

问题至此得解。

apache下对目录开启反向代理

需求:有一个apache站点foobar.mysite.net,其中一个目录里的文件与另一站点的某目录内容完全一致。假设该目录为/php, 是一套php程序,因为它使用了cookie,但cookie不能跨域,所以要分别部署在这两个站点下。这里可以通过反向代理,使对站点http://foobar.mysite.net/php/***的访问实际由http://www.mysite.net/php/***处理。

采用如下的设置,相关代码已经加粗着色(如没有着色,请到这里http://blog.path8.net/archives/5989.html阅读)。其中

<VirtualHost *:80>
    DocumentRoot "/var/www/html/vhosts/foobar.mysite.net/html"
    ServerName foobar.mysite.net
    <IfModule mod_php5.c>
        php_admin_value open_basedir "/var/www/html/vhosts/foobar.mysite.net/html/:/tmp"
    </IfModule>
    ProxyPass /php http://www.mysite.net/php  
    ProxypassReverse /php http://www.mysite.net/php 
    ProxypassReverseCookieDomain www.mysite.net foobar.mysite.net
</VirtualHost>

看参考,对指定目录设置反向代理也是可以的,但没有成功,不知哪里有错误,还请高手指教,配置如下。

#<Directory "/var/www/html/vhosts/foobar.mysite.net/html/php">
#    ProxyPass http://www.mysite.net/php
#    ProxypassReverse http://www.mysite.net/php
#    ProxypassReverseCookieDomain www.mysite.net foobar.mysite.net
#    ProxypassReverseCookiePath /php /php
#</Directory>

 

apache代理模块mod_proxy_html,修改html页面内容的url引用链接

参看apache参考手册proxy相关章节时,无意中发现apche有一个模块,可以实现修改代理页面html里的url引用链接,这正是之前想的一个功能,还真的有。apache实在太全面而强大了。

http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_proxy.html#proxypassreverse

apache中有一个第三方模块可以检查并改写HTML中的URL引用,该模块就是Nick Kew编写的mod_proxy_html

http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_proxy.html#proxypassreverse

nginx 1.2.0启用gzip http压缩手记

本站的web在vps上的nginx里跑,之前为简单其见,没有配置http gzip压缩支持,但vps有时网络抽风而速度很慢,于是想起来配置gzip压缩支持。

网上有很多nginx启用gzip压缩的文章,但还是上官方看文档是最权威准确的。这两个页面:

http://wiki.nginx.org/HttpGzipModule
http://wiki.nginx.org/NginxHttpGzipStaticModule

nginx官方文档很易懂,先给一个典型的配置实例,下面再详讲每条指令,感觉相当亲切。

查看ngix编译参考,是否启用了gzip模块,运行命令:

/path/to/binary/nginx -V
(我的nginx在PATH目录里,故命令中可以省略nginx所在的目录),写为nginx -t 即可,下文从略写

注意其中是否 --with-http_gzip_static_module,如果没有,那就自己编译一次吧,下面是我的配置参数,供参考。最后的--add-module=../nginx-lib/nginx-upload-progress-module-v0.9.0/是nginx上传进度模块,nginx第三方模块,源码放置在../nginx-lib/nginx-upload-progress-module-v0.9.0目录,如果你没有下载过该模块,去掉它就可以了。

nginx version: nginx/1.2.0
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/usr/local/conf/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_stub_status_module --with-http_gzip_static_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_random_index_module --with-cpu-opt=pentium4 --add-module=../nginx-lib/nginx-upload-progress-module-v0.9.0/

修改nginx配置文件,nginx配置文件目录参看nginx配置参数里的--conf-path。按我的配置,修改/usr/local/conf/nginx/nginx.conf,在http节点加入gzip配置即可。

    gzip_static on;
    gzip_http_version 1.1;
    gzip_proxied expired no-cache no-store private auth;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;

    gzip on;
    gzip_min_length 1000;
    gzip_types text/plain application/xml text/css text/javascript text/xml;

测试配置是否有语法错误

nginx -t

输出消息

nginx: the configuration file /usr/local/conf/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/conf/nginx/nginx.conf test is successful

确认无误,重新加载nginx配置

nginx -s reload

检测gzip压缩是否正常工作,使用live http headers ——firefox的一款插件,看http头是是否有这样一行:Content-Encoding: gzip

也可以使用firefox的firebug插件 的“网络”功能看,或者使用第三方的在线检测工具,如http://tool.chinaz.com/Gzips/

linux下通过acl配置灵活目录文件权限(可用于ftp,web服务器的用户权限控制)

linux 本身的ugo rwx的权限,对于精确的权限控制很是力不从心的,acl是一个好东西,有了它可以很完美且优雅的控制目录权限。acl的基础知识,这里不再详述,有兴趣可以参看此文(通过实践学习linux ACL基本用法/Linux ACL 体验)

一个很可能遇到的实际问题:

linux下的web站点,该站点开启ftp上传下载;web与ftp以不同的用户运行,分别是web, ftp.

该目录 ./html 结构大致如下

(shell当前目录为/var/www/html, 下同)

$ls
drwxr-xr-x 2 root root 4.0K May  7 07:51 admin
drwxr-xr-x 2 root root 4.0K May  7 07:51 image
drwxr-xr-x 2 root root 4.0K May  7 07:51 lib
drwxrwxrwx 2 root root 4.0K May  7 07:51 upload
-rw-r--r-- 1 root root    0 May  7 07:52 index.php
-rw-r--r-- 1 root root    0 May  7 07:52 config.inc.php

为了web的安全其见,其中

upload目录为web后台上传文件的目录,权限为777;其它文件(目录)权限755(这里使用555也是可以的)

这样web是安全了,但问题也来了

ftp用户就没有写入权限了,将无法通过ftp修改web程序。

如果能实现以下这样的功能就好了:

web用户还是以上权限,不多赋权;但ftp用户可以对这里的所有目录、子目录(及其中文件)都有完全的权限

这种情况下,就要派acl上场了。

对于web用户的权限,保持不变。而针对ftp用户设置几条acl规则:

setfacl -R -m u:ftp:rwx .

大意是,对当前目录 . 递归设置acl规则 u:ftp:rwx ,
u:ftp:rwx这条规则是针对指定用户设定的(u);该用户名为ftp; 权限规则是rwx

翻译成人类语言就是说:给当前目录及其子目录、文件设置acl规则,让用户ftp拥有完全权限。

太简单了,这样就完成搞定了!

差不多了,不过这里还有一个问题,对于以后新建的目录里,ftp用户可能并没有rwx权限,这是为什么呢?因为对于新建目录,它并没有相应的acl规则,而是沿用022的默认umask, 结果就是新文件的755权限。

这里就要用默认acl来实现,简单说来,就是让新建的目录,都自动继承一个默认的acl规则,让ftp用户拥有rwx权限。

setfacl -R -d --set u:ftp:rwx .

还是一条设置acl的命令(setacl); -R 是递归执行,这很简单。重点在 -d --set u:ftp:rwx 上。 -d,指后面是一条default acl规则,规则是  --set u:ftp:rwx, 对当前目录 . 设置规则

用人类的语言讲,就是让所有新建目录都对ftp用户设置rwx的默认权限。

就这样,设置完了。相当简单吧?

回过头来,再看看上面对upload目录设置777的权限,似乎也不并不怎么完美,是不是也可能通过acl规则让web用户拥有rwx的权限?当然可以,其实更好,因为这里的文件是web用户自己创建的,里面的文件所有者应该是web用户,777权限似乎高了点;而且如果这是从其它服务器上迁移过来的站点的话,这些文件的所有者可能还会比较乱。

另外,默认acl,只对以后的新建目录有效,而对已有文件,它并不改变其acl,所以,要同时使用上面所述的两个命令,对已有文件(setfacl -R -m u:ftp:rwx .)和以后的新建目录(setfacl -R -d --set u:ftp:rwx .)设置acl.

上面的acl是针对一个用户web设定的,还可以对一个用户组来设置 g:group_name:rwx , 这样对多用户协作状态下会比较有用。

一段apache虚拟主机的配置代码

一段apache虚拟主机的配置代码,包括了对部分目录禁用php解析,apache日志目录等

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/defsite
#    ServerName unknown-host.example.com
ErrorLog logs/defsite-host.example.com-error_log
CustomLog logs/defsit-host.example.com-access_log common

#    <IfModule mod_php5.c>
#        php_admin_value open_basedir "/var/www/html/vhosts/testsite/html/:/tmp"
#    </IfModule>
#
#    <IfModule suexec.c>
#        SuexecUserGroup web_testsite web_testsite
#    </IfModule>
</VirtualHost>

<VirtualHost *:80>
ServerAdmin tech@mysite.com
DocumentRoot "/var/www/html/vhosts/testsite/html"
ServerName www.testsite.com
ServerAlias job.mysite.com
ErrorLog "logs/testsite-error.log"
CustomLog "logs/testsite-access.log" common
<IfModule mod_php5.c>
php_admin_value open_basedir "/var/www/html/vhosts/testsite/html/:/tmp"
</IfModule>
RewriteLog "/var/www/html/vhosts/testsite/log/rewritelog.log"
</VirtualHost>
<Directory "/var/www/html/vhosts/testsite/html">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all

#AllowOverride AuthConfig  #this line and below is required to auth,
#  AllowOverride has been configured above, no need to re configure
#    AuthName web_testsite
#    AuthType Basic
#    AuthUserFile /var/www/htpasswd/testsite.htpasswd
#    require valid-user
</Directory>
<Directory "/var/www/html/vhosts/testsite/html/images">
AllowOverride None
Options FollowSymLinks
Order allow,deny
php_admin_flag engine off
Allow from all
</Directory>
<Directory "/var/www/html/vhosts/testsite/html/css">
AllowOverride None
php_admin_flag engine off
</Directory>
<Directory "/var/www/html/vhosts/testsite/html/data">
AllowOverride None
php_admin_flag engine off
</Directory>
<Directory "/var/www/html/vhosts/testsite/html/js">
AllowOverride None
php_admin_flag engine off
</Directory>

<VirtualHost *:80>
ServerAdmin tech@mysite.com
DocumentRoot "/var/www/html/vhosts/www2.mysite.com/html"
ServerName www2.mysite.com
ServerAlias job2.mysite.com
ErrorLog "logs/www2.mysite.com-error.log"
CustomLog "logs/www2.mysite.com-access.log" common
</VirtualHost>
<Directory "/var/www/html/vhosts/www2.mysite.com/html">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>

<VirtualHost *:80>
ServerAdmin tech@mysite.com
DocumentRoot "/var/www/html/vhosts/z.mysite.com/html"
ServerName z.mysite.com
ErrorLog "logs/z.mysite.com-error.log"
CustomLog "logs/z.mysite.com-access.log" common
</VirtualHost>
<Directory "/var/www/html/vhosts/z.mysite.com/html">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>

<VirtualHost *:80>
ServerAdmin tech@mysite.com
DocumentRoot "/var/www/html/vhosts/bbs.mysite.net/html"
ServerName bbs.mysite.com
ErrorLog "logs/bbs.mysite.net-error.log"
CustomLog "logs/bbs.mysite.net-access.log" common
</VirtualHost>
<Directory "/var/www/html/vhosts/bbs.mysite.net/html">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>

centos 6.x下的empathy安装包/rpm

直接上安装包

empathy-2.30_rpm_for_centos_f13

fedora13的二进制包,可以在centos 6.2下成功安装,并正常使用。这些包之间解决了包信赖,应该不再需要其它包;如果真的缺少了某个包,请通过yum 安装。

如果你的centos6安装有pidgin,推荐卸载掉,因为有个rpm包与centos6带的pidgin有冲突。

对于使用QQ的朋友,推荐下载安装这个 https://code.google.com/p/libqq-pidgin/ ,empathy/pidgin自带的QQ协议老了,而不再被tx支持。

centOS 6下通过yum安装php-mssql以使php支持microsoft sql server连接

centos 6下,安装fedoraproject的epel-release源,即可以安装php的mssql模块。

注:epel是fedora开发组为centos开发的附加软件yum源,可以弥补centos上游redhat里缺少的软件包。epel的质量还是相当之高的。

[root@c12 html]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
[root@c12 html]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@c12 html]# yum install php-mssql
[root@c12 html]# /etc/init.d/httpd graceful

完成。

phpinfo中可以看到mssql的信息

mssql模块实际还是FreeTDS,其功能主要是在Liunx下能够访问Sybase及MS SQL,官方网站是:http://www.freetds.org/ 。当然也可以手工编译mssql模块到php中,不过通过yum更简单一点。

关于epel源,参看这里 http://fedoraproject.org/wiki/EPEL/zh-cn

本方法来源于centOS 6更新yum以便可裝php-mssql (http://blog.hubin411.com/2011/10/13/centos-6%e6%9b%b4%e6%96%b0yum%e4%bb%a5%e4%be%bf%e5%8f%af%e8%a3%9dphp-mssql/) 阅读该页面请自备梯子。或参看如下转录的核心部分:

tep 1:
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm    //取得rpm檔案

step 2:
# rpm -ivh epel-release-6-5.noarch.rpm    //安裝取得的rpm檔案

step 3:
# yum update    //更新yum的資源庫

step 4:
# yum install php-mssql    //安裝php-mssql

step 5:
# service httpd restart    //重啟apache伺服器