高可用web集羣網站搭建及監控

1、項目目標

搭建一個高可用web集羣網站php

2、項目規劃


2.1 ip地址規劃

webp

2.2 拓撲圖

2.3 相關說明

2.3.1 數據庫採用mysql主主複製和mmm高可用html

2.3.2 web集羣爲lvs+dr模式,keeplived實現高可用mysql

2.3.3 nfs使兩個web服務器間信息數據同步linux

2.3.4 nagios監控各服務器狀態ios

3、環境搭建

各主機本地yum源配置

或者此處也可以使用自建內網yum源c++

mount -t iso9660 /dev/sr0 /mediaweb

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

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

[centos6-iso]vim

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;

webp

[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

webp


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

緣由及解決方法:前面存在殘留進程,殺掉便可

webp

設置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’

刪除多餘不用庫

相關文章
相關標籤/搜索