linux運維實戰練習-2016年3月4日-3月19日課程作業

I.作業(練習)內容:

1、搭建LAMP環境,並實踐基於DNS做基於域名的虛擬主機。

搭建LAMP環境步驟:

1. 下載相應的軟件包至/usr/local/src目前下

[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

[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

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

安裝libmcrypt

[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

[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

[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

[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

[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

[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

[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

[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

[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

[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配置文件,添加如下一行

p_w_picpath

重啓Apache服務器,確認80端口已經處理監聽狀態

[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服務器可以使用

p_w_picpath

將Apache服務器設置開機啓動

[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數據庫

[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!

添加用戶名和用戶組

[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文件

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

進入到安裝目錄/usr/local/mysql下,執行bin目錄下的mysql_install_db腳本,用來初始化MySQL數據庫的授權表,其中存儲了服務器訪問允許

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

將程序二進制的所有權改爲root用戶,數據目錄的所有權改爲運行mysqld程序的mysql用戶

[root@localhost mysql]# chown -R root .  //將文件的所有屬性改爲root用戶    
[root@localhost mysql]# whown -R mysql var  //將數據目錄的所有屬性改爲mysql用戶     
[root@localhost mysql]# chgrp -R mysql .   //將組屬性改爲mysql組

確認mysql目錄下生成以下10個文件

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

啓動Mysql

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

確認Mysql對應 的端口號3306正常打開

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

檢測Mysql服務器是否正常工作

查看Mysql的版本

[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

設置密碼:

[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,命令行如下

[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

[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

[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測試頁

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

重啓Apache服務器

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

成功訪問剛剛創建的測試頁

 p_w_picpath

phpMyAdmin安裝

解壓安裝文件

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

將解壓的目錄下的所有文件複製/usr/local/apache243/htdocs/phpmyadmin下

[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身份驗證模式

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

修改如下

phpmyadmin

成功訪問PhpMyAdmin下在的index.php

p_w_picpath

2、基於1題目中的環境,重新搭建一個同樣的環境,要求:

   a)實現web服務文件更新的自動同步到另一臺機器上

   b)數據庫實現主從複製

   c)通過shell腳本實現網站源代碼備份和mysql備份,備份策略包括全量備份、增量備份、差異備份

  3、使用壓測工具(ab/webbench等)實現搭建的頁面壓測,要求通過調整apache的工作模式來對比最後性能。

  4、基於3步驟過程中的壓測,通過腳本實現iptables自動判斷來源ip,並作拒絕制定ip訪問,要求訪問次數1秒超過10次的拒絕掉。

  5、基於2中的環境,通過lvs實現負載均衡,要求使用DR模式,並能把其中的原理部分通過自己的理解彙總出來。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章