linux运维实战练习-2016年3月4日-3月19日课程作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux运维实战练习-2016年3月4日-3月19日课程作业相关的知识,希望对你有一定的参考价值。
I.作业(练习)内容:
1、搭建LAMP环境,并实践基于DNS做基于域名的虚拟主机。
搭建LAMP环境步骤:
1. 下载相应的软件包至/usr/local/src目前下
[[email protected] ~]# 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
[[email protected] src]# tar zxvf libxml2-2.9.0.tar.gz 解压文件 [[email protected] src]# cd libxml2-2.9.0/ 切换目录 [[email protected] libxml2-2.9.0]# ./configure --prefix=/usr/local /libxml2 配置,指定安装到/usr/local /libxml2 目录下 [[email protected] libxml2-2.9.0]# make 进行编译 [[email protected] libxml2-2.9.0]# make install 开始安装libxm12库文件 安装成功在“/usr/local/libxm12”目录下有以下四个文件 [[email protected] ~]# ls /usr/local/libxm12 bin include lib share
安装gcc
[[email protected]]# yum install gcc gcc-c++ gcc-g77
安装libmcrypt
[[email protected] src]# tar zxvf libmcrypt-2.5.8.tar.gz 解压 [[email protected] src]# cd libmcrypt-2.5.8/ 切换目录 [[email protected] libmcrypt-2.5.8]# ./configure with-mcrypt-dir=/usr/local/libmcrypt 安装文件 [[email protected] libmcrypt-2.5.8]# yum install gcc gcc-c++ gcc-g77 安装gcc [[email protected] libmcrypt-2.5.8]# cd libltdl/ [[email protected] libltdl]# ./configure --enable-ltdl-install [[email protected] libltdl]# make [[email protected] 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
[[email protected] src]# tar zxvf zlib-1.2.7.tar.gz [[email protected] src]# cd zlib-1.2.7/ [[email protected] zlib-1.2.7]# ./configure -with- zlib-dir=/usr/local/libmcrypt [[email protected] zlib-1.2.7]# make [[email protected] zlib-1.2.7]# make install [[email protected] zlib-1.2.7]# ls /usr/local/zlib/ include lib share
安装libpng
[[email protected] src]# tar libpng-1.5.14.tar.gz ^C [[email protected] src]# cd libpng-1.5.14/ [[email protected] libpng-1.5.14]# ./configure --prefix=/usr/local/libpng^C [[email protected] libpng-1.5.14]# ls /usr/local/libpng/ bin include lib share
安装jpeg8
[[email protected] ~]# mkdir /usr/local/jpeg8 //建立jpeg8软件安装目录 [[email protected] ~]# mkdir /usr/local/jpeg8/bin //建立存放命令的目录 [[email protected] ~]# mkdir /usr/local/jpeg8/lib //创建jpeg8库文件所在目录 [[email protected] ~]# mkdir /usr/local/jpeg8/include //建立存放头文件目录 [[email protected] ~]# mkdir /usr/local/jpeg8/man/man1 //建立存放手册的目录 [[email protected] ~]# tar zxvf /usr/local/src/jpeg //解压 jpeg-8b/ jpegsrc.v8b.tar.gz [[email protected] ~]# tar zxvf /usr/local/src/jpeg jpeg-8b/ jpegsrc.v8b.tar.gz [[email protected] ~]# tar zxvf /usr/local/src/jpegsrc.v8b.tar.gz [[email protected] ~]# cd /usr/local/src/jpeg-8b/ [[email protected] jpeg-8b]# ./configgure --prefix=/usr/local/jpeg8/ --enable-share --enable-static
安装freetype
[[email protected] src]# tar zxvf freetype-2.4.10.tar.gz //解压包到freetype-2.4.10目录 [[email protected] src]# cd freetype-2.4.10/ //进入目录freetype-2.4.10中 [[email protected] freetype-2.4.10]# ./configure --prefix=/usr/local/freetype //编译 [[email protected] freetype-2.4.10]# make //对软件源代码文件进行编译 [[email protected] freetype-2.4.10]# make install //开始安装freetype库文件 [[email protected] freetype-2.4.10]# ls /usr/local/freetype/ //软件安装成功,在该目录下有以下4个文件 bin include lib share
安装atuoconf
[[email protected] src]# tar zxvf autoconf-2.69.tar.gz [[email protected] src]# cd autoconf-2.69/ [[email protected] 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/ [[email protected] autoconf-2.69]# make [[email protected] autoconf-2.69]# make install [[email protected] autoconf-2.69]# ls /usr/local/gd bin include lib
安装apr
[[email protected] src]# tar apr-1.5.2.tar.gz [[email protected] src]# cd apr-1.5.2/ [[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr-httpd/ && make && make install
安装apr-util
[[email protected] apr-1.5.2]# cd /usr/local/src/ [[email protected] src]# tar apr-util-1.5.1.tar.gz [[email protected] src]# cd apr-util-1.5.1/ [[email protected] apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/ && make && make install
安装pcre
[[email protected] apr-util-1.5.1]# cd /usr/local/src/ [[email protected] src]# unzip -o pcre-8.32.zip [[email protected] src]# cd pcre-8.32/ [[email protected] pcre-8.32]# .#./configure --prefix=/usr/local/pcre && make && make
安装Httpd
[[email protected] src]# tar xzvf httpd-2.4.3.tar.gz [[email protected] src]# cd httpd-2.4.3/ [[email protected] 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 [[email protected] ~]# make [[email protected] ~]# [[email protected] ~]# make install [[email protected] ~]# ls /usr/local/apache243/ 安装成功检测该文件夹下是否有以下文件 bin build cgi-bin error htdocs icons include lib logs man manual modules
修改httpd.conf配置文件,添加如下一行
重启Apache服务器,确认80端口已经处理监听状态
[[email protected] ~]# /usr/local/apache243/bin/apachectl start httpd (pid 130058) already running [[email protected] ~]# netstat -tnl | grep 80 tcp6 0 0 :::80 :::* LISTEN
确认Apache服务器可以使用
将Apache服务器设置开机启动
[[email protected] ~]# echo "/usr/local/apache243/bin/apachectl start" >> /etc/rc.d/rc.local[[email protected] ~]# 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数据库
[[email protected] mysql-5.0.18]# tar xvzf mysql-5.0.18 [[email protected] mysql-5.0.18]# cd mysql-5.0.18/ [[email protected] 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!
添加用户名和用户组
[[email protected] mysql-5.0.18]# groupadd mysql [[email protected] mysql-5.0.18]# useradd -g mysql mysql
创建mysql数据库服务器的配置文件,可以使用源码包support-files目录中的my-medium.cnf文件作为模板,将其复制到/etc/目录下,命名为my.cnf文件
[[email protected] mysql-5.0.18]# cp support-files/my-medium.cnf /etc/my.cnf
进入到安装目录/usr/local/mysql下,执行bin目录下的mysql_install_db脚本,用来初始化MySQL数据库的授权表,其中存储了服务器访问允许
[[email protected] mysql-5.0.18]# cd /usr/local/mysql [[email protected] mysql]# bin/mysql_install_db --user=mysql
将程序二进制的所有权改为root用户,数据目录的所有权改为运行mysqld程序的mysql用户
[[email protected] mysql]# chown -R root . //将文件的所有属性改为root用户 [[email protected] mysql]# whown -R mysql var //将数据目录的所有属性改为mysql用户 [[email protected] mysql]# chgrp -R mysql . //将组属性改为mysql组
确认mysql目录下生成以下10个文件
[[email protected] mysql]# pwd /usr/local/mysql [[email protected] mysql]# ls bin include info lib libexec man mysql-test share sql-bench var
启动Mysql
[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql & [1] 36598
确认Mysql对应 的端口号3306正常打开
[[email protected]host mysql]# netstat -tnl | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
检测Mysql服务器是否正常工作
查看Mysql的版本
[[email protected] 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
设置密码:
[[email protected] 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,命令行如下
[[email protected] mysql]# cd /usr/local/src/mysql-5.0.18 [[email protected] mysql-5.0.18]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql-5.0.18]# chown root.root /etc/rc.d/init.d/mysqld //修改权限 [[email protected] mysql-5.0.18]# chmod 755 /etc/rc.d/init.d/mysqld [[email protected] mysql-5.0.18]# chkconfig --add mysqld //把mysqld添加到chkconfig中 [[email protected] mysql-5.0.18]# chkconfig --level 3 mysqld on //加入运行级别三开机启动 [[email protected] mysql-5.0.18]# chkconfig --level 5 mysqld on //加入运行级别五开机启动 [[email protected] 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
[[email protected] 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
[[email protected] 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‘. [[email protected] 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测试页
[[email protected] php-5.4.11]# cat /usr/local/apache243/htdocs/text.php <?php phpinfo(); ?>
重启Apache服务器
[[email protected] php-5.4.11]# /usr/local/apache243/bin/apachectl stop [[email protected] php-5.4.11]# /usr/local/apache243/bin/apachectl start
成功访问刚刚创建的测试页
phpMyAdmin安装
解压安装文件
[[email protected] src]# tar xzvf phpMyAdmin-3.5.6-all-languages.tar.gz
将解压的目录下的所有文件复制/usr/local/apache243/htdocs/phpmyadmin下
[[email protected] 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身份验证模式
[[email protected] src]# cd /usr/local/apache243/htdocs/phpmyadmin/ [[email protected] phpmyadmin]# cp config.sample.inc.php config.inc.php
修改如下
成功访问PhpMyAdmin下在的index.php
2、基于1题目中的环境,重新搭建一个同样的环境,要求:
a)实现web服务文件更新的自动同步到另一台机器上
b)数据库实现主从复制
c)通过shell脚本实现网站源代码备份和mysql备份,备份策略包括全量备份、增量备份、差异备份
3、使用压测工具(ab/webbench等)实现搭建的页面压测,要求通过调整apache的工作模式来对比最后性能。
4、基于3步骤过程中的压测,通过脚本实现iptables自动判断来源ip,并作拒绝制定ip访问,要求访问次数1秒超过10次的拒绝掉。
5、基于2中的环境,通过lvs实现负载均衡,要求使用DR模式,并能把其中的原理部分通过自己的理解汇总出来。
本文出自 “WE BECOME WHATWEPRACTICE” 博客,请务必保留此出处http://nearlv.blog.51cto.com/2432295/1752970
以上是关于linux运维实战练习-2016年3月4日-3月19日课程作业的主要内容,如果未能解决你的问题,请参考以下文章
linux运维实战练习-2016年3月4日-3月19日课程作业
linux运维实战练习-2016年1月19日-2月3日课程作业
linux运维实战练习-2016年1月19日-2月3日课程作业
linux运维实战练习-2016年1月19日-2月3日课程作业