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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

I.作业(练习)内容:

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

搭建LAMP环境步骤:

1. 下载相应的软件包至/usr/local/src目前下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~] # ls /usr/local/src/ | grep 'tar*'    
apr-1.4.6. tar .gz     
apr-1.5.2. tar .gz     
apr-util-1.5.1. tar .gz     
autoconf-2.69. tar .gz     
freetype-2.4.10. tar .gz     
gd-2.0.35. tar .gz     
httpd-2.4.3. tar .gz     
jpegsrc.v8b. tar .gz     
libmcrypt-2.5.8. tar .gz     
libpng-1.5.14. tar .gz     
libxml2-2.9.0. tar .gz     
php-5.4.11. tar .gz     
phpMyAdmin-3.5.6-all-languages. tar .gz     
xunzai.com_mysql-5.0.18. tar .gz     
ZendGuard-5_5_0. tar .gz     
zlib-1.2.7. tar .gz

2. 软件的安装分配置(configure)、编译(make)、和安装(make install)三个步骤,以下将分别演示安装步骤:

安装libxm12

1
2
3
4
5
6
7
[root@localhost src] # tar zxvf libxml2-2.9.0.tar.gz  解压文件    
[root@localhost src] # cd libxml2-2.9.0/  切换目录     
[root@localhost libxml2-2.9.0] # ./configure --prefix=/usr/local /libxml2 配置,指定安装到/usr/local /libxml2 目录下     
[root@localhost libxml2-2.9.0] # make 进行编译     
[root@localhost libxml2-2.9.0] # make install   开始安装libxm12库文件
安装成功在“ /usr/local/libxm12 ”目录下有以下四个文件
[root@localhost ~] # ls /usr/local/libxm12    bin  include  lib  share

安装gcc

1
[root@localhost] # yum install gcc gcc-c++ gcc-g77

安装libmcrypt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost src] # tar zxvf libmcrypt-2.5.8.tar.gz  解压    
[root@localhost src] # cd libmcrypt-2.5.8/  切换目录     
[root@localhost libmcrypt-2.5.8] # ./configure with-mcrypt-dir=/usr/local/libmcrypt   安装文件     
[root@localhost libmcrypt-2.5.8] # yum install gcc gcc-c++ gcc-g77  安装gcc     
[root@localhost libmcrypt-2.5.8] # cd libltdl/     
[root@localhost libltdl] # ./configure --enable-ltdl-install     
[root@localhost libltdl] # make     
[root@localhost libltdl] # make install     
make [1]: Entering directory ` /usr/local/src/libmcrypt-2 .5.8 /libltdl '     
/bin/sh  ./.. /mkinstalldirs  /usr/local/lib     
/bin/sh  . /libtool   --mode= install  /usr/bin/install  -c libltdl.la  /usr/local/lib/libltdl .la     
/usr/bin/install  -c .libs /libltdl .lai  /usr/local/lib/libltdl .la     
/usr/bin/install  -c .libs /libltdl .a  /usr/local/lib/libltdl .a     
ranlib  /usr/local/lib/libltdl .a     
chmod  644  /usr/local/lib/libltdl .a     
PATH= "$PATH:/sbin"  ldconfig -n  /usr/local/lib     
----------------------------------------------------------------------     
Libraries have been installed  in :     
    /usr/local/lib

安装zlib

1
2
3
4
5
6
7
[root@localhost src] # tar zxvf zlib-1.2.7.tar.gz    
[root@localhost src] # cd zlib-1.2.7/     
[root@localhost zlib-1.2.7] # ./configure -with- zlib-dir=/usr/local/libmcrypt     
[root@localhost zlib-1.2.7] # make     
[root@localhost zlib-1.2.7] # make install     
[root@localhost zlib-1.2.7] # ls /usr/local/zlib/  
include  lib  share

安装libpng

1
2
3
4
5
[root@localhost src] # tar libpng-1.5.14.tar.gz ^C    
[root@localhost src] # cd libpng-1.5.14/     
[root@localhost libpng-1.5.14] # ./configure --prefix=/usr/local/libpng^C     
[root@localhost libpng-1.5.14] # ls /usr/local/libpng/     
bin  include  lib  share

安装jpeg8

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~] # mkdir /usr/local/jpeg8  //建立jpeg8软件安装目录    
[root@localhost ~] # mkdir /usr/local/jpeg8/bin  //建立存放命令的目录     
[root@localhost ~] # mkdir /usr/local/jpeg8/lib  //创建jpeg8库文件所在目录     
[root@localhost ~] # mkdir /usr/local/jpeg8/include  //建立存放头文件目录     
[root@localhost ~] # mkdir /usr/local/jpeg8/man/man1 //建立存放手册的目录     
[root@localhost ~] # tar zxvf /usr/local/src/jpeg //解压     
jpeg-8b/            jpegsrc.v8b. tar .gz  
[root@localhost ~] # tar zxvf /usr/local/src/jpeg     
jpeg-8b/            jpegsrc.v8b. tar .gz  
[root@localhost ~] # tar zxvf /usr/local/src/jpegsrc.v8b.tar.gz     
[root@localhost ~] # cd /usr/local/src/jpeg-8b/     
[root@localhost jpeg-8b] # ./configgure --prefix=/usr/local/jpeg8/ --enable-share --enable-static

安装freetype

1
2
3
4
5
6
7
[root@localhost src] # tar zxvf freetype-2.4.10.tar.gz //解压包到freetype-2.4.10目录    
[root@localhost src] # cd freetype-2.4.10/  //进入目录freetype-2.4.10中     
[root@localhost freetype-2.4.10] # ./configure --prefix=/usr/local/freetype //编译     
[root@localhost freetype-2.4.10] # make  //对软件源代码文件进行编译     
[root@localhost freetype-2.4.10] # make install  //开始安装freetype库文件     
[root@localhost freetype-2.4.10] # ls /usr/local/freetype/ //软件安装成功,在该目录下有以下4个文件     
bin  include  lib  share

安装atuoconf

1
2
3
4
5
6
7
8
9
10
11
[root@localhost src] # tar zxvf autoconf-2.69.tar.gz    
[root@localhost src] # cd autoconf-2.69/     
[root@localhost autoconf-2.69] # ./configure \  //配置命令     
>--prefix= /usr/local/gd  \    // 指定安装软件的位置     
>--with-jpeg= /usr/local/jpeg8/  \    // 指定去哪找jpeg库文件     
>--with-png= /usr/local/libpng/   \   // 指定去哪找png库文件     
>--with-freetype= /usr/local/freetype/     
[root@localhost autoconf-2.69] # make
[root@localhost autoconf-2.69] # make install
[root@localhost autoconf-2.69] # ls /usr/local/gd
bin  include  lib

安装apr

1
2
3
[root@localhost src] # tar apr-1.5.2.tar.gz    
[root@localhost src] # cd apr-1.5.2/     
[root@localhost apr-1.5.2] # ./configure --prefix=/usr/local/apr-httpd/ && make && make install

安装apr-util

1
2
3
4
[root@localhost apr-1.5.2] # cd /usr/local/src/    
[root@localhost src] # tar apr-util-1.5.1.tar.gz     
[root@localhost src] # cd apr-util-1.5.1/     
[root@localhost apr-util-1.5.1] # ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/ && make && make install

安装pcre

1
2
3
4
[root@localhost apr-util-1.5.1] # cd /usr/local/src/    
[root@localhost src] # unzip -o pcre-8.32.zip     
[root@localhost src] # cd pcre-8.32/     
[root@localhost pcre-8.32] # .#./configure --prefix=/usr/local/pcre && make && make

安装Httpd

1
2
3
4
5
6
7
8
9
[root@localhost src] # tar xzvf httpd-2.4.3.tar.gz    
[root@localhost src] # cd httpd-2.4.3/     
[root@localhost httpd-2.4.3] # ./configure --prefix=/usr/local/apache243 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-static-support     
--sysconfdir= /etc/httpd  --with-z= /usr/local/zlib/  --with-apr= /usr/local/apr-httpd/  --with-apr-util= /usr/local/apr-util-httpd/  --with-pcre= /usr/local/pcre/  --disable-userdir     
[root@localhost ~] # make     
[root@localhost ~] #     
[root@localhost ~] # make install     
[root@localhost ~] # ls /usr/local/apache243/  安装成功检测该文件夹下是否有以下文件     
bin  build  cgi-bin  error  htdocs  icons  include  lib  logs   man   manual  modules

修改httpd.conf配置文件,添加如下一行

image

重启Apache服务器,确认80端口已经处理监听状态

1
2
3
4
[root@localhost ~] # /usr/local/apache243/bin/apachectl start    
httpd (pid 130058) already running     
[root@localhost ~] # netstat -tnl | grep 80     
tcp6       0      0 :::80                   :::*                    LISTEN

确认Apache服务器可以使用

image

将Apache服务器设置开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~] # echo "/usr/local/apache243/bin/apachectl start" >> /etc/rc.d/rc.local[root@localhost ~]# cat /etc/rc.d/rc.local     
#!/bin/bash     
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES     
#     
# It is highly advisable to create own systemd services or udev rules     
# to run scripts during boot instead of using this file.     
#     
# In contrast to previous versions due to parallel execution during boot     
# this script will NOT be run after all other services.     
#     
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure     
# that this script will be executed during boot.
touch  /var/lock/subsys/local    
/usr/local/apache243/bin/apachectl  start

安装Mysql数据库

1
2
3
4
5
6
7
8
[root@localhost mysql-5.0.18] # tar xvzf mysql-5.0.18    
[root@localhost mysql-5.0.18] # cd mysql-5.0.18/     
[root@localhost mysql-5.0.18] # ./configure --prefix=/usr/local/mysql --enable-thread-safe-client --with-extra-charsets=all
config.status: ib_config.h is unchanged    
config.status: executing depfiles commands
MySQL has a Web site at http: //www .mysql.com/  which  carries details on the latest release, upcoming features, and other information to  make  your work or play with MySQL  more  productive. There you can also  find  information about mailing lists  for  MySQL discussion.
Remember to check the platform specific part of the reference manual  for     hints about installing MySQL on your platform. Also have a  look  at the     files  in  the Docs directory.
Thank you  for  choosing MySQL!

添加用户名和用户组

1
2
[root@localhost mysql-5.0.18] # groupadd mysql    
[root@localhost mysql-5.0.18] # useradd -g mysql mysql

创建mysql数据库服务器的配置文件,可以使用源码包support-files目录中的my-medium.cnf文件作为模板,将其复制到/etc/目录下,命名为my.cnf文件

1
[root@localhost mysql-5.0.18] # cp support-files/my-medium.cnf /etc/my.cnf

进入到安装目录/usr/local/mysql下,执行bin目录下的mysql_install_db脚本,用来初始化MySQL数据库的授权表,其中存储了服务器访问允许

1
2
[root@localhost mysql-5.0.18] # cd /usr/local/mysql    
[root@localhost mysql] # bin/mysql_install_db --user=mysql

将程序二进制的所有权改为root用户,数据目录的所有权改为运行mysqld程序的mysql用户

1
2
3
[root@localhost mysql] # chown -R root .  //将文件的所有属性改为root用户    
[root@localhost mysql] # whown -R mysql var  //将数据目录的所有属性改为mysql用户     
[root@localhost mysql] # chgrp -R mysql .   //将组属性改为mysql组

确认mysql目录下生成以下10个文件

1
2
3
4
[root@localhost mysql] # pwd    
/usr/local/mysql     
[root@localhost mysql] # ls     
bin  include  info  lib  libexec   man   mysql- test   share  sql-bench  var

启动Mysql

1
2
[root@localhost mysql] # /usr/local/mysql/bin/mysqld_safe --user=mysql &    
[1] 36598

确认Mysql对应 的端口号3306正常打开

1
2
[root@localhost mysql] # netstat -tnl | grep 3306    
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

检测Mysql服务器是否正常工作

查看Mysql的版本

1
2
3
4
[root@localhost mysql] # bin/mysqladmin version    
bin /mysqladmin   Ver 8.41 Distrib 5.0.18,  for  unknown-linux-gnu on x86_64 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is  free  software,and you are welcome to modify and redistribute it underthe GPL license
Server version        5.0.18-log    Protocol version    10     Connection        Localhost via UNIX socket     UNIX socket         /tmp/mysql .sock     Uptime:            1 day 2 hours 58 min 37 sec
Threads: 1  Questions: 12  Slow queries: 0  Opens: 0  Flush tables: 2  Open tables: 1  Queries per second avg: 0.000

设置密码:

1
2
3
4
5
6
7
[root@localhost mysql] # bin/mysql -u root -h localhost -p    
Enter password:     
Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection  id  is 11 to server version: 5.0.18-log
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the buffer.
mysql>  set  password  for  'root' @ 'localhost' =password( 'abc012' );    
Query OK, 0 rows affected (0.01 sec)
mysql>  exit     Bye

mysql服务器和apache服务器一样也有必要设置为开机自动运行,设置方法进入到mysql源代码目录/usr/local/src /mysql-5.0.18,将子目录support-files下的mysql.server文件复制到/etc/rc.d/init.d目录中,并重 命名为mysqld,命令行如下

1
2
3
4
5
6
7
8
9
[root@localhost mysql] # cd /usr/local/src/mysql-5.0.18   
[root@localhost mysql-5.0.18] # cp support-files/mysql.server /etc/rc.d/init.d/mysqld     [root@localhost mysql-5.0.18]# chown root.root /etc/rc.d/init.d/mysqld  //修改权限     
[root@localhost mysql-5.0.18] # chmod 755 /etc/rc.d/init.d/mysqld     
[root@localhost mysql-5.0.18] # chkconfig --add mysqld  //把mysqld添加到chkconfig中     
[root@localhost mysql-5.0.18] # chkconfig --level 3 mysqld on    //加入运行级别三开机启动 [root@localhost mysql-5.0.18]# chkconfig --level 5 mysqld on  //加入运行级别五开机启动  
[root@localhost mysql-5.0.18] # chkconfig --list mysqld  //检查设置
Note: This output shows SysV services only and does not include native          systemd services. SysV configuration data might be overridden by native           systemd configuration.
       If you want to list systemd services use  'systemctl list-unit-files' .          To see services enabled on particular target use            'systemctl list-dependencies [target]' .
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

安装PHP

编译PHP

1
[root@localhost php-5.4.11] # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache243/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-png-dir=/usr/local/libpng/ --with-jpeg-dir=/usr/local/jpeg8/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd/ --with-zlib-dir=/usr/local/zlib/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets

编译PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@localhost php-5.4.11] # make
lxml2 -lz -lm -ldl -lmysqlclient_r -lz -lcrypt -lnsl -lm -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt  -o sapi /cgi/php-cgi    
Generating phar.php     
Generating phar.phar     
PEAR package 
PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.  clicommand.inc     
directorygraphiterator.inc     
directorytreeiterator.inc     
invertedregexiterator.inc     
pharcommand.inc     
phar.inc
Build complete.    
Don 't forget to run ' make  test '.
[root@localhost php-5.4.11] # make install
[PEAR] XML_Util       - installed: 1.2.1    
[PEAR] PEAR           - installed: 1.9.4     
Wrote PEAR system config  file  at:  /usr/local/php/etc/pear .conf     
You may want to add:  /usr/local/php/lib/php  to your php.ini include_path     
/usr/local/src/php-5 .4.11 /build/shtool  install  -c ext /phar/phar .phar  /usr/local/php/bin   ln  -s -f  /usr/local/php/bin/phar .phar  /usr/local/php/bin/phar     
Installing PDO headers:          
/usr/local/php/include/php/ext/pdo/

创建PHP测试页

1
2
3
4
[root@localhost php-5.4.11] # cat /usr/local/apache243/htdocs/text.php    
<?php     
phpinfo();     
?>

重启Apache服务器

1
2
[root@localhost php-5.4.11] # /usr/local/apache243/bin/apachectl stop    
[root@localhost php-5.4.11] # /usr/local/apache243/bin/apachectl start

成功访问刚刚创建的测试页

 image

phpMyAdmin安装

解压安装文件

1
[root@localhost src] # tar xzvf phpMyAdmin-3.5.6-all-languages.tar.gz

将解压的目录下的所有文件复制/usr/local/apache243/htdocs/phpmyadmin下

1
2
[root@localhost src] # cp -a phpMyAdmin-3.5.6-all-languages 
/usr/local/apache243/htdocs/phpmyadmin

PhpMyAdmin(config.inc.php)配置文件,默认不存在config.inc.php文件,我们需要手工创建一个,也可以复制config.sample.inc.php,这时,我们以cookie身份验证模式

1
2
[root@localhost src] # cd /usr/local/apache243/htdocs/phpmyadmin/    
[root@localhost phpmyadmin] # cp config.sample.inc.php config.inc.php

修改如下

phpmyadmin

成功访问PhpMyAdmin下在的index.php

image

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

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

   b)数据库实现主从复制

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

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

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

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










本文转自 Nico_Lv 51CTO博客,原文链接:http://blog.51cto.com/nearlv/1752970,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
运维 Linux Apache
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
22 2
|
1月前
|
域名解析 Linux Apache
Linux Apache服务详解——虚拟网站主机功能实战
Linux Apache服务详解——虚拟网站主机功能实战
34 5
|
1月前
|
Linux 数据安全/隐私保护 Windows
Linux vsFTPd服务详解——本地用户登录实战
Linux vsFTPd服务详解——本地用户登录实战
33 2
|
1月前
|
运维 监控 Linux
Linux Rsync服务详解(二)——Rsync服务实战
Linux Rsync服务详解(二)——Rsync服务实战
18 1
|
14天前
|
存储 算法 Linux
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
38 6
|
22天前
|
运维 Linux Shell
linux运维常用命令
linux运维常用命令
|
29天前
|
运维 监控 Linux
linux脚本自动化运维任务
Linux自动化运维通过脚本提升效率,涵盖服务管理(启停服务、异常恢复)、系统监控(资源警报)、日志管理(清理分析)、备份恢复、补丁更新、自动化部署(如Ansible)、网络管理、定时任务(cron)和故障排查。结合shell、Python及工具,形成高效运维体系。
23 3
|
1月前
|
存储 缓存 Linux
Linux 系统调用深思:从原理到实战
Linux 系统调用深思:从原理到实战
39 1
|
1月前
|
监控 网络协议 Linux
Linux 命令大全 & CentOS常用运维命令
Linux 命令大全 & CentOS常用运维命令
156 0
|
1月前
|
运维 监控 Linux
Linux本地部署1Panel现代化运维管理面板并实现公网访问
Linux本地部署1Panel现代化运维管理面板并实现公网访问
79 1