Linux第十二周

1、请描述一次完整的http请求处理过程;

1、建立TCP连接

2、Web浏览器向Web服务器发送请求

3、Web浏览器发送请求头信息

建立连接后,客户机发送一个请求给服务器,请求方式的格式为:统一资源标识符(URL)、协议版本号,后边是MIME信息包括请求修饰符、客户机信息和可能的内容

4、Web服务器应答

服务器接到请求后,给予相应的响应信息,其格式为一个状态行,包括信息的协议版本号、一个成功或错误的代码,后边是MIME信息包括服务器信息、实体信息和可能的内容。

5、Web服务器发送应答头信息

6、Web服务器向浏览器发送数据

7、Web服务器关闭TCP连接

2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。

httpd所支持的事务处理模型主要有:

prefork

worker

event

他们分别使用于以下场景:

prefork:多进程模型,每个进程负责响应一个请求。prefork模型在工作时,由一个主进程负责生成n个子进程,即工作进程。每个工作进程响应一个用户请求,即使当前没有用户请求,它亦会预先生成多个空闲进程,随时等待请求连接,这样的好处是,服务器不用等到请求到达时,才去临时建立进程,缩短了进程创建的时间。提高连接效率。但受限于linux的特性,工作进程数上限为1024个,如果超出该数量,服务器性能会急剧降低。因而,prefork模型的最大并发连接数量为1024.由于每个工作进程相对独立,就算崩溃了,也不会对其它进程有明显影响。所以,该模型的特点是稳定可靠,适合于并发量适中而又追求稳定的用户使用。

worker:多线程模型,每个线程响应一个请求。worker模型在工作时,主进程负责生成多个子进程,同时每个子进程负责生成多个线程,每个线程响应一个用户请求。同时,worker模型也会预先创建一些空闲线程来等待用户连接。并发连接数,如果生成进程数为m,线程数为n,则并发数可达到m*n个。但由于在linux中,原生不支持线程,且进程本身就足够轻量化,与线程的区别不是很大,因而,worker模型在linux环境中的实际性能表现与prefork相差无几。

event:事件驱动模型,每个线程响应n个用户请求。event模型工作时,由主进程生成m个子进程,每个单独的子进程可响应n个用户请求。因而,event的并发数量可达到m*n个,同时,因为event的子进程为一对多,节省大量CPU进程切换上下文的时间,也没有了linux系统的1024个进程限制,所以,event模型是三种模型中效率最高的一种。可以突破10K的限制(即并发数1W),对海量的系统特别适用。

3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。

以CentOS7.2,http2.4.16,mysql-5.6.26.tar.gz,mysql-5.6.26.tar.gz为例,源码编译安装LAMP,详细步骤如下:

安装开发环境

[[email protected] ~]# yum groupinstall "Development Tools" "Server Platform Development" -y

1、编译安装Apache

解决依赖关系

(1)编译安装apr

[[email protected] ~]# tar xf apr-1.5.2.tar.gz 

[[email protected] ~]# cd apr-1.5.2/

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

[email protected] ~]# make && make install && cd

(2)编译安装apr-util

[[email protected] ~]# tar xf apr-util-1.5.4.tar.bz2 

[[email protected] ~]# cd apr-util-1.5.4/

[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 

[[email protected] apr-util-1.5.4]# make && make install && cd

(3)httpd-2.4.16依赖于pcre-devel软件包

[[email protected] ~]# yum -y install pcre-devel  openssl-devel

编译安装httpd-2.4.16

[[email protected] ~]# tar xf httpd-2.4.16.tar.bz2 

[[email protected] ~]# cd httpd-2.4.16/

[[email protected] httpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[[email protected] ~]# make -j 4 && make install &&cd

[[email protected] ~]# vim /etc/profile.d/httpd.sh

添加

export PATH=/usr/local/apache/bin:$PATH

[[email protected] ~]# . /etc/profile.d/httpd.sh 

#编辑apache服务脚本

[[email protected] ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[[email protected] ~]# vim /etc/init.d/httpd

添加

# chkconfig: 2345 85 15

# description: httpd startup for the Apache Http Server

[[email protected] ~]# service httpd start

[[email protected] ~]# chkconfig --add httpd

[[email protected] ~]# chkconfig httpd on

[[email protected] ~]# ss -tnl | grep :80

LISTEN     0      128         :::80                      :::* 

2、编译安装MySQL

#添加mysql用户

[[email protected] ~]# groupadd -g 316 mysql

[[email protected] ~]# useradd -g mysql -u 316 -r -s /sbin/nologin mysql

#安装mysql依赖的软件包

[[email protected] ~]# yum -y install cmake ncurses-devel

#编译安装mysql 

[[email protected] ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/

[[email protected] ~]# cd /usr/local/mysql-5.6.26/

[[email protected] mysql-5.6.26]# cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1  -DMYSQL_DATADIR=/usr/local/mysql/data  -DMYSQL-USER=mysql

[[email protected] mysql-5.6.26]# make -j 4 && make install

[[email protected] mysql-5.6.26]# cd && chown -R mysql:mysql /usr/local/mysql/

[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[[email protected] ~]# sed  -i ‘s#^basedir=#basedir=/usr/local/mysql#‘ /etc/init.d/mysqld

[[email protected] ~]# sed  -i ‘s#^datadir=#datadir=/usr/local/mysql/data#‘ /etc/init.d/mysqld

[[email protected] ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

[[email protected] ~]# sed -i ‘/^\[mysqld\]/adatadir = /usr/local/mysql/data‘ /etc/my.cnf

[[email protected] ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf

[[email protected] ~]# chkconfig mysqld on

[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

[[email protected] ~]# ln -s /usr/local/mysql/bin/* /bin/

[[email protected] ~]# service mysqld start

3、安装PHP

#安装PHP依赖的软件包

[[email protected] ~]# yum -y install libxml2-devel

#编译安装PHP

[[email protected] ~]# tar xf php-5.6.13.tar.bz2 

[[email protected] ~]# cd php-5.6.13/

[[email protected] php-5.6.13]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php

[[email protected] php-5.6.13]# make ; make install 

[[email protected] php-5.6.13]# cp php.ini-production /usr/local/php/php.ini;cd

[[email protected] ~]# sed -i ‘s/index.html/index.html index.php/‘ /etc/httpd/httpd.conf

[[email protected] ~]#  sed -i ‘377a    AddType application/x-httpd-php .php‘ /etc/httpd/httpd.conf 

[[email protected] ~]# sed -i ‘378a    AddType application/x-httpd-php-source .phps‘ /etc/httpd/httpd.conf 

[[email protected] ~]# service httpd  restart

[[email protected] ~]# echo ‘<?php phpinfo();  ?>‘ >/usr/local/apache/htdocs/index.php

4、wordpress程序的安装

#下载wordpress程序

[[email protected] ~]# wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz

#解压wordpress到/usr/local/apache/htdocs/

[[email protected] ~]# tar xf wordpress-4.5.3-zh_CN.tar.gz -C /usr/local/apache/htdocs/

[[email protected] ~]# cd /usr/local/apache/htdocs/

[[email protected] htdocs]# chown root:root wordpress/ -R

[[email protected] htdocs]# cd wordpress/

[[email protected] wordpress]# cp wp-config-sample.php wp-config.php

(1)修改数据库名

修改 

define(‘DB_NAME‘, ‘database_name_here‘);

define(‘DB_NAME‘, ‘wordpress‘);

(2) 修改MySQL数据库登录用户名

修改 

define(‘DB_USER‘, ‘username_here‘);

define(‘DB_USER‘, ‘root‘);

(3)修改MySQL数据库登录密码

修改

define(‘DB_PASSWORD‘, ‘password_here‘);

define(‘DB_PASSWORD‘, ‘magedu‘);

#登录mysql创建wordpress数据库,并设置root用户登录密码

[[email protected] ~]# mysql

mysql> create database wordpress;

mysql> use mysql;

mysql> update user set password=PASSWORD(‘magedu‘) where user=‘root‘;

mysql> flush privileges;

mysql> \q

在浏览器中输入

http://192.168.1.72/wordpress/

设置注册用户的用户名和密码,完成安装wordPress

4、建立httpd服务器(基于编译的方式进行),要求:

     提供两个基于名称的虚拟主机:

    (a)www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;

    (b)www2.stuX.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;

    (c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;

    (d)通过www1.stuX.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status);

安装开发环境

[[email protected] ~]# yum groupinstall "Development Tools" "Server Platform Development" -y

1、编译安装Apache

解决依赖关系

(1)编译安装apr

[[email protected] ~]# tar xf apr-1.5.2.tar.gz 

[[email protected] ~]# cd apr-1.5.2/

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

[email protected] ~]# make && make install && cd

(2)编译安装apr-util

[[email protected] ~]# tar xf apr-util-1.5.4.tar.bz2 

[[email protected] ~]# cd apr-util-1.5.4/

[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 

[[email protected] apr-util-1.5.4]# make && make install && cd

(3)httpd-2.4.16依赖于pcre-devel软件包

[[email protected] ~]# yum -y install pcre-devel  openssl-devel

编译安装httpd-2.4.16

[[email protected] ~]# tar xf httpd-2.4.16.tar.bz2 

[[email protected] ~]# cd httpd-2.4.16/

[[email protected] httpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[[email protected] ~]# make -j 4 && make install &&cd

[[email protected] ~]# vim /etc/profile.d/httpd.sh

添加

export PATH=/usr/local/apache/bin:$PATH

[[email protected] ~]# . /etc/profile.d/httpd.sh 

#编辑apache服务脚本

[[email protected] ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[[email protected] ~]# vim /etc/init.d/httpd

添加

# chkconfig: 2345 85 15

# description: httpd startup for the Apache Http Server

[[email protected] ~]# service httpd start

[[email protected] ~]# chkconfig --add httpd

[[email protected] ~]# chkconfig httpd on

[[email protected] ~]# ss -tnl | grep :80

LISTEN     0      128         :::80                      :::* 

2、编辑apache配置文件

[[email protected] ~]# cd /etc/httpd/

[[email protected] httpd]# cp httpd.conf{,.bak}

[[email protected] httpd]# vim httpd.conf

(1)启用虚拟主机

修改

#Include /etc/httpd/extra/httpd-vhosts.conf

Include /etc/httpd/extra/httpd-vhosts.conf

(2)添加两个虚拟主机目录的访问权限

在末尾添加以下内容:

<Directory "/web/vhosts/www1">

options none

allowoverride none

Require all granted

</Directory>

<Directory "/web/vhosts/www2">

options none

allowoverride none

Require all granted

</Directory>

(3)创建虚拟主机目录

[[email protected] ~]# mkdir -p /web/vhosts/www{1,2}

[[email protected] ~]# mkdir /var/log/httpd

[[email protected] ~]# touch /var/log/httpd/www{1,2}.{err,access}

(4)编辑虚拟主机文件

[[email protected] ~]# vim /etc/httpd/extra/httpd-vhosts.conf

在末尾添加以下内容

<VirtualHost *:80>

    DocumentRoot "/web/vhosts/www1"

    ServerName www1.stuX.com

    ErrorLog "/var/log/httpd/www1.err"

    CustomLog "/var/log/httpd/www1.access" common

</VirtualHost>

<VirtualHost *:80>

    DocumentRoot "/web/vhosts/www2"

    ServerName www2.stuX.com

    ErrorLog "/var/log/httpd/www2.err"

    CustomLog "/var/log/httpd/www2.access" common

</VirtualHost>

[[email protected]host ~]# service httpd restart

(5)创建虚拟主机主页文件

[[email protected] ~]# echo "<h1>www1.stuX.com</h1>" > /web/vhosts/www1/index.html

[[email protected] ~]# echo "<h1>www2.stuX.com</h1>" > /web/vhosts/www2/index.html 

(6)客户端测试,需要在DNS服务器或hosts中配置好虚拟主机

[[email protected] ~]# curl www1.stuX.com

<h1>www1.stuX.com</h1>

[[email protected] ~]# curl www2.stuX.com 

<h1>www2.stuX.com</h1>

3、构建Server-Status设置

在www1.stuX.com里,增加server-status的设置

[[email protected] httpd]# vim /etc/httpd/extra/httpd-vhosts.conf 

修改www1.stuX.com主机的配置文件为

<VirtualHost *:80>

DocumentRoot "/web/vhosts/www1"

ServerName www1.stuX.com

ErrorLog "/var/log/httpd/www1.err"

CustomLog "/var/log/httpd/www1.access" common

<Location /server-status>

SetHandler server-status

AuthType Basic

AuthName "Server-Status"

AuthUserFile "/etc/httpd/extra/.htpasswd"

Require valid-user

</location>

</VirtualHost>

#生成密码文件

[[email protected] ~]# htpasswd -cm /etc/httpd/extra/.htpasswd status #密码也设为status

[[email protected] httpd]# service httpd restart

5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;

   (1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu);

   (2)设置部门为Ops,主机名为www2.stuX.com,邮件为[email protected];

#CA与Web在同一主机上

1、创建私有CA

(1)创建所需要的文件

[[email protected] ~]# cd /etc/pki/CA

[[email protected] CA]# touch index.txt

[[email protected] CA]# echo 01 > serial

(2)CA自签证书

[[email protected] CA]# (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

Generating RSA private key, 2048 bit long modulus

...............................................+++

...........................+++

e is 65537 (0x10001)

[[email protected] CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pemYou are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:HA

Locality Name (eg, city) [Default City]:ZZ

Organization Name (eg, company) [Default Company Ltd]:MageEdu 

Organizational Unit Name (eg, section) []:OPS

Common Name (eg, your name or your server‘s hostname) []:ca.stuX.com

Email Address []:[email protected]

(3)发证

[[email protected] CA]# cd /etc/httpd/

[[email protected] httpd]# mkdir ssl

[[email protected] httpd]# (umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)Generating RSA private key, 2048 bit long modulus

.......................................+++

.............................................................................................................................................................................+++

e is 65537 (0x10001)

[[email protected] httpd]# openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out /etc/httpd/ssl/httpd.csrYou are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:HA

Locality Name (eg, city) [Default City]:ZZ

Organization Name (eg, company) [Default Company Ltd]:MageEdu

Organizational Unit Name (eg, section) []:Ops

Common Name (eg, your name or your server‘s hostname) []:www2.stuX.com

Email Address []:[email protected]

Please enter the following ‘extra‘ attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

 

  [[email protected] httpd]# openssl ca -in /etc/httpd/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365Using configuration from /etc/pki/tls/openssl.cnf

Check that the request matches the signature

Signature ok

Certificate Details:

        Serial Number: 1 (0x1)

        Validity

            Not Before: Oct 19 09:09:37 2016 GMT

            Not After : Oct 19 09:09:37 2017 GMT

        Subject:

            countryName               = CN

            stateOrProvinceName       = HA

            organizationName          = MageEdu

            organizationalUnitName    = Ops

            commonName                = www2.stuX.com

            emailAddress              = [email protected]

        X509v3 extensions:

            X509v3 Basic Constraints: 

                CA:FALSE

            Netscape Comment: 

                OpenSSL Generated Certificate

            X509v3 Subject Key Identifier: 

                CE:2A:51:9E:2C:5E:05:B4:79:AB:14:C8:32:E7:68:42:2B:E8:CD:4E

            X509v3 Authority Key Identifier: 

                keyid:88:96:ED:8A:43:0F:8B:2A:DD:D4:E5:B1:02:7A:6C:9F:11:45:FF:E9

Certificate is to be certified until Oct 19 09:09:37 2017 GMT (365 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[[email protected] httpd]# cp /etc/pki/CA/certs/httpd.crt /etc/httpd/ssl/

[[email protected] httpd]# ls /etc/httpd/ssl/

httpd.crt  httpd.csr  httpd.key

[[email protected] ~]# yum -y install mod_ssl

[[email protected] ~]# vim /etc/httpd/conf.d/ssl.conf

在末尾添加以下内容

<VirtualHost 192.168.1.73:443>

DocumentRoot /web/vhosts/www2/

ServerName  www2.stuX.com:443

SSLEngine on

SSLCertificateFile /etc/httpd/ssl/httpd.crt

SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

</VirtualHost>

6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。

安装开发环境

[[email protected] ~]# yum groupinstall "Development Tools" "Server Platform Development" -y

1、编译安装Apache

解决依赖关系

(1)编译安装apr、apr-util

[[email protected] ~]# tar xf apr-1.5.2.tar.gz 

[[email protected] ~]# cd apr-1.5.2/

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

[email protected] ~]# make && make install && cd

[[email protected] ~]# tar xf apr-util-1.5.4.tar.bz2 

[[email protected] ~]# cd apr-util-1.5.4/

[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 

[[email protected] apr-util-1.5.4]# make && make install && cd

(2)httpd-2.4.16依赖于pcre-devel软件包

[[email protected] ~]# yum -y install pcre-devel  openssl-devel

编译安装httpd-2.4.16

[[email protected] ~]# tar xf httpd-2.4.16.tar.bz2 

[[email protected] ~]# cd httpd-2.4.16/

[[email protected] httpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[[email protected] ~]# make -j 4 && make install && cd

[[email protected] ~]# vim /etc/profile.d/httpd.sh

添加

export PATH=/usr/local/apache/bin:$PATH

[[email protected]lhost ~]# . /etc/profile.d/httpd.sh 

#编辑apache服务脚本

[[email protected] ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

[[email protected] ~]# vim /etc/init.d/httpd

添加

# chkconfig: 2345 85 15

# description: httpd startup for the Apache Http Server

[[email protected] ~]# service httpd start

[[email protected] ~]# chkconfig --add httpd

[[email protected] ~]# chkconfig httpd on

[[email protected] ~]# ss -tnl | grep :80

LISTEN     0      128         :::80                      :::* 

2、编译安装MySQL

#添加mysql用户

[[email protected] ~]# groupadd -g 316 mysql

[[email protected] ~]# useradd -g mysql -u 316 -r -s /sbin/nologin mysql

#安装mysql依赖的软件包

[[email protected] ~]# yum -y install cmake ncurses-devel

#编译安装mysql 

[[email protected] ~]# tar xf mysql-5.6.26.tar.gz -C /usr/local/

[[email protected] ~]# cd /usr/local/mysql-5.6.26/

[[email protected] mysql-5.6.26]# cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1  -DMYSQL_DATADIR=/usr/local/mysql/data  -DMYSQL-USER=mysql

[[email protected] mysql-5.6.26]# make -j 4 && make install

[[email protected] mysql-5.6.26]# cd && chown -R mysql:mysql /usr/local/mysql/

[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[[email protected] ~]# sed  -i ‘s#^basedir=#basedir=/usr/local/mysql#‘ /etc/init.d/mysqld

[[email protected] ~]# sed  -i ‘s#^datadir=#datadir=/usr/local/mysql/data#‘ /etc/init.d/mysqld

[[email protected] ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

[[email protected] ~]# sed -i ‘/^\[mysqld\]/adatadir = /usr/local/mysql/data‘ /etc/my.cnf

[[email protected] ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf

[[email protected] ~]# chkconfig mysqld on

[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

[[email protected] ~]# ln -s /usr/local/mysql/bin/* /bin/

[[email protected] ~]# service mysqld start

3、安装PHP

安装php依赖的软件

[[email protected] ~]# yum -y install libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel

[[email protected] ~]# tar xf libmcrypt-2.5.8.tar.bz2 

[[email protected] ~]# cd libmcrypt-2.5.8/

[[email protected] libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt

[[email protected] libmcrypt-2.5.8]# make && make install

[[email protected] libmcrypt-2.5.8]# cd

(一)httpd模块形式编译安装PHP

[[email protected] ~]# tar xf php-5.6.13.tar.bz2 

[[email protected] ~]# cd php-5.6.13/

#以httpd模块方式运行,所以需要在编译时指定apache的apxs2的目录路径 --with-apxs2=/usr/local/apache/bin/apxs 

[[email protected] php-5.6.13]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/lib64 --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt=/usr/local/libcrympt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

[[email protected] php-5.6.13]# make -j 4 && make install

[[email protected] php-5.6.13]# cp php.ini-production /etc/php.ini && cd

#编辑apache配置文件

[[email protected] ~]#sed -i ‘s/index.html/index.html index.php/‘ /etc/httpd/httpd.conf

[[email protected] ~]#sed -i ‘377a    AddType application/x-httpd-php .php‘ /etc/httpd/httpd.conf

[[email protected] ~]#sed -i ‘378a    AddType application/x-httpd-php-source .phps‘ /etc/httpd/httpd.conf

[[email protected] ~]#service httpd  restart

[[email protected] ~]#echo ‘<?php phpinfo();  ?>‘ >/usr/local/apache/htdocs/index.php

访问http://192.168.1.72/index.php进行测试

(二)以fpm模式运行

[[email protected] ~]# sed -i ‘1a/usr/local/libmcrypt/lib‘ /etc/ld.so.conf

[[email protected] ~]# sed -i ‘2a/usr/local/mysql/lib‘ /etc/ld.so.conf

[[email protected] ~]# yum install php-pear -y

[[email protected] ~]# ldconfig

[[email protected] ~]# echo ‘ldconfig‘ >> /etc/rc.local

[[email protected] ~]# tar xf php-5.6.13.tar.bz2 

[[email protected] ~]# cd php-5.6.13/

#以fpm模式运行,使能fpm选项,--enable-fpm, --with-apxs2一项就不需要启用了

[[email protected] php-5.6.13]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-mcrypt=/usr/local/libmcrypt

[[email protected] php-5.6.13]# make -j 4 && make install

[[[email protected] php-5.6.13]# cp php.ini-production /usr/local/php/php.ini && cd

[[email protected] php-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[[email protected] php-5.6.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[[email protected] php-5.6.13]#  chmod +x /etc/init.d/php-fpm

[[email protected] php-5.6.13]# chkconfig php-fpm on

[[email protected] php-5.6.13]# /etc/init.d/php-fpm start

Starting php-fpm  done

[[email protected] php-5.6.13]# netstat -antup | grep php-fpm

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      9769/php-fpm: maste 

#编辑apache配置文件

[[email protected] ~]# sed -i ‘s/^#LoadModule proxy_fcgi/LoadModule proxy_fcgi/‘ /etc/httpd/httpd.conf

[[email protected] ~]# sed -i ‘s/^#LoadModule proxy_module/LoadModule proxy_module/‘ /etc/httpd/httpd.conf

[[email protected] ~]#sed -i ‘s/index.html/index.html index.php/‘ /etc/httpd/httpd.conf

[[email protected] ~]#sed -i ‘377a    AddType application/x-httpd-php .php‘ /etc/httpd/httpd.conf

[[email protected] ~]#sed -i ‘378a    AddType application/x-httpd-php-source .phps‘ /etc/httpd/httpd.conf

[[email protected] ~]#service httpd  restart

[[email protected] ~]#echo ‘<?php phpinfo();  ?>‘ >/usr/local/apache/htdocs/index.php

访问http://192.168.1.72/index.php进行测试

时间: 2024-10-11 17:16:22

Linux第十二周的相关文章

Linux 第十二周上课笔记 阿帕奇服务

apache [[email protected] ~]# yum install httpd -y [[email protected] html]# yum install httpd-manual -y 更改默认发布文件 [[email protected] html]# vim /etc/httpd/conf/httpd.conf 更改默认发布目录 [[email protected] html]# mkdir /www/westos -p [[email protected] html

2017-2018-1 《Linux内核原理与设计》第十二周作业

<linux内核原理与设计>第十二周作业 Sql注入基础原理介绍 分组: 和20179215袁琳完成实验 一.实验说明 ??SQL注入攻击通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,本章课程通过 LAMP 搭建 Sql 注入环境,两个实验分别介绍 Sql 注入爆破数据库.Sql 注入绕过验证两个知识点. 首先通过下面命令将代码下载到实验楼环境中,作为参照对比进行学习. $ wget http://labfil

20145317《信息安全系统设计基础》第十二周学习总结1

20145317<信息安全系统设计基础>第十二周学习总结1 教材学习内容总结 第九周学习内容总结http://www.cnblogs.com/5317p/p/6052889.html 第十周学习内容总结http://www.cnblogs.com/5317p/p/6076074.html 第十一周学习内容总结http://www.cnblogs.com/5317p/p/6106708.html 视频学习内容总结 指针与声明 C语言中变量的声明包括两个部分: 类型 声明符 对于简单类型,声明并不

2017-2018-1 20155321 《信息安全系统设计基础》第十二周学习总结

2017-2018-1 20155321 <信息安全系统设计基础>第十二周学习总结 代码托管 上周考试错题总结 (多选题|1分)Y86-64中()指令没有访存操作 A.rrmovl B.irmovq C.rmmovq D.pushq E.jXX F.ret 正确答案:ABE (单选题|1分)Y86-64中,指令执行分为()阶段 A.3 B.4 C.5 D.6 E.7 F.8 正确答案:D ( 多选题 | 1 分)下面说法正确的是() A.ALU是一种时序电路 B.ALU是一种组合电路 C.寄存

第十二周测试

第十二周测试 MySort 注意:研究sort的其他功能,要能改的动代码,需要答辩 模拟实现Linux下Sort -t : -k 2的功能. 要有伪代码,产品代码,测试代码(注意测试用例的设计) 参考 Sort的实现.提交博客链接. 1 import java.util.*; 2 3 public class MySort1 { 4 public static void main(String [] args) { 5 String [] toSort = {"aaa:10:1:1",

第十二周进度条

第十二周          日期  星期一   星期二   星期三   星期四   星期五   星期六   星期日  了解到的知识点 js获取当前时间 var d = new Date() var nowYear = +d.getFullYear() EF框架填充下拉菜单 var model = db.GYSAllFoods.Select(m => new{GYS = m.GYS}).Distinct();//去重很关键            foreach (var item in model

学习进度第十二周

  第十二周 所花时间(包括上课) 11h(4h上课,7课下) 代码量(行) 220 博客量(篇) 1 了解到的知识点 这个星期主要进行了安卓实验和大作业的编写,从中学到了利用安卓SQLite 数据库 进行表的存储以及应用,按照教程成功编写了一个特别小的视频播放器,学会了进度 条等控件的使用.

学习进度-第十二周

  第十二周 所花时间(包括上课) 10小时 代码量(行) 48行 博客量(篇) 3篇 了解到的知识点

第十二周(补)

这几周有点心不在焉的,学习状态不好,作业都忘记写了,有的是存在记事本里忘记上传 周次 学习时间 新编写代码行数 博客量(数) 学到知识点 第十二周 6 80 1 html                               <html><head> <title> HTML</title></head><body > <h1>会员注册界面</h1><form action="proces