第十一周作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十一周作业相关的知识,希望对你有一定的参考价值。

1、源码编译安装LNMP架构环境;

2、编写一个脚本完成以下功能:

(1)、一键搭建LNMP源码编译环境;

(2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。

#!/bin/bash
read -p ‘Please enter the installation path:‘ dataPath
read -p ‘Please enter your package path:‘ packagePath
installPath=$packagePath/lamp-server
serverCount=(apr apr-util httpd mysql php xcache)
log=$installPath/install.log
mysqlData=/mydata/data
mkdir $installPath &> /dev/null

serviceUnpack(){
    tar -xjf $1 -C  $installPath &>> $log   && echo "Unpack the $1 success"  ||  echo "Unpack the $1 failed" 
}


serviceInstall(){
    if [ $1 == ‘apr‘  -a ! -e $dataPath/$1 ]
    then
        echo "Began to extract the $1 installation" 
        cd $installPath/$1*
        sed -i "s/\(\<RM=..RM\)./\1 -f‘/g" configure 
        ./configure --prefix=$dataPath/$1 &>> $log
        make &>> $log && make install &>> $log  && echo "$1 installed successfully"  ||  echo "$1 installed failed" 
    elif [ $1 == ‘apr-util‘  -a ! -e $dataPath/$1 ]
    then
         echo "Began to extract the $1 installation" 
         cd $installPath/$1*
   	 ./configure --prefix=$dataPath/$1 --with-apr=$dataPath/apr  &>> $log
   	 make &>> $log && make install  &>> $log  && echo "$1 installed successfully"  ||  echo "$1 installed failed" 
    elif [ $1 == ‘httpd‘  -a ! -e $dataPath/$1 ]
    then
        echo "Began to extract the $1 installation" 
        cd $installPath/$1*
        ./configure --prefix=$dataPath/$1 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=$dataPath/apr --with-apr-util=$dataPath/apr-util --enable-modules=most --enable-mpms-shared=all  &>> $log
        make &>> $log && make install  &>> $log  && echo "$1 installed successfully"  ||  echo "$1 installed failed" 
    elif [ $1 == ‘mysql‘  -a ! -e $dataPath/$1 ]
    then
        echo "Began to extract the $1 installation" 
        cd $installPath/$1*
        cmake . -DCMAKE_INSTALL_PREFIX=$dataPath/mysql -DMYSQL_DATADIR=/mydata/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==$dataPath/mysql/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci &>> $log
        make &>> $log && make install  &>> $log  && echo "$1 installed successfully"  ||  echo "$1 installed failed" 
    elif [ $1 == ‘php‘  -a ! -e $dataPath/$1 ]
    then
        echo "Began to extract the $1 installation" 
        cd $installPath/$1*
        ./configure --prefix=$dataPath/php --with-mysql=$dataPath/mysql --with-openssl --with-mysqli=$dataPath/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=$dataPath/httpd/bin/apxs --with-mcrypt  --with-bz2  --enable-maintainer-zts &>> $log
        make &>> $log && make install &>> $log  && echo "$1 installed successfully"   ||  echo "$1 installed failed" 
    elif [ $1 == ‘xcache‘  -a ! -e $dataPath/php/lib/php/extensions/no-debug-zts-20100525/xcache.so ]
    then
        echo "Began to extract the $1 installation" 
        cd $installPath/$1*
        $dataPath/php/bin/phpize &>> $log
        ./configure --enable-xcache --with-php-config=$dataPath/php/bin/php-config &>> $log
        make &>> $log  && make install  &>> $log  && echo "$1 installed successfully"  ||  echo "$1 installed failed" 
    fi
}

serviceDrop(){
     cd $dataPath
     rm -rf $1  && echo "Delete the $1 service success"   || echo "Delete the $1 service failed" 
}

serviceConfig(){
    if [ $1 == ‘httpd‘ ]
    then
        cd $dataPath/httpd
  	sed -i ‘s/DirectoryIndex.*index.html/DirectoryIndex index.php index.html/g‘ conf/httpd.conf && sed -i ‘381,382cAddType application/x-httpd-php \.php\nAddType application/x-httpd-php-source  .phps‘ conf/httpd.conf && echo "$1 configuration success" || echo "$1 configuration failed"
    elif [ $1 == ‘xcache‘ ]
    then
        cd $installPath/php*
        cp -a  php.ini-production $dataPath/php/lib/php.ini
        cd $installPath/xcache*
        cp -a  xcache.ini  $dataPath/php/lib
        cd  $dataPath/php
        sed -i ‘380aextension_dir =  /usr/local/php/lib/php/extensions/no-debug-zts-20100525\nextension = xcache.so‘ lib/php.ini && echo "$1 configuration success" || echo "$1 configuration failed"
        echo ‘<?php phpinfo(); ?>‘ > $dataPath/httpd/htdocs/index.php
    elif [ $1 == ‘mysql‘ ]
    then
        mkdir -p /mydata/data &>> $log
        groupadd -r mysql &>> $log
        useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql  &>> $log
        chown -R mysql:mysql /mydata/data &>> $log
        chown -R mysql:mysql /usr/local/mysql   &>> $log
        cd  $dataPath/mysql
        ./scripts/mysql_install_db --basedir=$dataPath/mysql/ --datadir=$mysqlData --user=mysql &>> $log   && echo "$1 configuration success" || echo "$1 configuration failed"
 	ln -sv $dataPath/mysql/include  /usr/include/mysql
 	echo "$dataPath/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
	ldconfig
    fi
}

while true
do
read -p "Please enter the | config | unpack | install | drop | quit | to complete the configuration: " met
case $met in
unpack)
    echo `date ‘+%F %T‘` 
    echo ‘Began to unzip the installation services‘ 
    for i in  $packagePath/*
    do
        serviceUnpack   $i
    done
    echo -e ‘\n\n‘ 
;;
install)
    yum groupinstall  ‘Development tools‘ ‘Desktop Platform Development‘ -y &>> $log
    yum install  pcre-devel openssl-devel cmake ncurses-devel bzip2-devel libmcrypt-devel libxml2-devel libmcrypt-devel  -y &>> $log
    echo `date ‘+%F %T‘` 
    for i in  ${serverCount[@]}
    do
        serviceInstall   $i
    done
    echo -e ‘\n\n‘ 
;;
drop)
    $dataPath/mysql/support-files/mysql.server stop &>> $log  && echo "mysql stop successfully" || echo "mysql stop failed"
    $dataPath/httpd/bin/apachectl stop &>> $log  && echo "mysql stop successfully" || echo "mysql stop failed"
    groupdel  mysql  &>> $log
    userdel -r mysql &>> $log
    echo `date ‘+%F %T‘` 
    for i in  ${serverCount[@]}
    do
        serviceDrop   $i
    done
    echo -e ‘\n\n‘ 
    rm -f  $log
;;
config)
    echo `date ‘+%F %T‘` 
    for i in  ${serverCount[@]}
    do
        serviceConfig   $i
    done
    echo -e ‘\n\n‘ 
    $dataPath/mysql/support-files/mysql.server restart &>>  $log   && echo "mysql start successfully" || echo "mysql start failed"
    $dataPath/httpd/bin/apachectl restart &>> $log  && echo "mysql start successfully" || echo "mysql start failed"
;;
quit)
    exit 0
;;
esac
done


测试
[[email protected] ~]# ./test.sh 
Please enter the installation path:/usr/local
Please enter your package path:/opt
Please enter the | config | unpack | install | drop | quit | to complete the configuration: unpack
2017-02-28 10:45:10
Began to unzip the installation services
Unpack the /opt/apr-1.5.0.tar.bz2 success
Unpack the /opt/apr-util-1.5.3.tar.bz2 success
Unpack the /opt/httpd-2.4.9.tar.bz2 success
Unpack the /opt/lamp-server failed
Unpack the /opt/mysql-5.5.33.tar.bz2 success
Unpack the /opt/php-5.4.26.tar.bz2 success
Unpack the /opt/xcache-3.1.0.tar.bz2 success


Please enter the | config | unpack | install | drop | quit | to complete the configuration: install
2017-02-28 10:47:30
Began to extract the apr installation
apr installed successfully
Began to extract the apr-util installation
apr-util installed successfully
Began to extract the httpd installation
httpd installed successfully
Began to extract the mysql installation
mysql installed successfully
Began to extract the php installation
php installed successfully
Began to extract the xcache installation
xcache installed successfully


Please enter the | config | unpack | install | drop | quit | to complete the configuration: config
2017-02-28 11:00:44
httpd configuration success
mysql configuration success
xcache configuration success

mysql start successfully
httpd start successfully


[[email protected] ~]# curl -I 172.20.100.101
HTTP/1.1 200 OK
Date: Tue, 28 Feb 2017 03:05:11 GMT
Server: Apache/2.4.9 (Unix) PHP/5.4.26
X-Powered-By: PHP/5.4.26
Content-Type: text/html



Please enter the | config | unpack | install | drop | quit | to complete the configuration: drop
mysql stop successfully
httpd stop successfully
2017-02-28 11:14:52
Delete the apr service success
Delete the apr-util service success
Delete the httpd service success
Delete the mysql service success
Delete the php service success
Delete the xcache service success

3、结合图形描述LVS的工作原理;

4、阐述varnish的功能及其应用场景,并通过实际的应用案例来描述配置、测试、调试过程。

5、搭建一套LVS-DR模型的高性能集群,并用Keepalived实现nginx与lvs的高可用集群,同时实现以下功能:

(1)、wordpress程序通过nfs共享给各个realserver;

(2)、后端realserver中的nginx和php分离

代码语言



以上是关于第十一周作业的主要内容,如果未能解决你的问题,请参考以下文章

第十一周学习进度(补)

第十一周学习进度条

四巨头第十一周作业 翻译

第十一周软件工程作业-每周例行报告

数据库第十一周作业

第十一周学习作业