五台机器,一台做nginx,两台MySQL主从,两台web
系统软件环境:centos6.5
php/5.6.40
Apache/2.2.15
mysql/5.6.49
nginx/1.10.3
防火墙关闭,selinux禁用
##都是使用RPM包搭建##
1.首先搭建MySQL主从同步(MySQL5.6)
每台MySQL主机执行:
获取MySQL源:rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
yum clean all;yum repolist
yum list installed |grep mysql
yum repolist all|grep mysql
yum-config-manager --enable mysql56-community
yum-config-manager --disable mysql80-community
yum install mysql-community-server
rpm -qal mysql-community-server
service mysqld start
主库配置:在/etc/my.cnf启用binlog,设置server_id,并且GRANT语句创建复制数据的用户,授予replication slave权限以及授权从库主机
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replicater'@'192.168.4.%' IDENTIFIED BY 'pwd123';
主库执行:show master statusG;
从库配置:在/etc/my.cnf设置server_id要与主库ID不同,然后指定主库信息CHANGE MASTER TO....,最后启动START SLAVE;
- mysql> CHANGE MASTER TO MASTER_HOST='192.168.4.10',
- -> MASTER_USER='replicater',
- -> MASTER_PASSWORD='pwd123',
- -> MASTER_LOG_FILE='dbsvr1-bin.000002', //对应Master的日志文件
- -> MASTER_LOG_POS=334; //对应Master的日志偏移位置
- Query OK, 0 rows affected, 2 warnings (0.12 sec)
从库:show slave statusG;
2.安装Apache httpd+PHP(5.6)
yum list installed |grep httpd
yum install httpd
rpm -qal httpd
service httpd start
yum list installed | grep php
PHP5.6需要安装yum源:rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-pdo php56w-xml php56w-gd php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
yum -y install php56w-fpm
php -v
service php-fpm start
php连接MySQL驱动:https://www.php.net/manual/en/ref.pdo-mysql.php
3.nginx做反向代理
yum install nginx
vim /etc/nginx/nginx.conf
在nginx.conf的http模块中定义后端web:upstream XXX{server web1:80;server web2:80;}
在server模块的location中应用proxy_pass http://XXX;