ToB企服应用市场:ToB评测及商务社交产业平台
标题:
Web 前端接纳 Nginx+Keepalived 作负载均衡器后端wordpress接纳 MySQL数据
[打印本页]
作者:
瑞星
时间:
2024-9-1 14:57
标题:
Web 前端接纳 Nginx+Keepalived 作负载均衡器后端wordpress接纳 MySQL数据
原理:
使用keepalived+Nginx实现高可用以及负载均衡,后台wordpress+php毗连mysql主从复制实现数据同步
一、环境预备 192.168.96.34 主机 192.168.96.35 备机 192.168.96.36 192.168.96.37 192.168.96.38 做MySQL、nginx后台、以及word press、PHP 二、根本框架
三、主机配置 添加一个虚拟IP即VIP ip addr add 192.168.96.110/32 dev ens33 永世VIP nmcli con mod ens33 +ipv4.addr 192.168.96.110/32 systemctl restart network 安装keepalived和nginx #安装依赖包 yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel #yum安装软件 yum install -y keepalived yum install -y nginx
vim /etc/keepalived/keepalived.conf
配置nginx负载均衡: vim /etc/nginx/conf.d/nginx.conf
配置/etc/hosts 192.168.96.110 www.test.com 保存并重启nginx systemctl restart nginx 配置keepalived高可用 vim /etc/keepalived/nginx_check.sh
chmod a+x nginx_check.sh 给脚本加权限,并重新启动keepalived systemctl restart keepalived 四、备机配置 备机也安装keepalived和nginx(安装装过程同上) vim /etc/keepalived/keepalived.conf
vim /etc/nginx/conf.d/nginx.conf
备机同样编写脚本(同上)并加x权限之后重启keepalived
自此主机备机配置完毕。
六、配置mysql主从复制
给三台服务器分别安装mysql,nginx 安装mysql 先卸载mariadab: rpm -qa | grep maria rpm -e mariadb-libs-5.5.68-1.el7.x86_64 rpm -e postfix-libs-5.5.68-1.e17.x86_64 rpm -e mariadb-libs-5.5.68-1.el7.x86_64 rpm -qa | grep maria rpm安装MySQL tar xf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar -C /opt (mysql包在D盘linux笔记里) cd /opt yum localinstall * 启动MySQL systemctl start mysqld 登录MySQL grep "password" /var/log/mysqld.log 得到密码后输入下令 mysql -uroot -p 修改密码: alter user 'root'@'localhost' identified by 'Xing@123'; 配置MySQL主库(192.168.96.36): create database wordpress; 创建用户,授权,革新权限 create user 'wordpress'@'localhost' identified by ‘Xing@123'; grant all privileges on wordpress.* to 'wordpress'@'localhost'; flush privileges; vim /etc/my.cnf
show master status\G 配置MySQL从库:(192.168.96.37、38) vim /etc/my.cnf
登录 MySQL 并配置从服务器毗连到主服务器: CHANGE MASTER TO MASTER_HOST='192.168.96.36', MASTER_USER='epl_user', MASTER_PASSWORD='Xing@123', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=123; # 根据主服务器 SHOW MASTER STATUS 的结果填写 启动从服务器复制 start slave 查抄从服务器状态: show slave status\G 注意:
都为yes才算乐成开启主从复制,当上面谁人为no时,查抄防火墙,seliunx.假如都没错,则修改root为% alter user 'root'@'localhost' identified with mysql_native_password by 'Xing@123'; update mysql.user set host='%' where user='root'; flush privileges; 主从都进行修改
七、部署wordpress(三台都部署wordpress)
安装PHP环境
7.1安装php-fpm yum -y install php-fpm php-mysql 7.2启动php-fpm systemctl start php-fpm 7.3修改配置文件 vi /etc/php-fpm.d/www.conf 查找apache:/apache 修改属主和属组为nginx
7.4重启 systemctl restart php-fpm
7.5 检测php-fpm端口
yum -y install lsof
lsof -i:9000
安装Wordpress
wget
https://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz mv wordpress / chmod -R 777 /wordpress/ 一、问题: 安装wordpress时候访问出现下面情况: Your server is running PHP version 5.4.16 but WordPress 6.4.1 requires at least 7.0.0. 办理: 二、缘故原由: 您的服务器Q正在运行PHP版本5.4.16,但WordPress 6.4.1必要至少7.0.0版本的PHP。因此,必要升级PHP版本以使其与WordPress兼容。 三、办理方法: (1)查抄您的服务器是否已启用Remi存储库。假如未启用,请使用以下下令启用: yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm (2)启用Remi-PHP70存储库: yum install -y yum-utils yum-config-manager -- enable remi-php73 (3)安装PHPQ 7.0及其相关扩展: yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd (4)查抄PHP版本: php -v
八、测试
输入域名加端口
跳转至wordpress页面
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4