Archive for category LAMP

MySQL Replication Tips

MySQL的Replication已经很成熟了。下面总结一下生产中的一些小技巧

1、从Master上来过滤一些数据库,即忽略test,scratch数据库,不进行Rep
binlog-ignore-db=test,scratch
或者
binlog-ignore-db=test
binlog-ignore-db=scratch

2、如果只想同步某一或几个数据库,可以只制定需要Repl的数据库名
binlog-do-db=catalog
binlog-do-db=users
binlog-do-db=sessions

3、如果某些SQL语句导致Repl出现问题,可以使用如下方法:
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
SLAVE START SQL_THREAD;

4、从Slaves上过滤数据库,只同步某一些数据库(users)。
replicate-do-db=users
阻止temporary数据库同步的设置方法:
replicate-ignore-db=temporary

No Comments

Apache之userdir

Apache有个userdir的模块

http://httpd.apache.org/docs/2.2/howto/public_html.html

以前没用过,想用一下,可是就是很403,日志也是简单的
Permission denied: access to /~username denied

后来在另一台用yum安装的服务器上找到答案。
# The path to the end user account ‘public_html’ directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a “403 Forbidden” message.

具体操作过程就是 
#chmod -R 711 /home/*
#cd /home/username/
#chmod 755 -R public_html

一切正常了。

No Comments

读书计划之笔记1

Building Scalable Web Sites

1、To get started designing and building your first large-scale web application, you’ll need four things.
a. An idea
b. Find some people to build it
c. The most important thing you need is a method of discussing and recording the development process
d. With pens and Wiki in hand, we can start to design our application architecture and then start implementing our world-changing application. Read the rest of this entry »

No Comments

MySQL Sandbox(沙盒)

Sandbox (computer security), a virtual container in which untrusted programs can be safely run
Sandbox (software development), an online environment in which code or content changes can be tested without affecting the original system –From Wikipedia, the free encyclopedia
沙盒:在这里理解为一个模拟的容器,可以安全运行,而不影响其他程序(MySQL)

官方网站:http://launchpad.net/mysql-sandbox/
使用MySQL Sandbox可以测试一些新老的MySQL特性,而不影响系统和已经运行的程序
使用说明:

http://forge.mysql.com/wiki/MySQL_Sandbox

经过测试,感觉不错,只需要下载Mysql_sandbox和MySQL源码包,就可以了。
比较适合想测试MySQL一些特殊功能的朋友。

No Comments

mysql.sock引发的问题

有人装wordpress,出现数据库连接错误。
排除帐号密码错误,并且通过php直接测试也没问题。

取消wp-db.php 里面的@符号(显示详细错误)竟然它在连接/var/lib/mysqld/mysqld.sock
而系统中的是/tmp/mysql.sock

奇怪了,为什么不连localhost而直接去找sock连呢?
最后ln -s /tmp/mysql.sock /var/lib/mysqld/mysqld.sock 解决。

1 Comment

mysqlbinlog的日志

mysql的一些事件都以binary的格式存贮,通过mysqlbinlog这个工具来实现的。
mysqlbinlog可以用于Replication和数据库的恢复
这里主要是说一下mysqlbinlog日志的清理

mysqlbinlog日志的清除
mysql -uroot
PURGE {MASTER | BINARY} LOGS TO ‘log_name’
PURGE {MASTER | BINARY} LOGS BEFORE ‘date’
用于删除列于在指定的日志或日期之前的日志索引中的所有二进制日志。这些日志也会从记录在日志索引文件中的清单中被删除,这样被给定的日志成为第一个。
eg:
PURGE MASTER LOGS TO ‘mysql-bin.030′;
PURGE MASTER LOGS BEFORE ’2009-01-10 11:00:00′; Read the rest of this entry »

No Comments

php curl参数

<?php

$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $_GET['q']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$handles = curl_exec($ch);
curl_close($ch);

echo $handles;

?>

注: curl函数参考 Read the rest of this entry »

No Comments

mysql数据表损坏修复方法(来自网络)

当你试图修复一个被破坏的表的问题时,有三种修复类型。如果你得到一个错误信息指出一个临时文件不能建立,删除信息所指出的文件并再试一次–这通常是上一次修复操作遗留下来的。

这三种修复方法如下所示:

% myisamchk –recover –quick /path/to/tblName
% myisamchk –recover /path/to/tblName
% myisamchk –safe-recover /path/to/tblName Read the rest of this entry »

No Comments

关于crontab的一点补充

使用crontab定时执行,如果网上搜索每N分钟执行一次,估计会搜到很多 */N * * * *

今天在做东西的时候才发现这是不对的,只有在 N <= 30 的情况下才能成立

* 代表  0-59

而当 */N 是整除是才能执行,比如N=45 那么只有在 1:00 1:45 2:00 2:45执行

因为只有0,45才能整除

因此如果要每45分钟执行一次,需要计算。

0   */3 * * * root /srv/urscript
45  */3 * * * root /srv/urscript
30  1,4,7,10,13,16,19,22 * * * root /srv/urscript
15  2,5,8,11,14,17,20,23 * * * root /srv/urscript

No Comments

优化Apache

硬件上的优化就不用说,花银子买了。呵呵
软件上的说一下吧
系统级别上:
1. 关掉不需要的服务,一方面是安全,还就是优化了。
2. 保持软件更新,也是安全和优化方面的事。
vi /etc/sysctl.conf
# Use TCP syncookies when needed
net.ipv4.tcp_syncookies = 1
# Enable TCP window scaling
net.ipv4.tcp_window_scaling = 1
# Increase TCP max buffer size
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# Increase Linux autotuning TCP buffer limits
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# Increase number of ports available
net.ipv4.ip_local_port_range = 1024 65000 Read the rest of this entry »

No Comments