maxHttpHeaderSize="8192" useBodyEncodingForURI="true"
maxThreads="600" 最大连接数
redirectPort="8443"
enableLookups="false" 禁用DNS查询
compression="on"
compressionMinSize="2048" 压缩,压缩大小
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
connectionTimeout="20000"
disableUploadTimeout="true"
/>
设置环境目录
vi /etc/profile
TOMCAT_HOME=/data/conf/tomcat
JAVA_HOME=/data/conf/jdk
JRE_HOME=/data/conf/jdk/jre
export JAVA_HOME JRE_HOME TOMCAT_HOME
备份tomcat配置文件
cd /data/conf/tomcat/conf
mv server.xml server.xml.bak
设置tomcat配置文件,配置虚拟主机
vi server.xml
在后面添加
启动tomcat
/data/conf/tomcat/bin/startup.sh
查看启动进程
ps -ef |grep tomcat
访问tomcat测试页,出现猫头网页,则安装成功!
links
3. 安装nginx
解压压缩文件
tar zxvf pcre-8.02.tar.gz
cd pcre-8.02/
编译安装
./configure
make && make install
tar zxvf nginx-0.8.50.tar.gz
cd nginx-0.8.50/
编译安装
./configure --prefix=/data/conf/nginx --with-http_stub_status_module
make && make install
配置nginx配置文件
cd /data/conf/nginx
备份nginx.conf配置文件
mv nginx.conf nginx.conf.bak
vi nginx.conf
user nobody nobody;
worker_processes 4;
pid /data/conf/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
upstream www
{
server 127.0.0.1:8080;
}
server {
listen 80;
server_name ;
location / {
root /data/web/ ;
index index.jsp index.htm index.html;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass ;
}
access_log /data/logs/benet.com/
error_log /data/logs/benet.com/error-;
}
server {
listen 80;
server_name ;
location / {
root /var/www ;
index index.jsp index.htm index.html;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass ;
}
access_log /data/logs/accp.com/
error_log /data/logs/accp.com/error-;
}
server {
listen 80;
server_name ;
location / {
root /data/web/ ;
index index.jsp index.htm index.html;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass ;
}
access_log /data/logs/apache.com/
error_log /data/logs/apache.com/error-;
}
}
检测配置文件是否存在错误
./nginx -t
启动nginx
创建项目目录
mkdir /data/web/
mkdir /data/web/
mkdir /data/web/
mkdir -p /data/logs/benet.com
mkdir -p /data/logs/accp.com
mkdir -p /data/logs/apache.com
建立测试网页
echo "This is benet home page !!!" > /data/web//index.html
echo "This is accp home page !!! " > /data/web//index.html
echo "This is apache home page !!!" > /data/web//index.html
添加hosts记录
echo "192.168.1.248 " >> /etc/hosts
echo "192.168.1.248 " >> /etc/hosts
echo "192.168.1.248 " >> /etc/hosts
浏览测试网页,出现相应的网页,则配置完成。
links
links
links
4. sersync 同步配置,使得网站项目文件一致。
在192.168.1.248服务器上安装rsync
tar xzvf rsync-3.0.7.tar.gz
cd rsync-3.0.7
./configure --prefix=/data/conf/rsync
make && make install
rpm -qa |grep rsync
rpm -qf /usr/bin/rsync
rpm -e rsync-2.6.8-3.1
ln -s /data/conf/rsync/bin/rsync /usr/bin/rsync
查看rsync版本
rsync -version
配置rsync配置文件
vi rsyncd.conf
port = 873
max connections = 4
pid file = /data/conf/rsync/rsync.pid
lock file = /data/conf/rsync/rsync.lock
log file = /data/conf/rsync/rsync.log
[dataweb]
path = /data/web
auth users = aa
secrets file = /data/conf/rsync/conf/rsync.passwd
uid = webuser
gid = webuser
read only = no
创建认证用户名和密码文件
vi /data/conf/rsync/conf/rsync.passwd
aa:123456
启动rsync守护进程
rsync --daemon
在192.168.1.249安装sersync
tar xzvf sersync2.5_32bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/ /data/conf/sersync
cd /data/conf/sersync/
配置sersync配置文件
vi confxml.xml
修改为
开启sersync守护进程
./sersync2 -d
测试文件是否同步
在192.168.1.249服务器上/data/web/目录下创建些文件
在192.168.1.248服务器上/data/web/目录下看是否同步有相应的文件
LVS群集配置
1.客户端 就是真实服务器
在192.168.1.248和249服务器环回接口上绑定 虚拟ip
vi /data/conf/realserver
#!/bin/bash
#description : start realserver
VIP=192.168.1.100
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
开启虚拟IP
cd /data/conf
./realserve start
查看虚拟IP
ip add 或者 ifconfig
192.168.1.246 lvs主机------------192.168.1.247 lvs备份机
1. 在1.246和247上安装 ipvsadm
yum -y install ipvsadm
2. 192.168.1.246 lvs主机安装keepalived
安装keepalived
cd /soft
tar xzvf keepalived-1.1.19_.tar.gz
./configure --prefix=/data/conf/keepalived
make
make install
创建keepalived目录
mkdir -p /etc/keepalived
创建keepalived.conf配置文件
vim /etc/keepalived/keepalived.conf
#writed by sery ,
#guration File for keepalived
#global define
global_defs {
router_id LVS_CNC_1
}
vrrp_sync_group VGM {
group {
VI_CACHE
}
}
################################################################
# vvrp_instance define #
################################################################
vrrp_instance VI_CACHE {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 180
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
##############################################################
# virtual machine setting #
##############################################################
# setting port 80 forward
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
# persistence_timeout 20
protocol TCP
real_server 192.168.1.248 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.249 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
启动keepalived
cd /data/conf/keepalived/sbin
./keepalived -D
查看keepalived进程,是否有3个进程
ps -ef |grep keepalived
查看ipvsadm
ipvsadm -L -c
3. 192.168.1.247 lvs备份机
安装keepalived
cd /soft
tar xzvf keepalived-1.1.19_.tar.gz
./configure --prefix=/data/conf/keepalived
make
make install
创建keepalived目录
mkdir -p /etc/keepalived
创建keepalived.conf配置文件
#writed by sery ,
#guration File for keepalived
#global define
global_defs {
router_id LVS_CNC_2
}
vrrp_sync_group VGM {
group {
VI_CACHE
}
}
################################################################
# vvrp_instance define #
################################################################
vrrp_instance VI_CACHE {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 150
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
##############################################################
# virtual machine setting #
##############################################################
# setting port 80 forward
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
# persistence_timeout 20
protocol TCP
real_server 192.168.1.248 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.249 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
启动keepalived
cd /data/conf/keepalived/sbin
./keepalived -D
查看keepalived进程,是否有3个进程
ps -ef |grep keepalived
查看ipvsadm
ipvsadm -L -c
LVS群集测试:
设置hosts文件
192.168.1.100
192.168.1.100
192.168.1.100
访问测试网页
关闭LVS master主机,看是否还能访问测试网页不,如果能访问,则LVS配置成功了,若不行,则进行相应的排错啦、