综合项目: 前端:Keepalived 双机热备,节点:LAMP+Discuz 论坛(1)

两台从节点操作一致

[root@slave1 ~]# cat <> /etc/my.cnf

log-bin=mysql-slave1 #slave2改为2

server-id=2 #slave2改为3

log_slave_updates=1

END

[root@slave1 ~]# systemctl restart mysqld

[root@slave1 ~]# mysql -uroot -p123456

mysql> grant replication slave on . to repl@‘192.168.1.%’ identified by ‘123456’;

mysql> grant all privileges on . to root@‘192.168.1.%’ identified by ‘123456’;

mysql> flush privileges;

mysql> exit

在这里插入图片描述

3)建立主从复制

在 slave1 slave2 上操作

[root@slave1 ~]# mysql -uroot -p123456

mysql> change master to

master_host=‘192.168.1.1’,

master_user=‘repl’,

master_password=‘123456’;

mysql> start slave;

mysql> show slave status\G;

在这里插入图片描述

4.设置 MySQL 程序及 binglog 程序的软连接


master和两台从节点都要做

[root@master ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

[root@master ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog

5.在两台 Slave 设置临时只读和不自动清除中继日志


[root@slave1 ~]# mysql -uroot -p123456 -e ‘set global read_only=1’

[root@slave1 ~]# mysql -uroot -p123456 -e ‘set global relay_log_purge=0’

6.配置 MHA 工作目录及配置文件


[root@master ~]# mkdir -p /etc/masterha

[root@master ~]# mkdir -p /var/log/masterha/app1

[root@master ~]# vim /etc/masterha/app1.cnf

[server default]

manager_workdir=/var/log/masterha/app1

manager_log=/var/log/masterha/app1/manager.log

master_binlog_dir=/usr/local/mysql/data/

user=root

password=123456

ping_interval=1

remote_workdir=/tmp

repl_user=repl

repl_password=123456

ssh_user=root

[server1]

hostname=192.168.1.1

port=3306

[server2]

hostname=192.168.1.2

port=3306

candidate_master=1

check_repl_delay=0

[server3]

hostname=192.168.1.3

port=3306

7.检查 MHA 的环境是否工作正常


1)检测 SSH 连接是否配置正常

[root@master ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf

在这里插入图片描述

2)在管理节点检查复制配置

[root@master ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf

最后显示如下说明环境没有问题:

MySQL Replication Health is OK.

在这里插入图片描述

9.配置 VIP 地址


master 上操作

[root@master ~]# ifconfig ens33:1 192.168.1.188 netmask 255.255.255.0 up

[root@master ~]# ifconfig ens33:1

在这里插入图片描述

1)修改 MHA 配置文件,使其支持 VIP

[root@master ~]# vim /etc/masterha/app1.cnf

在 [server default] 项下面添加:

master_ip_failover_script=/usr/bin/master_ip_failover

2)编写 VIP 自动切换脚本

[root@master ~]# vim /usr/bin/master_ip_failover

#!/usr/bin/env perl

use strict;

use warnings FATAL => ‘all’;

use Getopt::Long;

my (

$command, $ssh_user, $orig_master_host, $orig_master_ip,

$orig_master_port, $new_master_host, $new_master_ip, $new_master_port

);

my $vip = ‘192.168.1.188/24’;

my $key = ‘1’;

my s s h s t a r t v i p = " / s b i n / i f c o n f i g e n s 33 : ssh_start_vip = "/sbin/ifconfig ens33: sshstartvip="/sbin/ifconfigens33:key $vip";

my s s h s t o p v i p = " / s b i n / i f c o n f i g e n s 33 : ssh_stop_vip = "/sbin/ifconfig ens33: sshstopvip="/sbin/ifconfigens33:key down";

GetOptions(

‘command=s’ => $command,

‘ssh_user=s’ => $ssh_user,

‘orig_master_host=s’ => $orig_master_host,

‘orig_master_ip=s’ => $orig_master_ip,

‘orig_master_port=i’ => $orig_master_port,

‘new_master_host=s’ => $new_master_host,

‘new_master_ip=s’ => $new_master_ip,

‘new_master_port=i’ => $new_master_port,

);

exit &main();

sub main {

print “\n\nIN SCRIPT TEST==== s s h s t o p v i p = = ssh_stop_vip== sshstopvip==ssh_start_vip===\n\n”;

if ( $command eq “stop” || $command eq “stopssh” ) {

my $exit_code = 1;

eval {

print “Disabling the VIP on old master: $orig_master_host \n”;

&stop_vip();

$exit_code = 0;

};

if ($@) {

warn “Got Error: $@\n”;

exit $exit_code;

}

exit $exit_code;

}

elsif ( $command eq “start” ) {

my $exit_code = 10;

eval {

print “Enabling the VIP - $vip on the new master - $new_master_host \n”;

&start_vip();

$exit_code = 0;

};

if ($@) {

warn $@;

exit $exit_code;

}

exit $exit_code;

}

elsif ( $command eq “status” ) {

print “Checking the Status of the script… OK \n”;

exit 0;

}

else {

&usage();

exit 1;

}

}

sub start_vip() {

ssh $ssh_user\@$new_master_host \" $ssh_start_vip \";

}

sub stop_vip() {

ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \";

}

sub usage {

print

“Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n”;

}

[root@master ~]# chmod +x /usr/bin/master_ip_failover

再次检测,结果应该和上面检测结果一样才对

[root@master ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf

在这里插入图片描述

10.开启监控


[root@master ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf \

–remove_dead_master_conf --ignore_last_failover < /dev/null > \

/var/log/masterha/app1/manager.log 2>&1 &

[root@master ~]# masterha_check_status --conf=/etc/masterha/app1.cnf

在这里插入图片描述

三、部署 Apahce+PHP 架构

=====================================================================================

挂光盘,并配置yum源

1.安装并启动 Apache


[root@web1 ~]# yum -y install gcc gcc-c++ apr apr-devel cyrus-sasl-devel expat-devel libdb-devel openldap-devel apr-util-devel apr-util pcre-devel pcre openssl*

[root@web1 ~]# ls

anaconda-ks.cfg httpd-2.4.25.tar.gz

[root@web1 ~]# tar zxf httpd-2.4.25.tar.gz -C /usr/src/

[root@web1 ~]# cd /usr/src/httpd-2.4.25/

[root@web1 httpd-2.4.25]# ./configure \

–prefix=/usr/local/httpd \

–enable-so \

–enable-rewrite \

–enable-charset-lite \

–enable-cgi \

–enable-ssl \

–enable-mpms-shared=all && make && make install

在这里插入图片描述

复制启动脚本

[root@web1 ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/apache

[root@web1 ~]# sed -i 1a’#chkconfig: 2345 11 88’ /etc/init.d/apache # 在第一行下面插入…

[root@web1 ~]# chkconfig --add apache # 添加为系统服务

[root@web1 ~]# vim /usr/local/httpd/conf/httpd.conf

204 ServerName web1:80 # web2将 web1:80 改为 web2:80

[root@web2 ~]# /etc/init.d/apache start

[root@web2 ~]# netstat -anpt | grep 80

在这里插入图片描述

2.安装 PHP


[root@web1 ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c libmcrypt-devel freetype-devel libjpeg-devel bzip2-devel

[root@web1 ~]# ls

anaconda-ks.cfg httpd-2.4.25.tar.gz libmcrypt-2.5.8.tar.gz php-5.5.38.tar.gz

[root@web1 ~]# tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/

[root@web1 ~]# cd /usr/src/libmcrypt-2.5.8/

[root@web1 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt && make && make install

在这里插入图片描述

[root@web1 ~]# tar -zxf php-5.5.38.tar.gz -C /usr/src/

[root@web1 ~]# cd /usr/src/php-5.5.38

[root@web1 php-5.5.38]# ./configure \

–prefix=/usr/local/php5.5 \

–with-mysql=mysqlnd \

–with-pdo-mysql=mysqlnd \

–with-mysqli=mysqlnd \

–with-openssl \

–enable-fpm \

–enable-sockets \

–enable-sysvshm \

–enable-mbstring \

–with-freetype-dir \

–with-jpeg-dir \

–with-png-dir \

–with-zlib \

–with-libxml-dir=/usr \

–enable-xml --with-mhash \

–with-mcrypt=/usr/local/libmcrypt \

–with-config-file-path=/etc \

–with-config-file-scan-dir=/usr/local/php5.5/etc/ \

–with-bz2 \

–enable-maintainer-zts \

–with-apxs2=/usr/local/httpd/bin/apxs && make && make install

[root@web1 php-5.5.38]# cp php.ini-production /usr/local/php5.5/etc/php.ini

3.配置 PHP,测试后端数据库 VIP


[root@web1 ~]# vim /usr/local/httpd/conf/httpd.conf

263 DirectoryIndex index.html index.php

401 AddType application/x-http-php .php .phtml

[root@web1 ~]# /etc/init.d/apache restart

1)创建测试页面

[root@web1 ~]# vim /usr/local/httpd/htdocs/index.php

<?php phpinfo(); ?>

[root@web1 ~]# /etc/init.d/apache restart

2)访问验证

在这里插入图片描述

4.安装 Discuz 论坛


1)在 Master 上创建一个 Discuz 论坛账号

[root@master ~]# mysql -uroot -p123456

mysql> grant all on . to dtest@‘%’ identified by ‘123456’;

mysql> flush privileges;

在这里插入图片描述

2)在 Web1 上创建测试页面

[root@web1 ~]# vim /usr/local/httpd/htdocs/test.php

<?php $link=mysql_connect('192.168.1.188','dtest','123456'); if ($link)echo "恭喜你,数据库连接成功!!"; mysql_close(); ?>

3)访问测试

在这里插入图片描述

4)安装 Discuz 论坛

web1上操作

[root@web1 ~]# ls

[root@web1 ~]# unzip Discuz_X3.3_SC_UTF8.zip -d discuz

[root@web1 ~]# cd discuz/

[root@web1 discuz]# cp -r upload/ /usr/local/httpd/htdocs/discuz

[root@web1 discuz]# vim /usr/local/php5.5/etc/php.ini

202 short_open_tag = 0n

[root@web1 discuz]# /etc/init.d/apache restart

[root@web1 discuz]# chown -R daemon:daemon /usr/local/httpd/htdocs/

5)在浏览器上安装 Discuz 论坛

访问:http://192.168.1.4/discuz/install/index.php

在这里插入图片描述

继续下一步,到我如下,按我下图填写

在这里插入图片描述

安装完成后点击右下角的访问

在这里插入图片描述

因为 Web1 上都已经安装好了,这里直接把 Web1 安装好的 Discuz,传给 Web2

[root@web1 ~]# scp -r /usr/local/httpd/ 192.168.1.5:/usr/local/

[root@web2 ~]# /etc/init.d/apache restart

[root@web2 ~]# chown -R daemon:daemon /usr/local/httpd/htdocs/

访问并测试数据一致性

在这里插入图片描述

在这里插入图片描述

到 Web1 的论坛中,登陆 zhangsan 账号,可以登陆

在这里插入图片描述

这是因为两个 Discuz 后端的数据库都是一个,数据都是在数据库中的,所以其中数据都是一样的。

四、部署 Keepliaved 双机热备

=======================================================================================

挂光盘,并配置yum源

1.配置主和备调度器


主备操作稍微不同,不同的地方下面我会说

[root@keep1 ~]# yum -y install ipvsadm keepalived

[root@keep1 ~]# cd /etc/keepalived/

[root@keep1 keepalived]# rm -rf keepalived.conf

web浏览器中的javascript

window对象

  • 计时器

  • 浏览器定位和导航

  • 浏览历史

  • 浏览器和屏幕信息

  • 对话框

  • 错误处理

  • 作为window对象属性的文档元素

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值