作者:蘑菇
今天在本本上装了个mysql主从库配置,中间遇到了几个问题,不过经过搜寻资料,已经可以正常工作了。
过程写下来做个记录:
因为上次已经装过LNMP,所以只要再装一个mysql做从库就好了。重新编译mysql安装
$ tar -zxvf mysql-5.1.45.tar.gz
$ cd mysql-5.1.45
$ ./configure --prefix=/usr/local/mysql_slave --enable-assembler --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-embedded-server --with-ssl -enable-local-infile
$ make && make install
$ cd ..
$ mkdir /usr/local/mysql_slave/var
$ chown -R mysql:mysql /usr/local/mysql_slave/var
$ chgrp -R mysql /usr/local/mysql_slave
#发现/usr/local/mysql_slave/var/下的mysql和test的组均为root,修改其属组
$ chgrp -R mysql /usr/local/mysql_slave
#修改my.cnf位置
$ cp /usr/local/mysql_slave/share/mysql/my-medium.cnf /etc/my-slave.cnf
$ vi /etc/my-slave.cnf
$ :s/3306/3308/g
$ :s/tmp\/mysql.sock/tmp\/mysql-slave.sock/g
$ /usr/local/mysql_slave/bin/mysqld_safe --defaults-file=/etc/my-slave.cnf --user=mysql &
$ /usr/local/mysql_slave/bin/mysqladmin -uroot password 123456
配置主从库:
#创建mysql日志目录
$ mkdir /var/log/mysql
$ chown -R mysql:mysql /var/log/mysql
[vi /etc/my.cnf]
server-id=1
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=test
binlog_ignore_db=mysql
[vi /etc/my-slave.cnf]
server-id=2
master-host=127.0.0.1
master-user=slave_usr
master-password=123456
master-port=3306
replicate-do-db=test
#启动测试:
$ /etc/init.d/mysql start
$ mysql -uroot -p123456
mysql > grant replication slave on *.* to 'slave_usr'@'127.0.0.1' identified by '123456';
mysql > exit;
$
$ /usr/local/mysql_slave/bin/mysqld_safe --defaults-file=/etc/my-slave.cnf --user=mysql &
$
#进入主库创建表
$ mysql -uroot -p123456
mysql > use test;
mysql > create table test(`id` int primary key auto_increment, `introtext` text);
mysql > exit;
$ mysql -uroot -p123456 -P3308 -h127.0.0.1
mysql > use test;
mysql > desc test;
我们会发现从库里创建了一个和主库一样的表。成功!
但是还有以下几个问题:
1.把/usr/local/mysql_slave/share/mysql/mysql.server拷贝到/etc/init.d/mysql-slave,但是无法用/etc/init.d/mysql-slave start启动从库。我改了pid,socket,datadir,basedir,启动也加了--defaults-file,但是没有成功,还要继续检查。
2.登录从库时必须加-h127.0.0.1,不知道怎么去掉这个选项。
CentOS + Nginx + PHP + MySQL 环境搭建
一、软件环境
CentOS 5.4 :
Nginx 0.8 : http://nginx.org/download/nginx-0.8.35.tar.gz
PHP 5.2.10 : http://www.eduicc.com/soft/php-5.2.10.tar.gz
MySQL 5.4.15 : http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz/from/http://mysql.ntu.edu.tw/
二、安装
1. 准备工作
这一步我称它为“准备工作”,其实是安装一些系统编译及其他环境
yum -y install patch make gcc gcc-c++ gcc-g77 flex bison libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
#安装编码格式转换库
wget http://www.eduicc.com/soft/libiconv-1.13.tar.gz
tar -zxvf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure --prefix=/usr/local
make && make install
cd ..
#安装libmcrypt库
wget http://www.eduicc.com/soft/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
ldconfig
cd libltdl
./configure --enable-libltdl-install
make && make install
cd ../../
#安装php-mhash扩展库
wget http://www.eduicc.com/soft/mhash-0.9.9.9.tar.gz
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
cd ..
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
wget http://www.eduicc.com/soft/mcrypt-2.6.8.tar.gz
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd ..
2. 安装MySQL
cd mysql-5.1.54
./configure --prefix=/usr/local/mysql --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install
cd ..
#添加mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.
#设置mysql开机自启动
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --level 345 mysql on
#增加mysql动态链接库文件
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
#添加root密码
/etc/init.d/mysql start
/usr/local/mysql/bin/mysqladmin -u root password root
/etc/init.d/mysql restart
/etc/init.d/mysql stop
#去掉mysql集群服务
chkconfig mysql-ndb off
chkconfig mysql-ndb-mgm off
3. 安装PHP
#我们用php-fpm来管理fastcgi
wget http://www.eduicc.com/soft/php-5.2.10-fpm-0.5.11.diff.gz
tar -zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
! 这里我们要先将autoconf降低版本,否则可能会出现: buildconf: Your version of autoconf likely contains buggy cache code.
yum -y install autoconf213
export PHP_AUTOCONF=/usr/bin/autoconf2.13
cd php-5.2.10
./buildconf --force
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-ftp --without-pear
make ZEND_EXTRA_LIBS='-libiconv'
make install
cp php.ini-dist /usr/local/php/etc/
4. 安装nginx
#安装pcre (Perl Compatible Regular Expressions正则表达式库)
wget http://www.eduicc.com/soft/pcre-7.9.tar.gz
tar -zxvf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make && make install
cd ..
tar -zxvf nginx-0.8.35.tar.gz
cd nginx-0.8.35
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
#有关nginx.conf和php-fpm.conf的配置可以参照:nginx.conf 和 php-fpm.conf
5. 测试
我们先来写一个脚本
vi /etc/init.d/run
写入以下内容
ulimit -SHn 51200
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
启动测试:
chown 0755 /etc/init.d/run
/etc/init.d/run
/etc/init.d/mysql start
好了,在/var/www/localhost下写个phpinfo测试下吧!
转载于:https://blog.51cto.com/soulful/466796