RHEL5搭建apache服务器全过程(三)MySQL实时同步以及pdo_Mydql的安装

1、在web1和web2上导入数据库和网页目录,并进行数据库实时同步的配置

放置网页目录及导入数据库:

[root@web1 Desktop]# mv eyo /usr/local/apache2/htdocs/
[root@web1 Desktop]# vim /usr/local/apache2/htdocs/eyo/data/config.php

// database password
$db_pass   = "redhat";
[root@web1 Desktop]# mysql -u root -p eyo < eyo.sql (需先创建eyo数据库,此步骤可以只在一台服务器上执行,实时同步配置成功后,另一台服务器会自动同步)
 

配置数据库实时同步:

192.168.0.223web1)上的配置:

[root@web1 Desktop]# vim /etc/my.cnf

 49 log-bin=mysql-bin
 54 server-id       = 1
 55 binlog-do-db=eyo
 56 binlog-ignore-db=mysql
 57 binlog-ignore-db=test
 58 log-slave-updates
 59 slave-skip-errors

[root@web1 Desktop]# service mysqld restart
[root@web1 Desktop]# mysql -u root -p

Enter password:
mysql> grant replication slave on *.* to [email protected] identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;记录FilePosition,从库设置将会用到
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |       98 | eyo          | mysql,test       |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

 

192.168.0.224web2)上的配置:

[root@web2 ~]# vim /etc/my.cnf
49 log-bin=mysql-bin
54 server-id       = 2(注意必须和web1上的不一样)
94 master-host     =   192.168.0.223
98 master-user     =   slave
102 master-password =   123456
106 master-port     =  3306
107 replicate-do-db=eyo
108 replicate-ignore-db=mysql
109 replicate-ignore-db=test
110 master-connect-retry=60
111 log-slave-updates

[root@web2 ~]# service mysqld restart
[root@web2 ~]# mysql -u root -p

Enter password:
mysql> slave stop;
Query OK, 0 rows affected (0.00 sec)

设置连接MASTER MASTER_LOG_FILE为主库的FileMASTER_LOG_POS为主库的Position:

mysql> CHANGE MASTER TO MASTER_HOST='192.168.0.223',MASTER_USER='slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000004',MASTER_LOG_POS=98;
Query OK, 0 rows affected (0.01 sec)

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.0.223
                Master_User: slave
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000004
        Read_Master_Log_Pos: 98
             Relay_Log_File: web2-relay-bin.000002
              Relay_Log_Pos: 235
      Relay_Master_Log_File: mysql-bin.000004
           Slave_IO_Running: Yes(必须是YES)
          Slave_SQL_Running: Yes(必须是YES)
            Replicate_Do_DB: eyo
        Replicate_Ignore_DB: mysql,test
         Replicate_Do_Table:
     Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 98
            Relay_Log_Space: 235
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: 0
1 row in set (0.00 sec)

显示上面的结果就代表同步成功,如果出现问题,可以删除/usr/local/mysql/var目录下面的master.info、relay-log.info再重启mysql服务

mysql>  UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)

注意:数据实时同步的配置就是在web1web2上重复上面彼此的配置,也就是说先完成以上的配置,然后把上面的配置反过来,在web1和web2上分别配置一次。但配置条目需要注意顺序,master的配置必须放在前面,slave的配置必须放在后面。以上配置只是配置了名为eyo数据库的实时同步,可以在此数据库中新建表格进行验证

 

附:以上网页是利用ecshop开发,如果是利用magento开发出的网页,则有一些附加的配置,下面只在web1上进行实验

[root@web1 Desktop]# mv goego /usr/local/apache2/htdocs/
 

如果此时访问http://192.168.0.223/goego/将会出现以下报错:

 

解决办法:

[root@web1 Desktop]# cd /usr/local/apache2/htdocs/goego/errors/
[root@web1 errors]# cp local.xml.sample local.xml

再次访问http://192.168.0.223/goego/将会出现以下报错:

 

解决办法:安装pdo_mysql

[root@web1 Desktop]# tar zxvf PDO_MYSQL-1.0.2.tgz
package2.xml
PDO_MYSQL-1.0.2/config.m4
PDO_MYSQL-1.0.2/CREDITS
PDO_MYSQL-1.0.2/mysql_driver.c
PDO_MYSQL-1.0.2/mysql_statement.c
PDO_MYSQL-1.0.2/pdo_mysql.c
PDO_MYSQL-1.0.2/php_pdo_mysql.h
PDO_MYSQL-1.0.2/php_pdo_mysql_int.h
PDO_MYSQL-1.0.2/php_pdo_mysql_sqlstate.h
package.xml
[root@web1 Desktop]# cd PDO_MYSQL-1.0.2
[root@web1 PDO_MYSQL-1.0.2]# /usr/local/php5/bin/phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519


[root@web1 PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php5/bin/php-config

执行后会报错:

configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for MySQL support for PDO... yes, shared
checking for mysql_config... not found
configure: error: Cannot find MySQL header files under

解决办法:

[root@web1 PDO_MYSQL-1.0.2]# cp /usr/local/mysql/bin/mysql_config /usr/bin/
[root@web1 PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php5/bin/php-config

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
 

[root@web1 PDO_MYSQL-1.0.2]# make


执行后会报错:

/root/Desktop/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:36: error: expected specifier-qualifier-list before 'MYSQL'
/root/Desktop/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:48: error: expected specifier-qualifier-list before 'MYSQL_FIELD'
/root/Desktop/PDO_MYSQL-1.0.2/php_pdo_mysql_int.h:53: error: expected specifier-qualifier-list before 'MYSQL_RES'
make: *** [pdo_mysql.lo] 错误 1

解决办法:利用本地系统光盘yum仓库安装mysql-devel(配置yum仓库不再赘述)

[root@web1 yum.repos.d]# yum -y install mysql-devel
 

此时如果直接执行make,仍然会报错,需再配置一次再执行make:

[root@web1 PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php5/bin/php-config

[root@web1 PDO_MYSQL-1.0.2]# make
 

[root@web1 PDO_MYSQL-1.0.2]# make install
Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/
 

执行make install后,需记住屏幕上回显的长串路径,等下会用到

[root@web1 PDO_MYSQL-1.0.2]# vim /usr/local/php5/php.ini 

 486 extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/"

 592    extension=pdo_mysql.so

 625 extension=php_mysql.dll
 

必须重启apache服务:

[root@web1 PDO_MYSQL-1.0.2]# /usr/local/apache2/bin/apachectl restart
 

再次访问http://192.168.0.223/goego/将出现以下报错:

解决办法:

[root@web1 ~]# mkdir /var/lib/mysql
[root@web1 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

 

再次访问http://192.168.0.223/goego/将出现以下报错:

 

解决办法: 设置数据库连接密码

[root@web1 ~]# vim /usr/local/apache2/htdocs/goego/app/etc/local.xml


                          <host><![CDATA[localhost]]></host>
                                        <username><![CDATA[root]]></username>
                                        <password><![CDATA[redhat]]></password>
                                        <dbname><![CDATA[goego]]></dbname>
                                        <active>1</active>
 

最后将goego数据库导入到localhost,有可能SQL语句里面设置了自动跳转的IP地址,可以将其修改为你实际的IP地址即可

[root@web1 ~]# vim Desktop/goego.sql
进行全局替换:

:%s/192.168.0.200/192.168.0.223/g

[root@web1 ~]# mysql -u root -p goego < Desktop/goego.sql (需要先创建goego数据库)
 

有需要SQL语句以及实验用网页的朋友请联系我:QQ  4427851

 

 

你可能感兴趣的:(apache,mysql,lamp,rhel5,pdo_mysql)