Linux+Nginx+PHP+MySQL主主

项目之五台服务器实战Linux+Nginx+PHP+MySQL主主
(可以扩展使用MHA|DRBD)+NFS文共享集群架构;
1)部署1台Nginx WEB前端服务器(不能跟PHP-CGI公用);
2)部署2台PHP-CGI网站代码;
3)部署2台MYSQL主主同步架构(可以加入MHA或者DRBD);
4)部署Discuz和WordPress多域名网站,通过两个域名dz.com|wp.com访问;
5)部署1台NFS文件共享服务器,网站代码统一存放在NFS服务器;

安装nginx

安装依赖
yum install -y pcre-devel zlib-devel gcc-c++
下载nginx,解压后进入安装目录进行预编译/编译/安装
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xzf nginx-1.12.2.tar.gz
cd nginx-1.12.2.tar.gz
./configure && make && make install 
启动nginx
/usr/local/nginx/sbin/nginx
关闭防火墙
systemctl stop firewalld
网页访问

在这里插入图片描述

安装php

192.168.9.110
192.168.9.120

源码上传php-5.6.9.tar.gz
解压

tar xzf php-5.6.9.tar.gz

安装依赖:

yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel  mysql-devel gcc-c++

进入解压后的目录

cd php-5.6.9

预编译

 ./configure --prefix=/usr/local/php5  --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-simplexml --enable-xml --disable-rpath --enable-bcmath --enable-soap --enable-zip --with-curl --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --enable-mbstring --enable-sockets --with-gd --with-openssl --with-mhash --enable-opcache --disable-fileinfo --with-gettext
make && make install

复制解压目录文件至安装目录下

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

cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

指定目录权限

chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on

启动

systemctl start php-fpm

整合nginx与php

192.168.9.100
添加index.php文件
源码默认发布网页目录/usr/local/nginx/html下

vim /usr/local/nginx/html/index.php

添加代码:

<?php
phpinfo();
?>
修改nginx配置文件,域名dz.com,新增index.php文件,php转发IP

在这里插入图片描述
重启nginx

/usr/local/nginx/sbin/nginx -s reload

192.168.9.110
192.168.9.120
php服务器新建目录

mkdir -p /usr/local/nginx/html
vim /usr/local/nginx/html/index.php

添加代码:

<?php
phpinfo();
?>

修改php服务器监听及被监听ip

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

在这里插入图片描述

useradd www

重启php

systemctl restart php-fpm
访问测试

windows本地浏览器访问域名测试
修改C:\Windows\System32\drivers\etc下的hosts文件
添加以下配置后保存
192.168.9.100 dz.com wp.com
在这里插入图片描述
在这里插入图片描述

安装mariadb(mysql)及配置mariadb(mysql)主主

两台mysql服务器,首先关闭防火墙及selinux

systemctl stop firewalld
setenforce 0

192.168.9.130
192.168.9.140

yum -y install mariadb mariadb-server
启动mariadb
systemctl start mariadb
设置开机启动mariadb
systemctl enable mariadb
修改配置文件并重启

192.168.9.130

vim /etc/my.cnf

在这里插入图片描述
192.168.9.140
在这里插入图片描述

重启
systemctl restart mariadb
接下来进行MariaDB的相关简单配置

mysql_secure_installation
首先是设置密码,会提示先输入密码

Enter current password for root (enter for none):<–初次运行直接回车

设置密码

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码

其他配置

Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车

Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,

Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车

Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

初始化MariaDB完成,接下来测试登录

mysql -uroot -p密码
mariadb主从配置(主主反向操作一遍)
授权

192.168.9.130

grant replication slave on *.* to'tongbu'@'192.168.9.140'identified by'1';
二进制文件名及位置
show master status;

在这里插入图片描述

链接主库并启动查看192.168.9.140
change master to  master_host='192.168.9.130',master_user='tongbu',master_password='1',master_log_file='mysql-bin.000001',master_log_pos=393;
start slave;
show slave status\G

在这里插入图片描述

分别在两台数据库新建数据库查看是否更新
create database user;
show databases;

192.168.9.130
在这里插入图片描述
192.168.9.140
在这里插入图片描述
192.168.9.140
在这里插入图片描述
192.168.9.130
在这里插入图片描述

安装nfs服务器

yum install nfs-utils rpcbind net-tools lsof
启动rpc服务
systemctl restart rpcbind.service
启动nfs服务
systemctl start nfs.service
配置nfs开机启动
systemctl enable rpcbind
systemctl enable nfs
修改配置文件
vim /etc/exports
/data 172.168.0.0/24(rw,sync,fsid=0) 192.168.9.0/24(rw,sync,fsid=0)
创建共享目录并授权
mkdir -p /data
chown nfsnobody.nfsnobody /data
重新加载nfs
exportfs -rv

######查看nfs挂载情况

showmount -e localhost

客户端安装nfs

yum install nfs-utils rpcbind
启动并设置开机自动启动
systemctl start rpcbind.service
systemctl start  nfs.service
systemctl enable rpcbind.service
systemctl  enable  nfs.service
挂载并设置自动挂载
mount -t nfs 192.168.9.100:/data /data
 vi /etc/fstab
 192.168.9.100:/data      /data    nfs    nolock   0 0
新建发布目录并通过挂载目录进行发布

192.168.9.100

mkdir /data/dz.com
mkdir /data/wp.com
挂载(分别在192.168.9.100/192.168.9.110/192.168.9.120执行挂载)
mount -t nfs 192.168.9.100:/data /usr/local/nginx/html
上转网站安装包并解压至指定目录

Discuz_X3.2_SC_UTF8.zip
wordpress-4.9.4.zip

cd /data/wp.com
unzip wordpress-4.9.4.zip
mv wordpress .
cd /data/dz.com
unzip Discuz_X3.2_SC_UTF8.zip
mv upload .

修改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf
    server {
        listen       80;
        server_name  dz.com;
        location / {
            root   html/dz.com/;
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           html/dz.com/;
            fastcgi_pass   192.168.9.120:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
     server {
        listen       80;
        server_name  wp.com;
        location / {
            root   html/wp.com/;
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           html/wp.com/;
            fastcgi_pass   192.168.9.110:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

在这里插入图片描述

网页访问

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
安装discuz,报错没有权限
在这里插入图片描述

cd /data/dz.com
chmod 757  -R  data/  uc_server/  config/  uc_client/
再次刷新正常,下一步

在这里插入图片描述
在这里插入图片描述

提示需要连接数据库,新建数据库及授权远程访问,通过本地域名重定向访问mysql

192.168.9.130或者192.168.9.140

create database discuz charset=utf8;
grant all privileges on *.* to 'discuz'@'192.168.9.100' identified by '1' with grant option;
create database wordpress charset=utf8;
grant all privileges on *.* to 'wordpress'@'192.168.9.100' identified by '1' with grant option;

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值