一、项目目标

搭建一个高可用web集群网站

二、项目规划


2.1 ip地址规划

高可用web集群网站搭建及监控_第1张图片

2.2 拓扑图

2.3 相关说明

2.3.1 数据库采用mysql主主复制和mmm高可用

2.3.2 web集群为lvs+dr模式,keeplived实现高可用

2.3.3 nfs使两个web服务器间信息数据同步

2.3.4 nagios监控各服务器状态

三、环境搭建

各主机本地yum源配置

或者此处也可使用自建内网yum源

mount -t iso9660 /dev/sr0 /media

echo ‘/dev/sr0 /media iso9660 defaults 0 0’>>/etc/fstab

[root@web02 ~]# cat /etc/yum.repos.d/centos.repo

[centos6-iso]

name=centos

baseurl=file:///media

enabled=1

gpgcheck=0

iptables及selinux关闭

service iptables stop;chkconfig iptables off

sed -i “s/SELINUX=enforcing/SELINUX=disabled/” /etc/selinux/config;setenforce 0

时间同步问题—NTP 服务器搭建

[root@nagios ~]# rpm -qa|grep ntp

如未安装使用yum install -y ntp安装

chkconfig ntpd on

vim /etc/ntp.conf

#restrict default kod nomodify notrap nopeer noquery #注释此行

restrict 192.168.2.0 mask 255.255.0.0 nomodify notrap #新增此行

server s1d.time.edu.cn  #网络同步地址

server s2g.time.edu.cn  #网络同步地址

[root@nagios ~]#service ntpd restart 重启ntp服务


然后其他主机做定时任务同步此时间服务器

echo ‘*/5 * * * * /usr/sbin/ntpdate 192.168.2.11 >/dev/null 2>&1’>>/var/spool/cron/root

各主机hosts文件修改

[root@nagios ~]# cat /etc/hosts

127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4

::1        localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.2.62 mysql-m44

192.168.2.64 mysql-m45

192.168.2.40 mysql-mon40

192.168.2.65 web-lnmp01

192.168.2.66 web-lnmp02

192.168.2.60 nfs

192.168.2.50 lb-01

192.168.2.51 lb-02

192.168.2.11 nagios


3.1 nagios服务器搭建

所需软件包

nagios-3.5.1.tar.gz

nagios-plugins-2.1.1.tar

nrpe-2.15.tar

[root@nagios ~]# yum install -y httpd

[root@nagios ~]# chkconfig httpd on

nagios安装

[root@nagios nagios]# groupadd nagios;useradd nagios -g nagios

[root@nagios ~]# tar xzvf nagios-3.5.1.tar.gz ;cd nagios

[root@nagios nagios]# yum install -y gcc gcc-c++ glibc glibc-common gd gd-devel mysql-server httpd php php-gd

[root@nagios nagios]# ./configure –prefix=/usr/local/nagios –with-command-group=nagios

[root@nagios nagios]#make all && make install

[root@nagios nagios]# make install-init;make install-commandmode;make install-config

[root@nagios nagios]# make install-webconf       ##nagios web配置文件

[root@nagios nagios]# htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin 123456

service httpd restart && service nagios restart


nagios-plugins安装

[root@nagios ~]# tar xf nagios-plugins-2.1.1.tar.gz

[root@nagios ~]# cd nagios-plugins-2.1.1

[root@nagios nagios-plugins-2.1.1]# ./configure –prefix=/usr/local/nagios/ –with-nagios-user=nagios –with-nagios-group=nagios && make && make install

[root@nagios ~]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

[root@nagios nagios-plugins-2.1.1]# chkconfig nagios on

[root@nagios nagios-plugins-2.1.1]# service nagios restart

验证nagios配置文件命令/etc/init.d/nagios checkconfig

如想看到详细报错又不想用/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg命令

可以修改vim /etc/init.d/nagios,将下图中定向到空的内容删除

即修正后为$NagiosBin -v $NagiosCfgFile;

高可用web集群网站搭建及监控_第2张图片

[root@nagios ~]# vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

nagios本机监控配置

[root@nagios ~]# vim /usr/local/nagios/etc/objects/hosts.cfg

[root@nagios etc]# head -51 objects/localhost.cfg |grep -v ‘#|^
>objects/hosts.cfg

[root@nagios etc]# vim objects/hosts.cfg

define host{

use                    linux-server

host_name              2.11-nagios

alias                  2.11-nagios

address                127.0.0.1

}

define hostgroup{

hostgroup_name  linux-servers

alias          Linux Servers

members        2.11-nagios

}

[root@nagios etc]# grep -v ‘#|^$’ objects/services.cfg

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            PING

check_command check_ping!100.0,20%!500.0,60%

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            Root Partition

check_command check_local_disk!20%!10%!/

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            Current Users

check_command check_local_users!20!50

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            Total Processes

check_command check_local_procs!250!400!RSZDT

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            Current Load

check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            Swap Usage

check_command check_local_swap!20!10

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            SSH

check_command check_ssh

notifications_enabled 0

}

define service{

use                            local-service        ; Name of service template to use

host_name                      2.11-nagios

service_description            HTTP

check_command check_http

notifications_enabled 0

}

[root@nagios etc]#chown nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg

[root@nagios etc]#chown nagios.nagios /usr/local/nagios/etc/objects/services.cfg

[root@nagios etc]# /etc/init.d/nagios checkconfig

Total Warnings: 0

Total Errors:  0

Things look okay – No serious problems were detected during the pre-flight check

OK.

[root@nagios etc]# /etc/init.d/nagios restart

客户端访问http://192.168.2.11/nagios

高可用web集群网站搭建及监控_第3张图片


3.2 mysql服务器搭建mysql-m62和mysql-m64

mysql-5.5.52.tar.gz    #源码安装

解决依赖

[root@xuegod62 mysql-5.5.52]# yum install -y ncurses-devel libaio-devel cmake

解压安装

[root@xuegod62 ~]# tar xf mysql-5.5.52.tar.gz;cd mysql-5.5.52

[root@xuegod64 mysql-5.5.52]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1

[root@xuegod62 mysql-5.5.52]# make -j 4 && make install

[root@xuegod62 mysql-5.5.52]# mysql -V

mysql  Ver 14.14 Distrib 5.5.52, for Linux (x86_64) using readline 5.1

#授权mysql用户管理mysql的安装目录,

初始化mysl数据库文件

[root@mysql-m62 mysql-5.5.52]# chown -R mysql.mysql /application/mysql/

[root@mysql-m62 mysql-5.5.52]# /application/mysql/scripts/mysql_install_db –basedir=/application/mysql/ –datadir=/application/mysql/data/ –user=mysql

[root@mysql-m62 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@mysql-m62 mysql]# chmod +x /etc/init.d/mysqld

启动报错:

webp

原因及解决方法:前面存在残留进程,杀掉即可

高可用web集群网站搭建及监控_第4张图片

设置mysql开机自启动

[root@mysql-m62 mysql]# chkconfig mysqld on

[root@mysql-m62 mysql]# chkconfig –add mysqld

重启mysql          service mysqld restart

[root@mysql-m62 mysql]# mysqladmin -uroot password ‘123456’

删除多余不用库