1、請描述一次完整的http請求處理過程; (1)建立或處理連接:接受請求或拒絕請求 (2)如果接受請求: 并發訪問響應模型: 單進程I/O結構:啟動一個進程處理用戶請求,而且一次只處理一個,多個請求被串行響應; 多進程I/O結構:并行啟動多個進程,每個進程響應一個請求; 復用I/O結構:一個進程生成N個線程,每個線程響應一個用戶請求; (3)處理請求:對請求的報文進行解析,并獲取請求的資源及請求方法等相關信息; (4)訪問資源:獲取請求報文中請求的資源; (5)構建響應報文 (6)發送響應報文 (7)記錄日志 2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。 httpd所支持的處理模型有:prefork,worker,event prefork:多進程模型,每個進程響應一個請求; 一個主進程:負責生成n個子進程,子進程也稱為工作進程,每個子進程處理一個用戶請求,即便沒有用戶請求,也會預先生成多個空閑進程,等待客戶請求(最大不超過1024個) wokrer:多線程模型:,每個線程響應一個請求;一個主進程生成多個子進程,每個子進程負責生多個線程,每個線程響應一個請求 event:事件驅動模型,每個線程響應n個請求,一個主進程,生成m個子進程,每個進程直接n個請求 httpd-2.2:event為測試使用 httpd-2.4:event可生產中使用 3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。 LAMP編譯安裝 # LAMP編譯安裝,目前CentOS7操作系統上可以使用yum進行安裝,在CentOS6上需要編譯安裝 CentOS6 http-2.2主要安裝的,編譯安裝LAMP需要http-2.4進行編譯安裝 linux上需要準備編譯安裝的環境: 包組(CentOS 6): Server Platform Development Development Tools http-2.4需要較新版本的apr和apr-util 1,編譯安裝apr 需要下載:apr-1.5.2 (1).tar.bz2,apr-util-1.5.4.tar.bz2 ~]# tar xf apr-1.5.2\ \(1\).tar.bz2 ~]# cd apr-1.5.2 ]# ./configure --prefix=/usr/local/apr ]# make && make install 編譯安裝apr-util-1.5.4.tar.bz2 ]# tar xf apr-util-1.5.4.tar.bz2 ]# cd apr-util-1.5.4 ]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr(告知程序依據那個apr進行編譯安裝) ]# make && make install 好了這里就安裝好了apr和apr-util了 安裝http-2.4 1,httpd-2.4編譯安裝需要依賴pcre-devel軟件包,使用yum install進行安裝 ]# tar xf httpd-2.4.23.tar.bz2 ]# cd httpd-2.4.23 ]# ./configure --prefix=/usr/local/apache(程序安裝路徑) --sysconfdir=/etc/httpd24(程序配置文件) --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=event ]# make && make install 配置服務類腳本 ]# cd /etc/rc.d/init.d/ ]# cp httpd httpd24 編輯httpd24的配置文件修改文件路徑 apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd24.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd24} 將服務加入 ]# chkconfig --add httpd24 ]# chkconfig --list httpd24 httpd24 0:off 1:off 2:off 3:off 4:off 5:off 6:off 將httpd命令定義到新的httpd24下 ]# . /etc/profile.d/httpd.sh ]# cat /etc/profile.d/httpd.sh export PATH=/usr/local/apache/bin:$PATH 重讀配置文件 ]# . /etc/profile.d/httpd.sh ]# hash hits command 1 /usr/local/apache/bin/httpd 編譯安裝mariadb 先將下載好的軟件包進行解壓縮 ]# tar xf mariadb-5.5.32-linux-x86_64.tar.gz ]# cp mariadb-5.5.32-linux-x86_64 /usr/local/ -a 創建連接為mysql ]# ln -sv mariadb-5.5.32-linux-x86_64/ mysql 創建屬組:]# groupadd -r -g 306 mysql 創建用戶:]# useradd -r -g 306 -u 306 mysql 修改此文件中的屬主為root,屬組為mysql ]# chown root:mysql ./* 新建磁盤分區用于數據庫的使用 這里使用的邏輯磁盤分區的方法 使用fdisk /dev/sda 創建一個20G的磁盤空間 使用t將磁盤修改類型為8e 先建立pv ]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created 建立vg ]# vgs VG #PV #LV #SN Attr VSize VFree VolGroup 1 3 0 wz--n- 59.99g 0 [root@localhost mysql]# vgcreate myvg /dev/sda3 Volume group "myvg" successfully created 創建lv ]# lvcreate -L 10G -n mydata myvg Logical volume "mydata" created. 這里使用xfs文件系統 先使用yum install xfsprogs 加載模塊文件 ]# modprobe xfs ]# modinfo xfs filename: /lib/modules/2.6.32-642.4.2.el6.x86_64/kernel/fs/xfs/xfs.ko license: GPL description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled author: Silicon Graphics, Inc. srcversion: 67725EF8353DC29370566C8 depends: exportfs vermagic: 2.6.32-642.4.2.el6.x86_64 SMP mod_unload modversions 對磁盤進行格式化 ]# mkfs.xfs /dev/myvg/mydata meta-data=/dev/myvg/mydata isize=256 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 編輯/etc/fstab文件是其開啟自動掛載文件 /dev/myvg/mydata /mydata xfs defaults 0 0 新建一個目錄用戶存放mydata數據 查看需要編譯安裝的配置文件 [root@localhost mysql]# scripts/mysql_install_db --help ]# scripts/mysql_install_db --user=mysql(指定用戶) --datadir=/mydata/data/(初始化數據放入到那個文件夾) 啟動mysql需要使用一個服務腳本 [root@localhost support-files]# ls binary-configure magic my-medium.cnf mysql.server config.huge.ini my-huge.cnf my-small.cnf ndb-config-2-node.ini config.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.server SELinux config.small.ini my-large.cnf mysql-log-rotate solaris ]# cp mysql.server /etc/rc.d/init.d/mysqld 將服務加入到chkconfig [root@localhost support-files]# chkconfig --add mysqld [root@localhost support-files]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 配置文件查找次序: /etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf 這里如果需要將mysql命令加入到bash變量中永久有效有2中方法 在/etc/profile的export下面加入一行 export PATH=/usr/local/mysql/bin:$PATH 使用source /etc/profile 如需要對個人生效 在~/.bash_profile中加入 export PATH=/usr/local/mysql/bin:$PATH source ~/.bash_profile 這里在mysql第一次運作時需要對用戶權限等進行一次修改 mysql_secure_installation:安全初始化 初始化完成之后 [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 5.5.32-MariaDB-log MariaDB Server Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> user mysql -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'user mysql' at line 1 MariaDB [(none)]> MariaDB [(none)]> MariaDB [(none)]> MariaDB [(none)]> use mysql; Database changed MariaDB [mysql]> SELECT User,Host,Password FROM user; +------+-----------------------+-------------------------------------------+ | User | Host | Password | +------+-----------------------+-------------------------------------------+ | root | localhost | *17C5214AB2227D33B7976A03E25B9D7AD58913AD | | root | localhost.localdomain | *17C5214AB2227D33B7976A03E25B9D7AD58913AD | | root | 127.0.0.1 | *17C5214AB2227D33B7976A03E25B9D7AD58913AD | | root | ::1 | *17C5214AB2227D33B7976A03E25B9D7AD58913AD | +------+-----------------------+-------------------------------------------+ 4 rows in set (0.00 sec) 編譯安裝PHP 將下載好的php軟件包進行解壓縮 ]# tar xf php-5.5.38.tar.bz2 ]# cd php-5.5.38 解決好軟件依賴關系 請配置好yum源(系統安裝源及epel源)后執行如下命令: ]# yum -y groupinstall "Desktop Platform Development" ]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel 然后進行編譯安裝 ]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/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=/usr/local/apache/bin/apxs (將php編譯為http模塊)--with-mcrypt (加解密庫) --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts(支持apache work或event功能) 這里等待編譯完成,這里要記住httpd默認是不支持php模塊的,需要在httpd的文件中加入 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 定位至DirectoryIndex index.html 修改為: DirectoryIndex index.php index.html 查看http配置文件發現模塊文件有 LoadModule php5_module modules/libphp5.so 找到AddType加入上訴語句 為php提供配置文件 ]# cp php.ini-production /etc/php.ini 我的測試文件為: ]# cat index.php <?php $counn=mysql_connect('127.0.0.1','root','Pa$$w0rd01!'); if($counn) echo "OK"; else echo "NOT OK"; mysql_close(); phpinfo(); ?> 建立數據庫: 建立用戶名和登錄地址與密碼 > GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.0.44' IDENTIFIED BY 'wppasswd'; 建立數據庫: > CREATE DATABASE wpdb;
原創文章,作者:wostop,如若轉載,請注明出處:http://www.www58058.com/51799
請認真對待每一次作業中要求的細節,因為它很可能就是你工作中遺漏且真正讓你無法找到正解真正原因