LVS+Keepalived+Squid+Nginx+MySQL主从高性能集群架构部署方案
方案一,在tomcat的workers.properties里面配置相关条件
worker.tomcat.lbfactor=
worker.tomcat.cachesize=
worker.tomcat.cache_timeout=
worker.tomcat.socket_keepalive=
worker.tomcat.socket_timeout=
Linux内核优化:
vi /etc/sysctl.conf # 编辑sysctl.conf文件添加以下内容
net.ipv4.tcp_rmem =
net.ipv4.tcp_wmem =
net.core.wmem_default =
net.core.rmem_default =
net.core.rmem_max =
net.core.wmem_max =
net.core.netdev_max_backlog =
net.core.somaxconn =
net.ipv4.tcp_max_orphans =
net.ipv4.tcp_max_syn_backlog =
net.ipv4.tcp_max_tw_buckets =
net.ipv4.tcp_timestamps =
net.ipv4.tcp_synack_retries =
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_tw_recycle =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_mem =
net.ipv4.tcp_fin_timeout =
net.ipv4.tcp_keepalive_time =
net.ipv4.ip_local_port_range =
以上配置说明:
net.ipv4.tcp_rmem = 4096 87380 4194304:TCP读buffer,可参考的优化值: 32768 436600 873200
net.ipv4.tcp_wmem = 4096 65536 4194304:TCP写buffer,可参考的优化值: 8192 436600 873200
net.core.wmem_default:表示发送套接字缓冲区大小的缺省值(以字节为单位)
net.core.rmem_default:表示接收套接字缓冲区大小的缺省值(以字节为单位)
net.core.rmem_max :表示接收套接字缓冲区大小的最大值(以字节为单位)
net.core.wmem_max:表示发送套接字缓冲区大小的最大值(以字节为单位)
net.core.netdev_max_backlog = 262144:每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目。
net.core.somaxconn = 262144:web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值。
net.ipv4.tcp_max_orphans = 3276800:系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。
net.ipv4.tcp_max_syn_backlog = 8192:表示SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数。
net.ipv4.tcp_max_tw_buckets = 5000:表示系统同时保持TIME_WAIT套接字的最大数量,如果超过这个数字,TIME_WAIT套接字将立刻被清除并打印警告信息。减少它的最大数量,避免Squid服务器被大量的TIME_WAIT套接字拖死。
net.ipv4.tcp_timestamps = 0:时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号,时间戳能够让内核接受这种“异常”的数据包,这里需要将其关掉。
net.ipv4.tcp_tw_recycle = 1:表示开启TCP连接中TIME-WAIT sockets的快速回收。
net.ipv4.tcp_tw_reuse = 1:表示开启重用,允许将TIME-WAIT sockets重新用于新的TCP连接。
net.ipv4.tcp_mem = 786432 1048576 1572864:同样有3个值,net.ipv4.tcp_mem[0]:低于此值,TCP没有内存压力;net.ipv4.tcp_mem[1]:在此值下,进入内存压力阶段;net.ipv4.tcp_mem[2]:高于此值,TCP拒绝分配socket。可根据物理内存大小进行调整,如果内存足够大的话,可适当往上调。建议94500000 915000000 927000000。
net.ipv4.tcp_fin_timeout = 30:表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。
net.ipv4.tcp_keepalive_time = 1200:表示当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时,改为20分钟。
net.ipv4.ip_local_port_range = 1024 65000:表示用于向外连接的端口范围。缺省情况下很小:32768到61000,改为1024到65000。
#使配置立即生效:
/sbin/sysctl -p
LVS + keepalived 配置:
mkdir /usr/local/src/lvs
cd /usr/local/src/lvs
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz lsmod |grep ip_vs
uname -r
ln -s /usr/src/kernels/$(uname -r)/usr/src/linux
#ln -s /usr/src/kernels/2.6.* /usr/src/linux
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
tar zxvf keepalived-1.1..tar.gz
cd keepalived-1.1.
./configure&& make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
#you can service keepalived start|stop cat >> /usr/local/etc/keepalived/keepalived.conf <<EOF ! Configuration File for keepalived
global_defs {
notification_email {
rfyiamcool@.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER # BACKUP
interface eth0
virtual_router_id
priority # 另一端
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
10.10.10.88
}
}
virtual_server 10.10.10.88 {
delay_loop
lb_algo rr
lb_kind DR
persistence_timeout
protocol TCP
real_server 10.10.10.21 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
}
real_server 10.10.10.22 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
real_server 10.10.10.23 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
} }
} EOF
service keepalived start
backup主机的配置:
mkdir /usr/local/src/lvs
cd /usr/local/src/lvs
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz lsmod |grep ip_vs
uname -r
ln -s /usr/src/kernels/$(uname -r)/usr/src/linux
#ln -s /usr/src/kernels/2.6.* /usr/src/linux
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
tar zxvf keepalived-1.1..tar.gz
cd keepalived-1.1.
./configure&& make && make install
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
#you can service keepalived start|stop cat >> /usr/local/etc/keepalived/keepalived.conf <<EOF ! Configuration File for keepalived
global_defs {
notification_email {
rfyiamcool@.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
10.10.10.88
}
}
virtual_server 10.10.10.88 {
delay_loop
lb_algo rr
lb_kind DR
persistence_timeout
protocol TCP
real_server 10.10.10.21 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
}
real_server 10.10.10.22 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
}
real_server 10.10.10.23 {
weight
TCP_CHECK {
connect_timeout
nb_get_retry
delay_before_retry
connect_port
} }
} EOF
service keepalived start
Squid缓存反向代理配置:
#!/bin/bash
wget http://www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE6.tar.bz2
tar jxvf squid-2.6.STABLE6.tar.bz2
./configure --prefix=/usr/local/squid \
--enable-async-io= \
--enable-storeio="aufs,diskd,ufs" \
--enable-useragent-log \
--enable-referer-log \
--enable-kill-parent-hack \
--enable-forward-log \
--enable-snmp \
--enable-cache-digests \
--enable-default-err-language=Simplify_Chinese \
--enable-epoll \
--enable-removal-policies="heap,lru" \
--enable-large-cache-files \
--disable-internal-dns \
--enable-x-accelerator-vary \
--enable-follow-x-forwarded-for \
--disable-ident-lookups \
--with-large-files \
--with-filedescriptors= cat >> /usr/local/squid/etc/squid.conf <<EOF
visible_hostname cache1.taobao.com
http_port 192.168.1.44: vhost vport
icp_port
cache_mem MB
cache_swap_low
cache_swap_high
maximum_object_size KB maximum_object_size_in_memory KB cache_dir ufs /tmp1 cache_store_log none emulate_httpd_log on efresh_pattern ^ftp: % refresh_pattern ^gopher: % refresh_pattern . % negative_ttl minutes positive_dns_ttl hours negative_dns_ttl minute connect_timeout minute read_timeout minutes request_timeout minutes client_lifetime day half_closed_clients on maximum_single_addr_tries uri_whitespace strip ie_refresh off logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh pid_filename /var/log/squid/squid.pid
cache_log /var/log/squid/cache.log
access_log /var/log/squid/access.log combined acl all src 0.0.0.0/0.0.0.0 acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY acl picurl url_regex -i \.bmp$ \.png$ \.jpg$ \.gif$ \.jpeg$
acl mystie1 referer_regex -i aaa
http_access allow mystie1 picurl
acl mystie2 referer_regex -i bbb
http_access allow mystie2 picurl acl nullref referer_regex -i ^$
http_access allow nullref
acl hasref referer_regex -i .+
http_access deny hasref picurl cache_peer 10.10.10.56 parent no-query originserver name=web1 round-robin
cache_peer 10.10.10.57 parent no-query originserver name=web2 round-robin #请自己改域名 比如123.com www..com *..com
cache_peer_domain all ..com cache_effective_user nobody
cache_effective_group nobody acl localhost src 127.0.0.1
acl my_other_proxy srcdomain .a.com
follow_x_forwarded_for allow localhost
follow_x_forwarded_for allow all #允许转发 head ip 头
acl_uses_indirect_client on #只有2.6才有这这个个参数
delay_pool_uses_indirect_client on #只有2.6才有这这个个参数
log_uses_indirect_client on # 只有2.6才有这这个个参数 #refresh_pattern ^ftp: %
#refresh_pattern ^gopher: %
#refresh_pattern ^gopher: %
#refresh_pattern . %
refresh_pattern -i \.css$ %
refresh_pattern -i \.js$ %
refresh_pattern -i \.html$ %
refresh_pattern -i \.jpg$ %
refresh_pattern -i \.gif$ %
refresh_pattern -i \.swf$ %
refresh_pattern -i \.jpg$ %
refresh_pattern -i \.png$ %
refresh_pattern -i \.bmp$ %
refresh_pattern -i \.doc$ %
refresh_pattern -i \.ppt$ %
refresh_pattern -i \.xls$ %
refresh_pattern -i \.pdf$ %
refresh_pattern -i \.rar$ %
refresh_pattern -i \.zip$ %
refresh_pattern -i \.txt$ % EOF
#建立缓存和日志目录,并改变权限使squid能写入
mkdir /tmp1
mkdir /var/log/squid
chown -R nobody:nobody /tmp1
chmod /tmp1
chown -R nobody:nobody /var/log/squid #首次运行squid要先建立缓存
/usr/local/squid/sbin/squid -z #启动squid
echo "" > /proc/sys/fs/file-max
ulimit -HSn
/usr/local/squid/sbin/squid
*取得squid运行状态信息: squidclient -p 80 mgr:info
*取得squid内存使用情况: squidclient -p 80 mgr:mem
*取得squid已经缓存的列表: squidclient -p 80 mgr:objects. use it carefully,it may crash
*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
缓存的清理脚本
格式:
qingli.sh www.linuxidc.com
qingli.sh jpg
qingli.sh linuxidc.com 123 bbb jpg
#!/bin/sh
squidcache_path="/squidcache"
squidclient_path="/home/local/squid/bin/squidclient"
#grep -a -r $ $squidcache_path/* | grep "http:" | awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' > cache.txt
if [[ "$1" == "swf" || "$1" == "png" || "$1" == "jpg" || "$1" == "ico" || "$1" == "gif" || "$1" == "css" || "$1" == "js" || "$1" == "html" || "$1" == "shtml" || "$1" == "htm" ]]; then
grep -a -r .$1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' | grep "$1$" | uniq > cache.txt
else
grep -a -r $1 $squidcache_path/* | strings | grep "http:" |grep $2$ |grep $3$|grep $4$|grep $5$ |grep $6$| awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' | uniq > cache.txt
fi
sed -i "s/\";$//g" cache.txt
cat cache.txt | while read LINE
do
$squidclient_path -p 80 -m PURGE $LINE
done
下面是3.1的安装,针对需要3.1部分模块的朋友,但是不推荐用3.1
tar -zxvf squid-3.1.--r10455.tar.gz
cd squid-3.1.--r10455
./configure --prefix=/usr/local/squid --enable-async-io= --disable-delay-pools --disable-mem-gen-trace --disable-useragent-log --enable-kill-parent-hack --disable-arp-acl --enable-epoll --disable-ident-lookups --enable-snmp --enable-large-cache-files --with-large-files
make && make install
groupadd squid #创建squid用户组
useradd -g squid -s /sbin/nologin squid #创建squid用户,并加入到squid组里,不允许登录系统 chown -R squid /usr/local/squid/ #修改squid的安装目录所属用户为squid用户
mkdir -p /var/cache #创建squid的第一个缓存目录
mkdir -p /var/squid #创建squid的第二个缓存目录
chown squid.squid -R /var/cache /var/squid #设置目录所有者
chmod -R /var/cache /var/squid #设置目录权限
mv /usr/local/squid/etc/squid.conf /usr/local/squid/etc/squid.conf.bak vi /usr/local/squid/etc/squid.conf
cache_effective_user squid #运行squid的用户
cache_effective_group squid #运行squid的用户所在的组
visible_hostname squid1.cache.cn #设定squid的主机名,如无此项squid将无法启动
http_port accel vhost vport #代理端口
icp_port #icp端口
# 配置其他缓存服务器,当squid1在其缓存中没有找到请求的资源时,通过ICP查询去其邻居中取得缓存
cache_peer 10.10.10.21 sibling
cache_peer 10.10.10.22 sibling
cache_peer 10.10.10.23 sibling
# 后端web服务器配置,round-robin表示通过轮询方式将请求分发到其中一台web节点
cache_peer 10.10.10.56 parent no-query originserver round-robin name=webServer1
cache_peer 10.10.10.57 parent no-query originserver round-robin name=webServer2
cache_peer_domain webServer1 webServer2 ..com #根据通配域名xuad.com来进行转发
# 下面三行是配置访问控制的
http_access allow all #允许以上所有规则通过
# URL中包含cgi-bin和以https:\\开头的都不缓存,asp、cgi、php、jsp等动态页面也不缓存
hierarchy_stoplist cgi-bin ?
hierarchy_stoplist -i ^https:\\ ?
acl QueryString urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi
acl denyssl urlpath_regex -i ^https:\\
no_cache deny QueryString
no_cache deny denyssl
# 日志和缓存目录的设置
cache_log /usr/local/squid/var/logs/cache.log #cache.log日志文件存放目录
access_log /usr/local/squid/var/logs/access.log squid #access.log日志文件存放目录
cache_dir aufs /var/cache #设定缓存目录cache,目录容量最大1024M,*256级子目录
cache_dir aufs /var/squid #设定缓存目录squid,目录容量最大3072M,*256级子目录
cache_mem MB #squid用于缓存的内存容量
# 当缓存目录空间使用达到95%以上时,新的内容将取代旧的内容,直到空间又下降到90%才停止这一活动
cache_swap_low
cache_swap_high
# 设置存储策略
maximum_object_size KB #能缓存的最大对象为4M
maximum_object_size_in_memory KB #内存中缓存的最大对象80K
ipcache_size #缓存DNS解析得到的IP,最大单个对象为1024K
ipcache_low
ipcache_high
cache_replacement_policy lru #缓存替换策略
memory_replacement_policy lru #内存替换策略
memory_pools on #开启内存池
memory_pools_limit MB #限制内存池大小为32MB forwarded_for on #开启转发
log_icp_queries off #关闭icp查询日志 forward_timeout seconds #允许转发超时20秒
connect_timeout seconds #连接到其他机器的最大尝试时间
read_timeout minutes #允许读取超时3分钟
request_timeout minutes #允许返回超时1分钟
persistent_request_timeout seconds #允许持续连接超时30秒
client_lifetime minutes #客户端会话保���
shutdown_lifetime seconds
negative_ttl seconds #设置错误信息的生存时间
# 允许一个IP最大并发数为50
acl OverConnLimit maxconn
http_access deny OverConnLimit client_persistent_connections off #对客户端长连接KeepAlive这个参数的支持
server_persistent_connections on # 开启服务端的KeepAlive,web端要开启KeepAlive,不然这里打开是没用的
tcp_recv_bufsize bytes #TCP套接字接收缓冲区大小
half_closed_clients off #当客户与squid的连接处于半关闭状态时,允许squid立即关闭连接 via on #开启转发循环的检测
request_header_access via deny all #避免由于两台squid的主机名一样而返回403错误
httpd_suppress_version_string off #错误页面不显示squid的版本信息
ie_refresh off #是否允许对旧版本的IE浏览器强制刷新页面
/usr/local/squid/sbin/squid -N –z
/usr/local/squid/sbin/squid
配置lvs客户端模式
#!/bin/bash
SNS_VIP=10.10.10.88
source /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo: $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP dev lo:
echo "" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Start OK"
;;
stop)
ifconfig lo: down
route del $SNS_VIP >/dev/null >&
echo "" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit
esac exit
lnmp自动安装脚本,含有eaccelerator memcache组件
这个是完整的配置脚本,可以把mysql部分取消~
版本我选择的是
pcre-8.01.tar.gz, nginx-1.0.2.tar.gz, mysql-5.1.41.tar.gz, php-5.3.3.tar.bz2, memcache-2.2.5.tgz
#!/bin/sh
srcpath=/usr/src
apppath=/usr/local
sleep
if
[ $UID -ne ];then echo “This script must use administrator or root user ,please exit …….”
sleep
exit fi Download ()
{
cd $srcpath && wget http://blog.mgcrazy.com/download/{pcre-8.01.tar.gz,nginx-1.0.2.tar.gz,mysql-5.1.41.tar.gz,php-5.3.3.tar.bz2,memcache-2.2.5.tgz,php-fpm.conf,php.ini,nginx.conf,fcgi.conf,eaccelerator-0.9.6.1.tar.bz2} echo “THIS IS STARTING SHELL MAKE INSTALL SHELL ,PLEASE WAITING ………………………..” sleep 2s if [ $? -eq ];then
echo -n “DownLoad Linux source packages End ,Please Waiting Install………………”
else
echo -n “Download Linux source packages Failed ,Please Check………………”
fi
} Nginx_install ()
{
cd $srcpath && tar xzf pcre-8.01.tar.gz && cd pcre-8.01 && ./configure –prefix=$apppath/pcre && make &&make install if
[ $? -eq ];then echo “This pcre make install end ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”
else
echo “Pcre install failed ,please check install shell or system gcc configuration ,exiting ……….”
sleep 1s
exit fi echo “pcre install end ………..,please install nginx …………………” useradd www ; cd $srcpath && tar xzf nginx-1.0..tar.gz && cd nginx-1.0. && ./configure –prefix=$apppath/nginx –with-http_stub_status_module –with-cc-opt=’-O3′ –with-cpu-opt=opteron –with-openssl=/usr/ –with-pcre=/usr/src/pcre-8.01 –user=www –group=www ; make ; make install
cp -r $srcpath/{nginx.conf,fcgi.conf} $apppath/nginx/conf/ if [ $? -eq ];then
echo -n “Nginx Install success ………………”
else
echo -n “Nginx Install Failed ,Please Check………………”
exit
fi echo “nginx install end …………………..,Next install mysql …………………………..” } Mysql_install ()
{
cd $srcpath && tar xzf mysql-5.1..tar.gz && cd mysql-5.1. && ./configure –prefix=$apppath/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase && make &&make install if [ $? -eq ];then
echo -n “Mysql Install success ………………”
else
echo -n “Mysql Install Failed ,Please Check………………”
exit
fi echo “init mysql server , ……….please waiting ………………………………….” cd /usr/local/mysql && useradd mysql ; chown -R mysql:mysql /usr/local/mysql && /usr/local/mysql/bin/mysql_install_db –user=mysql && chown -R mysql:mysql var/ echo “Now install php ,please waiting………………………………….”
} Php_install ()
{
yum clean all && yum install -y libevent* &&cd $srcpath &&tar jxvf php-5.3..tar.bz2 && cd php-5.3. && ./configure –prefix=$apppath/php5 –with-config-file-path=$apppath/php5/etc –with-mysql=$apppath/mysql –with-mysqli=$apppath/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fpm –enable-sockets && make &&make install if
[ $? -eq ];then echo “This PHP make install end ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++”
else
echo “This PHP failed ,please check install shell ,exiting ……….” sleep 2s
echo “This PHP failed ,please check install shell ,exiting ……….” |mail -s “PHP make install failed” wgkgood@.com exit fi cp -r $srcpath/php.ini $apppath/php5/etc/ cp $srcpath/php-5.3./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm ;chmod o+x /etc/init.d/php-fpm
} Eacce_install ()
{
echo “Now install eaccelerator …………….,please waiting……………………..”
cd /usr/src && tar jxvf eaccelerator-0.9.6.1.tar.bz2 && cd eaccelerator-0.9.6.1 && $apppath/php5/bin/phpize && ./configure –enable-eaccelerator=shared –with-php-config=$apppath/php5/bin/php-config &&make &&make test &&make install &&mkdir -p /tmp/eaccelerator && chmod -R /tmp/eaccelerator if
[ $? -eq ];then echo “Install eaccelerator success ”
else
echo “Install eaccelerator failed ,please check ………………………”
fi } Mem_install ()
{
###########now install memcached ####################### echo “next install memcached……………………………………..” cd $srcpath && tar xzf memcache-2.2..tgz && cd memcache-2.2. && /usr/local/php5/bin/phpize && ./configure –prefix=$apppath/memcached –with-php-config=$apppath/php5/bin/php-config &&make &&make install if
[ $? -eq ];then echo “Install Memcache success ”
else
echo “Install Memcache failed ,please check ………………………”
fi
} EXIT ()
{
echo “Now not Install ,Please exit …………………..”
exit
} PS3=”Please Select Install Linux Packages: ” select option in Download Nginx_install Mysql_install Php_install Eacce_install Mem_install EXIT
do
$option
done
memcached 缓存安装配置:
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH # Check if user is root
if [ $(id -u) != "" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit
fi clear
cur_dir=$(pwd) get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs= count= > /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start install Memcached..."
char=`get_char` printf "=========================== install memcached ======================\n" wget -c http://soft.vpser.net/lib/libevent/libevent-2.0.13-stable.tar.gz
tar zxvf libevent-2.0.-stable.tar.gz
cd libevent-2.0.-stable/
./configure --prefix=/usr/local/libevent
make&& make install
cd ../ ln -s /usr/local/libevent/lib/libevent-2.0.so. /lib/libevent-2.0.so. wget -c http://soft.vpser.net/web/memcached/memcached-1.4.7.tar.gz
tar zxvf memcached-1.4..tar.gz
cd memcached-1.4./
./configure --prefix=/usr/local/memcached
make &&make install
cd ../ ln /usr/local/memcached/bin/memcached /usr/bin/memcached cp conf/memcached-init /etc/init.d/memcached
chmod +x /etc/init.d/memcached
useradd -s /sbin/nologin nobody if [ -s /etc/debian_version ]; then
update-rc.d -f memcached defaults
elif [ -s /etc/RedHat-release ]; then
chkconfig --level memcached on
fi echo "Starting Memcached..."
/etc/init.d/memcached start
mysql安装配置,已开启了indodb的支持
read mima
wget -c http://soft.vpser.net/datebase/mysql/mysql-5.1.60.tar.gz
tar -zxvf mysql-5.1..tar.gz
cd mysql-5.1./
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --with-plugins=max --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-innodb
make && make install
cd ../
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.
cp -f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod /etc/init.d/mysql
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
ldconfig ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
/etc/init.d/mysql start ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk /usr/local/mysql/bin/mysqladmin -u root password $mima /etc/init.d/mysql restart
mysql主从设置:
()首先确保主从服务器上的Mysql版本相同
()在主服务器上,设置一个从数据库的账户,使用REPLICATION SLAVE赋予权限,如: mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave001'@'10.10.10.59' IDENTIFIED BY
'';
Query OK, rows affected (0.13 sec) ()修改主数据库的配置文件my.cnf,开启BINLOG,并设置server-id的值,修改之后必须重启Mysql服务 [mysqld]
log-bin=mysql-bin
binlog-ignore-db= mysql
server-id= ()之后可以得到主服务器当前二进制日志名和偏移量,这个操作的目的是为了在从数据库启动后,从这个点开始进行数据的恢复 mysql> show master status\G;
*************************** . row ***************************
File: mysql-bin.
Position:
Binlog_Do_DB:
Binlog_Ignore_DB:
row in set (0.00 sec) ()好了,现在可以停止主数据的的更新操作,并生成主数据库的备份,我们可以通过mysqldump到处数据到从数据库,当然了,你也可以直接用cp命令将数据文件复制到从数据库去
注意在导出数据之前先对主数据库进行READ LOCK,以保证数据的一致性 mysql> flush tables with read lock;
Query OK, rows affected (0.19 sec) 之后是mysqldump mysqldump -h127.0.0. -p3306 -uroot -p test > /home/chenyz/test.sql 最好在主数据库备份完毕,恢复写操作 mysql> unlock tables;
Query OK, rows affected (0.28 sec) ()将刚才主数据备份的test.sql复制到从数据库,进行导入
()接着修改从数据库的my.cnf,增加server-id参数,指定复制使用的用户,主数据库服务器的ip,端口以及开始执行复制日志的文件和位置 [mysqld]
server-id=
log-bin=mysql-bin
master-host =10.10.10.58
master-user=test
master-pass=
master-port =
master-connect-retry=
replicate-do-db =test ()在从服务器上,启动slave进程 mysql> start slave; ()在从服务器进行show salve status验证 mysql> SHOW SLAVE STATUS\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: root
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: gbichot-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin .
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
LVS+Keepalived+Squid+Nginx+MySQL主从高性能集群架构部署方案的更多相关文章
- Lvs+Keepalived+Squid+Nginx负载均衡
前言* 随着互联网IT行业的发展,越来越多的企业开始使用开源软件搭建自己的web架构,主流的LVS也得到了广泛的应用,在保证高可用的同时,用户对网站的体验速度也有了很高的要求,这时候需要我们在我们的架 ...
- LVS+Keepalived 实现高可用负载均衡集群
LVS+Keepalived 实现高可用负载均衡集群 随着网站业务量的增长,网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如 F5 ,Array又太贵,你们又是创业型互联公司如何有效 ...
- 构建MHA实现MySQL高可用集群架构
一.MHA简介 MHA(Master HighAvailability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开 ...
- MySQL 8 InnoDB 集群生产部署
生产部署InnoDB集群 1.先决条件 InnoDB集群使用组复制技术,所以InnoDB中的实例需要满足组复制要求.可以查看MySQL文档中组复制相关的部分,也可以通过AdminAPI提供的dba.c ...
- Lvs+keepAlived实现负载均衡高可用集群(DR实现)
第1章 LVS 简介 1.1 LVS介绍 LVS是Linux Virtual Server的简写,意为Linux虚拟服务器,是虚拟的服务器集群系统,可在UNIX/LINUX平台下实现负载均衡集群功能. ...
- 手把手教程: CentOS 6.5 LVS + KeepAlived 搭建 负载均衡 高可用 集群
为了实现服务的高可用和可扩展,在网上找了几天的资料,现在终于配置完毕,现将心得公布处理,希望对和我一样刚入门的菜鸟能有一些帮助. 一.理论知识(原理) 我们不仅要知其然,而且要知其所以然,所以先给大家 ...
- MYSQL高可用集群架构-MHA架构
1 MHA简介:MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司 ...
- MySQL企业常用集群图解
mysql集群架构图片 1.mysql企业常用集群架构 在中小型互联网的企业中.mysql的集群一般就是上图的架构.WEB节点读取数据库的时候读取dbproxy服务器.dbproxy服务器通过对S ...
- 【MySQL】容器集群支持数据库实践
京东容器数据库系统,管理1800台物理计算节点,生产1W+ 多MySQL Docker容器实例.架构简单可靠,Docker容器计算平台与MySQL集群管理平台解耦处理.为描述方便,京东容器化数据库系统 ...
随机推荐
- iOS开发之SQLite-C语言接口规范(一)——Ready And Open Your SQLite
为什么要搞一搞SQLite的C语言接口规范呢? 因为在做iOS开发中难免会遇到操作数据库的情况,你可以使用第三方的FMDB等,或者使用CoreData.但我们还是有必要去搞清楚如何去使用SQLite的 ...
- cf201.div1 Number Transformation II 【贪心】
1 题目描述: 被给一系列的正整数x1,x2,x3...xn和两个非负整数a和b,通过下面两步操作将a转化为b: 1.对当前的a减1. 2.对当前a减去a % xi (i=1,2...n). 计算a转 ...
- MyCAT报java.lang.OutOfMemoryError: Java heap space
早上同事反映,mycat又假死了,估计还是内存溢出,查看了一下错误日志. INFO | jvm | // :: | java.lang.OutOfMemoryError: Java heap spac ...
- 深入instanceof
本文转自这里 规范中 instanceof 运算符定义 11.8.6 The instanceof operator The production RelationalExpression: Rela ...
- 使用普通用户替代root来管理IEE
环境:RHEL 6.4 + IEE 4.0.6 需求:IEE数据库之前是使用root用户部署和管理的,现在安全加固,将数据库交给普通用户iee来管理. 一.当前环境 二.安全加固 1.创建iee用户 ...
- Android测试提升效率批处理脚本
前言: APP测试过程中,经常需要用的一些命令,如adb,每次敲命令,虽可以加深印象,但个人认为那即繁琐又浪费时间.本文贴出一些我使用的批处理,以及一点点小小技巧. 目录 1.[查看APK文件信息.b ...
- 归一化变换 Normalizing transformations
归一化变换包含两个部分,图像坐标的平移和尺度的缩放.进行归一化的变换不但能够提高处理结果的精确度,而且通过选择一个标准的坐标系预先的消除了图像尺度和坐标原点的选择对算法最终结果的影响. 归一化变换的步 ...
- Linux 学习笔记
Linux学习笔记 请切换web视图查看,表格比较大,方法:视图>>web板式视图 博客园不能粘贴图片吗 http://wenku.baidu.com/view/bda1c3067fd53 ...
- SQL Server基础之《视图的概述和基本操作》
数据库中的视图是一个虚拟表.同真实的表一样,视图包含一系列带有名称的列和行数据,行和列数据用来自由定义视图和查询所引用的表,并且在引用视图时动态产生.本篇将通过一些实例来介绍视图的概念,视图的作用, ...
- jQuery-1.9.1源码分析系列(十五) 动画处理
首先需要有队列(queue)的基本知识.见上一章. a.动画入口jQuery.fn.animate函数执行流程详解 先根据参数调用jQuery.speed获取动画相关参数,得到一个类似如下的对象:并且 ...