linux运维实战练习-2016年3月4日-3月19日课程作业

1、搭建LAMP环境,并实践基于DNS做基于域名的虚拟主机。

搭建LAMP环境:

            [root@mini ~]# yum install httpd mariadb-server php php-mysql

    初始化mariadb:

            

            [root@mini ~]# mysql_secure_installation

基于DNS做基于域名的虚拟主机

            [root@mini ~]# vim /etc/httpd/conf.d/myhoust.conf    
            <VirtualHost *:80>
              ServerName www.myhost.com
              DocumentRoot "/web/"
            </VirtualHost>



2、基于1题目中的环境,重新搭建一个同样的环境,要求:

   a)实现web服务文件更新的自动同步到另一台机器上

host1

                    [root@mini ~]# yum install nfs-utils rpcbind            
                    [root@mini ~]# vim /etc/exports
                    /web *(rw,sync)

host2

                    [root@ee-a ~]# mount -t nfs 10.9.9.7:/web /web

   b)数据库实现主从复制

master:ee-o 

                my.cnf                
                log-bin=/tmp/mysql-bin
                server-id=1

slava:ee-a

                    my.cnf                    
                    log-bin=/tmp/mysql-bin
                    server-id=2

2.授权slave

                    MariaDB [ab]> grant replication slave on *.* to 'ee-a'@'10.9.9.16';

3.查看bin日志

                    MariaDB [(none)]> show master logs;                    
                    +-----------------+-----------+
                    | Log_name        | File_size |
                    +-----------------+-----------+
                    | mysql-bi.000001 |       245 |
                    +-----------------+-----------+

4.salve

                MariaDB [(none)]> change master to                    
                    -> master_host='10.9.9.1',
                    -> master_port=3306,
                    -> master_user='ee-a',
                    -> master_password='',
                    -> master_log_file='mysql-bi.000001',
                    -> master_log_pos=245;
                    MariaDB [(none)]> start slave;



   c)通过shell脚本实现网站源代码备份和mysql备份,备份策略包括全量备份、增量备份、差异备份

                    #!bin/bash                    
                    #全量备份
                    tar -cf /bak/web.bak`date +%y%m%d` /web
                    mysqldump -uab -phello -A > mariadb.dump
                    #!bin/bash
                    #增量备份
                    read -p "请输入这是第几次备份" level
                    dupm -l $(( $levle-1 )) -f /bak/web`date +%y%m%d` /web
                    mysqldump -uab -phello -A > mariadb.dump
                    #!bin/bash
                    #差异备份
                    read -p "0:第一次备份;1:非第一次备份" level
                    dupm -l $level -f /bak/web`date +%y%m%d` /web
                    mysqldump -uab -phello -A > mariadb.dump

3、使用压测工具(ab/webbench等)实现搭建的页面压测,要求通过调整apache的工作模式来对比最后性能。

[root@mini ~]# ab -c 1000 -n 100000 http://10.9.9.7/index.html
prefork:
Concurrency Level:      1000
Time taken for tests:   45.518 seconds
Complete requests:      100000
Failed requests:        80
   (Connect: 0, Receive: 0, Length: 80, Exceptions: 0)
Write errors:           0
Non-2xx responses:      99985
Total transferred:      38694195 bytes
HTML transferred:       20796880 bytes
Requests per second:    2196.94 [#/sec] (mean)
Time per request:       455.178 [ms] (mean)
Time per request:       0.455 [ms] (mean, across all concurrent requests)
Transfer rate:          830.16 [Kbytes/sec] received
worker:
Concurrency Level:      1000
Time taken for tests:   37.335 seconds
Complete requests:      100000
Failed requests:        118
   (Connect: 0, Receive: 0, Length: 118, Exceptions: 0)
Write errors:           0
Non-2xx responses:      99998
Total transferred:      38699226 bytes
HTML transferred:       20799584 bytes
Requests per second:    2678.45 [#/sec] (mean)
Time per request:       373.350 [ms] (mean)
Time per request:       0.373 [ms] (mean, across all concurrent requests)
Transfer rate:          1012.24 [Kbytes/sec] received
event:
Concurrency Level:      1000
Time taken for tests:   21.753 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Non-2xx responses:      100000
Total transferred:      38700000 bytes
HTML transferred:       20800000 bytes
Requests per second:    4597.15 [#/sec] (mean)
Time per request:       217.526 [ms] (mean)
Time per request:       0.218 [ms] (mean, across all concurrent requests)
Transfer rate:          1737.40 [Kbytes/sec] received
prefork<worker<event

  


4、基于3步骤过程中的压测,通过脚本实现iptables自动判断来源ip,并作拒绝制定ip访问,要求访问次数1秒超过10次的拒绝掉。





5、基于2中的环境,通过lvs实现负载均衡,要求使用DR模式,并能把其中的原理部分通过自己的理解汇总出来。

[root@ee-o ~]# ip addr add 10.9.9.8/32 dev eno16777736 ##配置vip
[root@ee-o ~]# ip route add 10.9.9.8 dev eno16777736
[root@ee-o ~]# echo 1 >/proc/sys/net/ipv4/ip_forward
[root@ee-o ~]# ipvsadm -C
[root@ee-o ~]# ipvsadm -A -t 10.9.9.9:80 -p 5 -s rr
[root@ee-o ~]# ipvsadm -a -t 10.9.9.9:80 -r 10.9.9.1:80 -g
[root@ee-o ~]# ipvsadm -a -t 10.9.9.9:80 -r 10.9.9.2:80 -g
RS1:10.9.9.1
[root@ee-o ~]# ip addr 10.9.9.8/32 dev lo
[root@ee-o ~]# ip route add 10.9.9.8 dev lo
[root@ee-o ~]# echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@ee-o ~]# echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
[root@ee-o ~]# echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce
[root@ee-o ~]# echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
RS1:10.9.9.2
[root@ee-o ~]# ip addr 10.9.9.8/32 dev lo
[root@ee-o ~]# ip route add 10.9.9.8 dev lo
[root@ee-o ~]# echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@ee-o ~]# echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
[root@ee-o ~]# echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce
[root@ee-o ~]# echo 2>/proc/sys/net/ipv4/conf/all/arp_announce

LVS-DR原理

利用LAN内主机基于ARP协议通信的原理,当客户端的数据包到达virtual server后修改其二层封装地址为real server,再将数据包转发至ARP表对应的主机,最后real server处理请求直接发回客户端;


你可能感兴趣的:(linux,虚拟主机,课程)