mkdir -pv /mydata/data
chown -R MySQL.mysql /mydata/data
(这是为了mysql能够向目录里面写数据)安装配置mariadb groupadd mysql
useradd -g mysql mysql
tar xf mariadb-5.5.54-linux-x86_64.tar -C /usr/local
cd /usr/local
ln -sv mariaDB-version mysql
cd /usr/local/mysql
chown -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/data
innodb_file_per_table = ON
skip_name_resolve = ON
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
这个地方好像不能使用复制,必须手打cp support-files/mysql.server /etc/init.d/mysqld
chkconfig –add mysqld
service 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 install
2:编译安装apr-util-1.4+ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
3:编译安装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=prefor
make && make install
4:自带的Apache服务控制脚本:apachectl脚本在/usr/local/httpd-2.4/bin/目录下,可以将这个目录添加到环境变量中,编辑 vi /etc/profile.d/httpd.sh
, 添加export PATH=/usr/local/apache-2.4/bin/:$PATH
,那么启动的时候,就可以直接使用apachectl start
5:另外,一般来说需要将头文件和库文件输出 ln -sv /usr/local/apache-2.4/include /usr/include/httpd
6:编写服务脚本实现service httpd start 启动httpd 可以拷贝一个启动脚本,修改中对应的变量cp /etc/init.d/httpd httpd2.4
vi 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.4
service 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)测试结果
![Alt text](./屏幕快照 2017-02-13 上午12.30.23.png)
![Alt text](./屏幕快照 2017-02-13 上午12.38.25.png)
![Alt text](./屏幕快照 2017-02-13 上午12.49.49.png)![Alt text](./屏幕快照 2017-02-13 上午12.50.03.png)(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 3655
mkdir -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/ssl
cd /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 365
scp 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 365
scp /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)检验结果 ![Alt text](./屏幕快照 2017-02-13 上午1.43.41.png)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数据库。可以将三个服务分别拆分至不同的主机上新闻热点
疑难解答