1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #!/bin/bash# author: kuangl# mail: kuangl@orient-media.com# description: The installation of Nginx files.# -------------------------------------------------------- # ## Nginx_install# -------------------------------------------------------- ## Nginx installation#CURRENT_PATH=$(pwd)for i in $(rpm -q gcc gcc-c++ kernel-devel openssl-devel zlib-devel popt-devel popt-static libnl-devel wget make |grep 'not installed' | awk '{print $2}')do yum -y install $idone[ -d /root/software ][ "$?" != 0 ] && mkdir /root/softwarecd /root/software[ ! -e pcre-8.33.tar.gz ] && wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gztar -zxvf pcre-8.33.tar.gzcd pcre-8.33./configuremake && make installecho $? || [ $? != 0 ] || echo " installation pcre failed" || exit 1cd /root/software[ ! -e nginx-1.2.9.tar.gz ] && wget http://nginx.org/download/nginx-1.2.9.tar.gztar -zxvf nginx-1.2.9.tar.gzcd nginx-1.2.9./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_modulemake && make installecho $? || [ $? != 0 ] || echo " installation nginx failed" || exit 1# -------------------------------------------------------- # ## Keepalived_intsall# -------------------------------------------------------- ## Keepalived installationcd /root/softwarae[ ! -e keepalived-1.2.4.tar.gz ] && wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gztar -zxvf keepalived-1.2.4.tar.gzcd keepalived-1.2.4ln -s /usr/src/kernels/$(uname -r) /usr/src/kernels/linux./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/bin --libexecdir=/usr/libexec --localstatedir=/var --libdir=/lib64 --infodir=/usr/share/info --sysconfdir=/etc --mandir=/usr/local/share/man --with-kernel-dir=/usr/src/kernels/linuxmake && make installecho $? || [ $? != 0 ] || print " installation keepalived failed" || exit 1chkconfig --add keepalivedchkconfig --level 345 keepalived on |
1 2 3 4 5 | [root@node4 ~]# yum -y install httpd[root@node4 html]# echo "this is 192.168.122.4" > /var/www/htmlindex.html[root@node4 ~]# service httpd start[root@node4 html]# curl 192.168.122.4this is 192.168.122.4 |
1 2 3 4 5 | [root@node5 ~]# yum -y install httpd[root@node5 html]# echo "this is 192.168.122.5" > /var/www/htmlindex.html[root@node5 ~]# service httpd start[root@node5 html]# curl 192.168.122.5this is 192.168.122.5 |
1 2 3 4 5 | [root@node6 ~]# yum -y install httpd[root@node6 html]# echo "this is 192.168.122.6" > /var/www/htmlindex.html[root@node6 ~]# service httpd start[root@node6 html]# curl 192.168.122.6this is 192.168.122.6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@node2 ~]# vim /usr/local/nginx/conf/nginx.confupstream web1 ##定义负载均衡组为web1 { ip_hash; server 192.168.122.4:80; server 192.168.122.5:80; server 192.168.122.6:80; } server { listen 80; server_name dev.test01.com; location / { root /home/kuangl/; index index.html index.htm; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://web1; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | [root@node2 conf]# vim /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs { notification_email { 404060945@qq.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script chk_haproxy { script "/etc/keepalived/chk_nginx.sh" interval 2 weight 2}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 200 priority 250 advert_int 1 authentication { auth_type PASS auth_pass kuanglnginx } track_script { chk_nginx } virtual_ipaddress { 192.168.122.22 }}vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 251 priority 100 advert_int 1 authentication { auth_type PASS auth_pass kuangl } track_script { chk_nginx } virtual_ipaddress { 192.168.122.23 }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ! Configuration File for keepalivedglobal_defs { notification_email { 404060945@qq.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script chk_haproxy { script "/etc/keepalived/chk_nginx.sh" interval 2 weight 2}vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 200 priority 100 advert_int 1 authentication { auth_type PASS auth_pass kuanglnginx } track_script { chk_nginx } virtual_ipaddress { 192.168.122.22 }}vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 251 priority 250 advert_int 1 authentication { auth_type PASS auth_pass kuangl } track_script { chk_nginx } virtual_ipaddress { 192.168.122.23 }} |
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/bash# description:# 定时查看nginx是否存在,如果不存在则启动nginx# 如果启动失败,则停止keepalivedstatus=$(ps -C nginx --no-heading|wc -l)if [ "${status}" = "0" ]; then /usr/local/nginx/sbin/nginx status2=$(ps -C nginx --no-heading|wc -l) if [ "${status2}" = "0" ]; then /etc/init.d/keepalived stop fifi |
1 2 3 4 | [root@node2 ~]# service keepalived start[root@node2 ~]# /usr/local/nginx/sbin/nginx[root@node3 ~]# service keepalived start[root@node3 ~]# /usr/local/nginx/sbin/nginx |
1 2 3 4 5 6 7 8 9 10 11 12 | [kuangl@node01 ~]$ curl http://192.168.122.22this is 192.168.122.6[kuangl@node01 ~]$ curl http://192.168.122.22this is 192.168.122.4[kuangl@node01 ~]$ curl http://192.168.122.22this is 192.168.122.5[kuangl@node01 ~]$ curl http://192.168.122.23this is 192.168.122.6[kuangl@node01 ~]$ curl http://192.168.122.23this is 192.168.122.4[kuangl@node01 ~]$ curl http://192.168.122.23this is 192.168.122.5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [root@node5 ~]# yum -y install rsync[root@node5 ~]# vim /etc/rsynsd.confuid = rootgid = rootuse chroot = nomax connections = 5pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[web01] path=/home/kuangl/ comment = update ignore errors read only = no list = no hosts allow = 192.168.122.0/24auth users = root uid = rootgid = rootsecrets file = /etc/rsyncd.secrets[root@node5 ~]# vim /etc/rsyncd.secretsroot:123456[root@node5 ~]# chmod 0600 /etc/rsyncd.secrets[root@node5 ~]# ll /etc/rsyncd.secrets-rw-------. 1 root root 12 Jul 20 19:41 /etc/rsyncd.secrets[root@node5 ~]# rsync --daemon[root@node5 ~]# echo "rsync --daemon" >> /etc/rc.local |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@node4 ~]# yum -y install rsync[root@node4 ~]# vim /etc/rsyncd.secrets123456[root@node4 ~]# chmod 0600 /etc/rsyncd.secretsroot@node4 kuangl]# rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets rsync+inotify root@192.168.122.5::web01sending incremental file listrsync+inotify/rsync+inotify/inotify-tools-3.14.tar.gz 358772 100% 1.85MB/s 0:00:00 (xfer#1, to-check=2/4)rsync+inotify/rsync+inotify_client.sh 617 100% 3.11kB/s 0:00:00 (xfer#2, to-check=1/4)rsync+inotify/rsync+inotify_server.sh 900 100% 4.03kB/s 0:00:00 (xfer#3, to-check=0/4)sent 360679 bytes received 69 bytes 240498.67 bytes/sectotal size is 360289 speedup is 1.00 |
1 2 3 4 5 | [root@node5 ~]# cd /home/kuangl/[root@node5 kuangl]# lltotal 8-rw-r--r--. 1 root root 22 Jul 20 15:16 index.htmldrwxr-xr-x. 2 root root 4096 Nov 11 2012 rsync+inotify |
所有评论
加载评论 ...
发表评论


