LVS+Keepalived+Squid+Nginx+MySQL主从高性能集群架构部署方案
LVS+Keepalived+Squid+Nginx+MySQL主从高性能集群架构部署方案
方案一,在tomcat的workers.properties里面配置相关条件
worker.tomcat.lbfactor=====
Linux内核优化:
vi /etc/sysctl.conf # 编辑sysctl.conf文件添加以下内容
net.ipv4.tcp_rmem = = = = = = = = = = = = = = = = = = = =
以上配置说明:
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.ipv4.tcp_max_orphans = 3276800:系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。
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 配置:
master的配置:mkdir /usr/local/src//usr/local/src/
wget http:
|--s /usr/src/kernels/$(uname -r)/usr/src/-s /usr/src/kernels/.* /usr/src/--&&-.-./configure&& make &&/usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d//usr/local/etc/sysconfig/keepalived /etc/sysconfig//etc//usr/local/etc/keepalived/keepalived.conf /etc/keepalived//usr/local/sbin/keepalived /usr/sbin/|>> /usr/local/etc/keepalived/keepalived.conf <<! Configuration File . # 另一端 .. . . .
backup主机的配置:
mkdir /usr/local/src//usr/local/src/
wget http:
|--s /usr/src/kernels/$(uname -r)/usr/src/-s /usr/src/kernels/.* /usr/src/--&&-.-./configure&& make &&/usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d//usr/local/etc/sysconfig/keepalived /etc/sysconfig//etc//usr/local/etc/keepalived/keepalived.conf /etc/keepalived//usr/local/sbin/keepalived /usr/sbin/|>> /usr/local/etc/keepalived/keepalived.conf <<! Configuration File ... . . .
Squid缓存反向代理配置:
#!/bin/
tar jxvf squid-/configure --prefix=/usr/local/--enable--io=--enable-storeio=--enable-useragent---enable-referer---enable-kill-parent---enable-forward---enable---enable-cache---enable--err-language=--enable---enable-removal-policies=--enable-large-cache---disable----enable-x-accelerator---enable-follow-x-forwarded---disable-ident---with-large---with-filedescriptors=>> /usr/local/squid/etc/squid.conf <<.:/tmp1 ^ftp: % ^gopher: % % %>a %ui %un [%tl] %Hs %<st %Ss:%//log/squid///log/squid///log/squid/./.-----i ^-i .+. parent no-query originserver name=web1 round-. parent no-query originserver name=web2 round-.com *..^ftp: % ^gopher: % ^gopher: % % -i \.css$ % -i \.js$ % -i \.html$ % -i \.jpg$ % -i \.gif$ % -i \.swf$ % -i \.jpg$ % -i \.png$ % -i \.bmp$ % -i \.doc$ % -i \.ppt$ % -i \.xls$ % -i \.pdf$ % -i \.rar$ % -i \.zip$ % -i \.txt$ % ///log/-R nobody:nobody / /-R nobody:nobody //log//usr/local/squid/sbin/squid - > /proc/sys/fs/file--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.linuxboy.net
qingli.sh jpg
qingli.sh linuxboy.net 123 bbb jpg
#!/bin/==-a -r $ $squidcache_path
下面是3.1的安装,针对需要3.1部分模块的朋友,但是不推荐用3.1
tar -zxvf squid-.---.--/configure --prefix=/usr/local/squid --enable--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-&&-g squid -s /sbin/-R squid /usr/local/squid/-p //-p //-R //cache //-R //cache ///usr/local/squid/etc/squid.conf /usr/local/squid/etc//usr/local/squid/etc/. sibling . sibling . sibling -. parent no-query originserver round-robin name=. parent no-query originserver round-robin name=--bin ?-i ^https:\\ ?-i cgi-bin \?-i ^/usr/local/squid//logs//usr/local/squid//logs///cache #设定缓存目录cache,目录容量最大1024M,*//squid #设定缓存目录squid,目录容量最大3072M,*%以上时,新的内容将取代旧的内容,直到空间又下降到90%
/usr/local/squid/sbin/squid -/usr/local/squid/sbin/squid
配置lvs客户端模式
#!/bin/=./etc/rc.d/init.d/ $SNS_VIP netmask ./sbin/route add -host $SNS_VIP dev lo: >/proc/sys/net/ipv4/conf/lo/ >/proc/sys/net/ipv4/conf/lo/ >/proc/sys/net/ipv4/conf/all/ >/proc/sys/net/ipv4/conf/all/>/dev/ >& >/proc/sys/net/ipv4/conf/lo/ >/proc/sys/net/ipv4/conf/lo/ >/proc/sys/net/ipv4/conf/all/ >/proc/sys/net/ipv4/conf/all/*
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/=/usr/=/usr/
-ne && wget http:
[ $? -eq --&& tar xzf pcre-.tar.gz && cd pcre- && ./configure –prefix=$apppath/pcre && make &&? -eq ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&& tar xzf nginx-..tar.gz && cd nginx-. && ./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- –user=www –group=-r $srcpath/{nginx.conf,fcgi.conf} $apppath/nginx/conf/
[ $? -eq --&& tar xzf mysql-..tar.gz && cd mysql-. && ./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 && [ $? -eq --/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 /&& yum install -y libevent* &&cd $srcpath &&tar jxvf php-..tar.bz2 && cd php-. && ./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 &&? -eq ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|mail -s “PHP make install failed” wgkgood@-r $srcpath/php.ini $apppath/php5/etc//php-./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm ;chmod o+x /etc/init.d/php-/usr/src && tar jxvf eaccelerator-..tar.bz2 && cd eaccelerator-. && $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/? -eq && tar xzf memcache-..tgz && cd memcache-. && /usr/local/php5/bin/phpize && ./configure –prefix=$apppath/memcached –with-php-config=$apppath/php5/bin/php-config &&make &&? -eq = option
memcached 缓存安装配置:
#!/bin/=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/ user [ $(id -u) != ==`stty --=/dev/tty bs= count= > /dev/-
=-c http:
tar zxvf libevent-.--.-stable//configure --prefix=/usr/local/&&/-s /usr/local/libevent/lib/libevent-.so. /lib/libevent-.so.-c http:
tar zxvf memcached-.-.//configure --prefix=/usr/local/&&//usr/local/memcached/bin/memcached /usr/bin//memcached-init /etc/init.d/+x /etc/init.d/-s /sbin/ [ -s /etc/-rc.d --s /etc/RedHat---level
/etc/init.d/memcached start
mysql安装配置,已开启了indodb的支持
-c http:
tar -zxvf mysql-.-.//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-&&/-s /sbin/nologin -M --f /usr/local/mysql/share/mysql/my-medium.cnf /etc/-i /etc//usr/local/mysql/bin/mysql_install_db --user=-R mysql /usr/local/mysql/-R mysql /usr/local/mysql/-f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/ /etc/init.d/> /etc/ld.so.conf.d/mysql.conf<</usr/local/mysql/lib//usr/local/-s /usr/local/mysql/lib/mysql /usr/lib/-s /usr/local/mysql/include/mysql /usr/include//etc/init.d/-s /usr/local/mysql/bin/mysql /usr/bin/-s /usr/local/mysql/bin/mysqldump /usr/bin/-s /usr/local/mysql/bin/myisamchk /usr/bin//usr/local/mysql/bin/mysqladmin -/etc/init.d/mysql restart
mysql主从设置:
(> GRANT REPLICATION SLAVE ON *.* TO @ rows affected ()修改主数据库的配置文件my.cnf,开启BINLOG,并设置server--bin=mysql--ignore-db=-id=>*************************** . row ***************************-bin. row (> flush tables with read rows affected (-h127.. -p3306 -uroot -p test > /home/chenyz/> rows affected ()接着修改从数据库的my.cnf,增加server--id=-bin=mysql--host =.-user=-pass=-port =-connect-retry=--db =>>*************************** . row *************************** master to send -bin.-relay-bin.-bin .
评论暂时关闭