我爱linux

我是一个linux运维从业者,这个网站记录一些平时调试linux相关文档及生活随笔

Archive for the ‘mysql’ tag

ubuntu修改mysql数据库路径

without comments

ubuntu的mysql默认数据库存放路径是/var/lib/mysql,但如果是只在/etc/mysql/my.cnf,显然不起作用。

如果要修改这个路径,方法如下:
1. mv /var/lib/mysql /data/
2. 一般来说,mv之后权限是保持的,但可以修改确保无误。 chown -R mysql:mysql /data/mysql
3. vi /etc/mysql/my.cnf 把 datadir 那行改为 datadir = /data/mysql
4. vi /etc/apparmor.d/usr.sbin.mysqld

/var/lib/mysql r,
/var/lib/mysql/** rwk,
中的 /var/lib/mysql 改为新的路径,也就是 /data/mysql
5. 重启服务
/etc/init.d/apparmor restart
/etc/init.d/mysql restart
折腾完毕。

Written by zhangweibo

十二月 26th, 2012 at 10:36 下午

Posted in Mysql,ubuntu

Tagged with ,

轻松获取nginx apache mysql php的编译参数

without comments

轻松获取nginx apache mysql php的编译参数

由于工作的需要,有时候需要在一台不是你参与编译的环境调试环境,这就需要知道nginx,apache,mysql,php的编译参数,以下小方法能快速让你了解默认的服务器里的编译参数。

 

查看获取nginx的编译参数

li384-194:~# /usr/local/nginx/sbin/nginx -V
nginx: nginx version: nginx/1.0.8
nginx: built by gcc 4.3.2 (Debian 4.3.2-1.1)
nginx: configure arguments: –user=www-data –group=www-data –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_gzip_static_module

 
查看获取apache的编译参数

[root@www ~]# cat /usr/local/apache2/build/config.nice
#! /bin/sh
#
# Created by configure

“./configure” \
“–prefix=/usr/local/apache2″ \
“–enable-so” \
“–enable-modules=all” \
“–enable-mods-shared=all” \
“–enable-layout=Apache” \
“–enable-ssl=static” \
“–with-ssl=/usr/local/openssl” \
“–enable-rewrite” \
“–enable-suexec” \
“–with-suexec-logfile=/www/logs/suexec.log” \
“–with-suexec-uidmin=500″ \
“–with-suexec-gidmin=100″ \
“–with-suexec-caller=nobody” \
“–with-suexec-docroot=/www” \
“$@”

 
查看获取mysql的编译参数
[root@www ~]# grep configure /usr/local/mysql4/bin/mysqlbug
# This is set by configure
CONFIGURE_LINE=”./configure ‘–prefix=/usr/local/mysql4′ ‘–sysconfdir=/etc’ ‘–enable-assembler’ ‘–without-debug’ ‘–with-client-ldflags=-all-static’ ‘–with-mysqld-ldflags=-all-static’ ‘–localstatedir=/www/mysql’ ‘–with-big-tables’ ‘–with-low-memory’ ‘–with-extra-charsets=all’ ‘–enable-thread-safe-client’ ‘–with-pthread’ ‘–with-unix-socket-path=/tmp/mysql.sock’”

 

 

参看获取php的编译参数

-extra-charsets=all’ ‘–enable-thread-safe-client’ ‘–with-pthread’ ‘–with-unix-socket-path=/tmp/mysql.sock’”
[root@www ~]# /usr/local/php5/bin/php -i |grep configure
Configure Command => ‘./configure’ ‘–prefix=/usr/local/php5′ ‘–enable-exif’ ‘–enable-mbstring’ ‘–with-iconv’ ‘–with-curl=/usr’ ‘–with-gdbm’ ‘–with-gettext’ ‘–enable-calendar’ ‘–enable-magic-quotes’ ‘–enable-wddx’ ‘–enable-ftp’ ‘–enable-inline-optimization’ ‘–with-gd=/usr/local’ ‘–with-zlib’ ‘–enable-gd-native-ttf’ ‘–with-t1lib=/usr/local’ ‘–with-zlib-dir=/usr’ ‘–with-ttf’ ‘–with-freetype-dir=/usr’ ‘–with-gd’ ‘–with-png-dir=/usr’ ‘–with-jpeg-dir=/usr’ ‘–with-mysql=/usr/local/mysql4′ ‘–enable-force-cgi-redirect’ ‘–with-apxs2=/usr/local/apache2/bin/apxs’ ‘–with-pdo-mysql=/usr/local/mysql4′ ‘–enable-sockets’ ‘–with-openssl=/usr/local/openssl’

 

Written by zhangweibo

十二月 19th, 2012 at 8:42 下午

Posted in apache,Mysql,nginx,Php

Tagged with , , , , ,

mysql的master/slave实战指南

without comments

mysql的master/slave 实战指南

A:192.168.1.1 master

B:192.168.1.2 slave

 

1:确保A和B的mysql版本尽量一致,如果版本不一致可能会有问题,特别是从新的版本复制到旧的版本

2:master主机配置:

a:建复制权限指定账号

CREATE USER ‘repl_user’@’192.168.1.2′;

GRANT REPLICATION SLAVE , REPLICATION CLIENT ON * . * TO ‘repl_user’@’192.168.1.2′ IDENTIFIED BY ’123456′;

b:修改my.cnf

//至少要有server-id、与log-bin两项

server-id = 1
log-bin = /www/logs/mysql-bin
log-error = /www/logs/mysql-bin.err
binlog_ignore_db = mysql //忽略复制的数据库
c:
mysql> FLUSH TABLES WITH READ LOCK;

锁定数据库的写操作

d:创建A主机的数据库快照,可以用二进制备份方法,比如tar命令
shell> tar zcf /tmp/backup.tar.gz /var/lib/mysql

e:mysql > SHOW MASTER STATUS;
记录日志名和偏移量后,以后从服务器从那个偏移量开始复制

f:mysql> UNLOCK TABLES;

重启数据库写活动
3:slave主机配置

a:修改my.cnf

server-id = 2
master-host = 192.168.1.1
master-user = repl_user
master-password = 123456
master-port = 3306
slave-skip-errors = all

b:前期工作:先用备份导出命令把master主机的数据库copy一份到slave主机上

 

C: 然后先重启master,再重启slave主机

常用命令

mysql> slave stop;
mysql> slave start;
mysql> show slave status\G

 

FAQ:

1:复制遇到Duplicate Entry on key” 这个错误的解决方法

修改my.cnf

slave-skip-errors=all

或者单独跳过某个命令

mysql>slave stop;

mysql>set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;

mysql>slave start;

 

2:ERROR 29 (HY000): File ‘/var/lib/mysql/mysql-relay-bin.index’ not found (Errcode: 13)

备注:执行shell命令工具 perror 13 会告诉你是无访问权限

因权限问题出错,那么就必须为中继日志文件目录变更权限信息,命令为:
chown mysql:mysql /var/lib/mysql/mysql-relay-bin.index

chmod 660 /var/lib/mysql/mysql-relay-bin.index

 

3: Error (Code 1201): Could not initialize master info structure; more error messages can be found in the MySQL error log

故障的原因是生成了一个0KB的空文件master.info,正式因为这个文件导致mysqld提示复制无法初始化主数据库服务器的信息

直接删除0字节文件:rm -f /var/lib/mysql/master.info,再充型执行CHANAGE MASTER TO 命令,复制搭建成功,且生成了记录主数据库服务器信息的master.info文件。

 

Written by zhangweibo

九月 25th, 2012 at 10:47 上午

Posted in Mysql

Tagged with , ,

Debian 6(Squeeze)编译搭建shopex或ecshop环境

without comments

Debian 6(Squeeze)编译搭建shopex或ecshop环境 Nginx+php5.2.x+Mysql+ZendOptimizer

shopex环境目前只支持php5.2.x,是因为它只支持Zend Optimizer,高版本的Zend Guard是不支持的, 而debian 6 默认安装php是5.3.x,这个版本的php是不支持Zend Optimizer,只支持Zend Guard.所以很矛盾呀,要想使用shopex系统,要么使用debian5 ,但又纠结于想用更高版本的debian6 ,所以我们这里讲述如何在debian6 系统上手动编译安装 支

shopex环境的搭建。真是没办法,老实说不愿破坏debian自带的软件包管理系统

一、安装nginx

添加nginx源 vi /etc/apt/sources.list

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

apt-get update
apt-get install nginx

这样我们就能升级到最新稳定版本的nginx,截至目前是1.0.10

二、安装mysql-server及编译所需库文件

apt-get install mysql-server libmysqlclient15-dev

三、编译安装php5.2.x

准备php编译所需的依赖包

aptitude install libgd2-noxpm-dev libxml2-dev libcurl3-dev libmhash-dev libmcrypt-dev libxslt-dev libpspell-dev libbz2-dev libglobus-openssl-dev

安装编译环境

apt-get install build-essential

下载php3.2.17
wget http://am.php.net/distributions/php-5.2.17.tar.gz

下载php-fpm补丁
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -d php-5.2.17-fpm-0.5.14.diff.gz

tar zvxf php-5.2.17.tar.gz

cd php-5.2.17
patch -p1 < ../php-5.2.17-fpm-0.5.14.diff

./configure –prefix=/usr/local/php5 –with-iconv –with-zlib –enable-xml –enable-fastcgi –enable-fpm –with-curl –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-mhash –enable-sockets –with-xmlrpc –enable-zip –with-mysql –with-mysqli –enable-ftp –with-jpeg-dir –with-freetype-dir –with-png-dir –enable-bcmath –enable-calendar –enable-exif –with-openssl –with-bz2

make
make install

cp php.ini-dist /usr/local/php5/lib/php.ini

vi /usr/local/php5/etc/php-fpm.conf

去掉前面的注释

<value name=”user”>nobody</value>
<value name=”group”>nogroup</value>

ln -s /usr/local/php5/sbin/php-fpm /etc/init.d/php-fpm

/etc/init.d/php-fpm start

修改默认主机的配置:

vi /etc/nginx/conf.d/default.conf

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

注意:/usr/share/nginx/html$fastcgi_script_name; 前面的目录是默认主目录的位置,请根据你自己的实际情况修改,默认从nginx.org源安装的nginx最新版本,默认主目录

是/usr/share/nginx/html

/etc/init.d/nginx restart

好了,写个info文件,测试一下nginx+php+mysql是否完美结合了:)

四、安装ZendOptimizer

下载ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz,这是ZendOptimizer的最后一个版本了,也是shopex和ecshop能支持的ZendOptimizer,更高的版本是ZendGuardLoader,

但目前shopex等都不支持呀,非常让人纠结,要不今天我们也不会写这篇文章指导大家搭建合适的环境。

make /usr/local/zend
把解压后的so文件,拷贝到刚才建立的目录
vi /usr/local/php5/lib/php.ini
增加:
zend_extension= /usr/local/zend/ZendOptimizer.so

重启一下 php-fpm 应该马上生效了

自此,shopex或者ecshop的安装环境已经搭建成功。

后续:

五、加入memcache支持

aptitude install memcached

apt-get install m4 autoconf

wget http://pecl.php.net/get/memcache-2.2.6.tgz
tar zvxf memcache-2.2.6.tgz

cd memcache-2.2.6

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-memcache –with-php-config=/usr/local/php5/bin/php-config –with-zlib-dir
make
make install

Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/

修改php.ini
vi /usr/local/php5/lib/php.ini

增加下面4句

extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”
extension = memcache.so
memcache.chunk_size = 32768
memcache.hash_strategy = consistent

一般教程都是只加上面2句,建议把下面2句也加上,修改一下默认的一些参数,使memcache的使用性能更加有效率

六、加入eAccelerator支持

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1

/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519

./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php5/bin/php-config
make
make install

修改php.ini
vi /usr/local/php5/lib/php.ini

extension=”eaccelerator.so”
eaccelerator.shm_size=”32″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.keys = “disk_only”
eaccelerator.session = “disk_only”
eaccelerator.content = “disk_only”

保存

make /var/cache/eaccelerator
chmod -R 777 /var/cache/eaccelerator

因为之前安装memcache,已经加了extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”,所以安装eaccelerator就不加这句了,如果实际操作

中没装memcache,那就需要在php.ini中加入这句,或者直接指定eaccelerator.so的绝对路径

重启一下 php-fpm 应该马上生效了

Written by zhangweibo

十二月 10th, 2011 at 5:03 上午