
适用场景:它适合于没有线程安全库,需要避免线程兼容性问题的系统。它是要求将每个请求相互独立的情况下最好的MPM,这样若一个请求出现问题就不会影响到其他请求,适合于并发量适中而又追求稳定的用户使用。worker:多进程多线程模型,每线程处理一个用户请求 一个主进程:负责生成子进程;负责创建套接字;负责接收请求,并将其派发给某子进程进行处理多个子进程:每个子进程负责生成多个线程每个线程:负责响应用户请求并发响应数量:m*n,m:子进程数量,n:每个子进程所能创建的最大线程数量适用场景:占据更少的内存,高并发下表现更优秀。event:事件驱动模型,多进程模型,每个进程响应多个请求 一个主进程 :负责生成子进程;负责创建套接字;负责接收请求,并将其派发给某子进程进行处理子进程:基于事件驱动机制直接响应多个请求适用场景:event模型是三种模型中效率最高的一种,可以突破10K的限制(即并发数1W),对海量的系统特别适用。 简要图解
mkdir -pv /mydata/datachown -R MySQL.mysql /mydata/data (这是为了mysql能够向目录里面写数据)安装配置mariadb groupadd mysqluseradd -g mysql mysqltar xf mariadb-5.5.54-linux-x86_64.tar -C /usr/localcd /usr/localln -sv mariaDB-version mysqlcd /usr/local/mysqlchown -R root:mysql ./*(防止mysql进程被劫持,具有目录的属主权限)cp support-files/my-large.cnf /etc/mysql/my.cnf(mysql进程读取配置文件的顺序/etc/my.cnf –> /etc/mysql/my.cnf –>–default-extra-file=/PATH/TO/CONF_FILE –> ~/.my.cnf)vi /etc/mysql/my.cnf 添加: datadir = /mydata/datainnodb_file_per_table = ONskip_name_resolve = ONscripts/mysql_install_db --user=mysql --datadir=/mydata/data 这个地方好像不能使用复制,必须手打cp support-files/mysql.server /etc/init.d/mysqldchkconfig –add mysqldservice mysqld start将mysql的库文件共享链接出来 vi /etc/ld.so.conf.d/mysql.conf添加:/usr/local/msyql/lib重读配置文件:ldconfig检查mysql的库文件是否可以读取:ldconfig -p | grep mysql将mysql的客户端程序的路径添加到环境变量中 vi /etc/profile.d/mysql.sh添加 export PATH=/usr/local/mysql/bin:$PATH让内核重新读取配置文件:. /etc/profile.d/mysql.sh使用mysql的安全安装工具对mysql进行安全加固 mysql_secure_installation登入mysql , 授权远程登入的root用户 grant all on *.* to root@'192.168.%.%' identified by 'yhy3426356';flush privileges;安装httpd-2.4 由于在CentOS 6上安装httpd-2.4,需要编译安装,依赖apr-1.4+ , 依赖apr-util-1.4+,那么如果需要在CentOS 6上安装httpd需要编译安装,并且安装Development tools、Server Platform Development包组和pcre-devel包下载apr-1.5.2.tar和apr-util-1.5.4.tar在当前目录下 , 解压 ,下载httpd-2.4到当前目录下,解压1:编译安装apr-1.4+ ./configure --prefix=/usr/local/apr/make && make install2:编译安装apr-util-1.4+ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install3:编译安装httpd-2.4 ./configure --prefix=/usr/local/apache-2.4 --sysconfdir=/etc/httpd-2.4 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=preformake && make install4:自带的Apache服务控制脚本:apachectl脚本在/usr/local/httpd-2.4/bin/目录下,可以将这个目录添加到环境变量中,编辑 vi /etc/profile.d/httpd.sh, 添加export PATH=/usr/local/apache-2.4/bin/:$PATH,那么启动的时候,就可以直接使用apachectl start5:另外,一般来说需要将头文件和库文件输出 ln -sv /usr/local/apache-2.4/include /usr/include/httpd6:编写服务脚本实现service httpd start 启动httpd 可以拷贝一个启动脚本,修改中对应的变量cp /etc/init.d/httpd httpd2.4vi httpd-2.4#注释 # if [ -f /etc/sysconfig/httpd ]; then # . /etc/sysconfig/httpd # fi # 修改为编译安装的apachectl路径 apachectl=/usr/local/apache-2.4/bin/apachectl # 修改为编译安装的httpd路径 httpd=${HTTPD-/usr/local/apache-2.4/bin/httpd} prog=httpd # 修改为编译安装的pidfile路径 pidfile=${PIDFILE-/usr/local/apache-2.4/logs/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd-2.4} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} 虽然可以这样修改,但是服务控制脚本一定要会编写,属于shell编程部分chkconfig --add /etc/rc.d/init.d/httpd-2.4service httpd-2.4 start添加apache 用户和用户组,并且修改主配置文件指定user为apache,group为apacheCentOS 7 编译安装php5.4安装 (编译为httpd的模块) 下载php-5.4.26.tar ,解压yum install libxml2-devel libmcrypt-devel bzip2-devel curl-devel -y如果MariaDB和PHP安装不在一台主机上使用:./configure --prefix=/usr/local/php5.4 --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache-2.4/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl拷贝php的主配置文件:cp php.ini-production /etc/php.ini编辑httpd的主配置文件,注释中心主机,启用虚拟机,在主配置文件中添加: include /etc/httpd-2.4/extra/httpd-vhosts.conf include /etc/httpd-2.4/extra/httpd-php.conf编辑/etc/httpd-2.4/extra/httpd-vhosts.conf文件 修改:<VirtualHost *:80> ServerAdmin 307443272@QQ.com DocumentRoot "/apps/vhosts/b.net" ServerName www.b.net ErrorLog "logs/b.net_error_log" CustomLog "logs/b.net_access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin 307443272@qq.com DocumentRoot "/apps/vhosts/c.org" ServerName www.c.org ErrorLog "logs/c.org_error_log" CustomLog "logs/c.org_access_log" common </VirtualHost>编辑/etc/httpd-2.4/extra/httpd-php.conf 添加:DirectoryIndex index.php AddType application/x-httpd-php .php首先在/apps/vhosts/b.net中测试下php和mysql vi index.php <?php $conn=mysql_connect('192.168.10.218','root','yhy3426356'); if ($conn) echo "ok"; else echo "failured"; phpinfo(); ?>显示结果为ok!!!和PHP的编译参数下载WordPress源码,将wordpress里面的所有的文件解压至/apps/vhosts/b.net中并且在数据库中创建Wordpress的数据库,和授权一个用户给WordPress试验过程如下:
(1)在主配置文件中注销中心主机(2)编辑子配置文件中的虚拟主机文件vi /etc/httpd/conf.d/vhost.conf添加内容如下: <VirtualHost *:80> ServerName www1.stuX.com DocumentRoot "/web/vhosts/www1" ErrorLog "/var/log/httpd/www1.err" CustomLog "/var/log/httpd/www1.access" combined <Directory "/web/vhosts/www1"> Options none AllowOverride none Require all granted </Directory> <Location /server-status> SetHandler server-status AuthType Basic AuthName "please enter your username and password!" AuthUserFile "/etc/httpd/conf/.htpasswd" Require valid-user </Location> </VirtualHost> <VirtualHost *:80> ServerName www2.stuX.com DocumentRoot "/web/vhosts/www2" ErrorLog "/var/log/httpd/www2.err" CustomLog "/var/log/httpd/www2.access" combined <Directory "/web/vhosts/www2"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>(3)生成虚拟用户文件 htpasswd -m -c /etc/httpd/conf/.htpasswd tom(4)测试结果


(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655mkdir -pv /etc/pki/CA/{certs,crl,newcerts}touch /etc/pki/CA/{serial,index.txt}echo 01 > /etc/pki/CA/serial(2)在httpd服务器上(IP:192.168.10.216),申请签证请求 mkdir /etc/httpd/sslcd /etc/httpd/ssl(umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)openssl req -new -key /etc/httpd/ssl/httpd.key -out httpd.csr -days 365scp httpd.csr root@192.168.10.219:/root/(3)CA主机上给httpd服务器签证 openssl ca -in /root/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365scp /etc/pki/CA/certs/httpd.crt root@192.168.10.216:/etc/httpd/ssl/(4)在httpd服务端安装mod_ssl模块,并设置https虚拟主机 yum -y install mod_ssl编辑配置文件/etc/httpd/conf.d/ssl.conf修改: DocumentRoot "/web/vhosts/www2" ServerName www2.stuX.com SSLCertificateFile /etc/httpd/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/ssl/httpd.key <Directory "/web/vhosts/www2"> Options none AllowOverride none Require all granted </Directory>(5)检验结果 php作为httpd的模块编译安装 当用户的请求到达的时候,到达web服务器,静态的内容都会在本地装载,都由httpd通过系统调用进行装载,如果装载的是静态内容,直接返回,如果是动态内容,交给httpd的php模块进行处理,将处理的结果进行返回给客户端,如果动态页面需要请求数据,那么php代码会通过网络套接字连接到MariaDB数据库。这种模式可以使用两天服务器,httpd+php 一台,MariaDB一台(2)php作为php-fpm编译安装,作为一项单独的服务 当用户的请求到达的时候,到达web服务器,静态的内容都会在本地装载,都由httpd通过系统调用进行装载,如果装载的是静态内容,直接返回。如果是动态内容,将整个请求的URL通过fcgi模块反向代理至php-fpm服务,php-fpm进程会通过URL加载本地的动态资源路径,如果动态页面需要请求数据,那么php代码会通过网络套接字连接到MariaDB数据库。可以将三个服务分别拆分至不同的主机上新闻热点
疑难解答