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 [email protected] 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 [email protected] 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 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 [email protected]:/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 [email protected]:/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數據庫。可以將三個服務分別拆分至不同的主機上新聞熱點
疑難解答