部署Discuz:php
1.編碼亂碼的解決方法:mysql
AddDefaultCharset GB2312linux
FastCGI:web
php-fpm:php-fpm-VERSION-release.rpmsql
安裝軟件包:可信任的軟件包:數據庫
1.OS的發行商發佈的rpm包(光盤鏡像中)apache
2.OS的發行商的官方站點中額外擴展的包vim
3.EPEL源中的包api
注意FastCGI所依賴的環境:瀏覽器
1.httpd-2.4+
2.php-5.3.3+
編譯安裝AMP:
A:Apache(httpd), http://httpd.apache.org
M:MySQL or MariaDB
www.mysql.com
mariadb.org
P:php, http://php.net
httpd-2.4.27(apr-1.5.2 + apr-util-1.5.4) + MariaDB-5.5.57 + php-5.6.31
編譯以前,須要先安裝開發包組:
"Development Tools"
"Server Platform Development"
pcre-devel
libevent-devel
在編譯安裝程序以前,確保沒有使用rpm包的方式安裝過httpd、mysql-server、mariadb-server、php、php-fm;
1、編譯安裝httpd-2.4.27
1.編譯安裝apr:
# tar xf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr152
# make -j #
# make install
2.編譯安裝apr-util:
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.2
# ./configure --prefix=/usr/local/apr-util154 --with-apr=/usr/local/apr152
# make -j #
# make install
3.編譯安裝httpd-2.4.27:
# tar xf httpd-2.4.27.tar.gz
# cd httpd-2.4.27
# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr/local/apr152 --with-apr-util=/usr/local/apr-util154
# make -j #
# make install
4.
1) 導出二進制文件:
建立/etc/profile.d/httpd24.sh
export PATH=/usr/local/apache24/bin:$PATH
2) 導出幫助文檔:可選
編輯/etc/man.config
MANPATH /usr/local/apache24/man
3) 導出頭文件:
# ln -sv /usr/local/apache24/include/ /usr/include/httpd
5.若是想要使用service命令來啓動或關閉服務,則須要爲httpd提供sysV風格的腳本,腳本內容以下:/etc/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd24/httpd.conf
# config: /etc/sysconfig/httpd24
# pidfile: /var/run/httpd24.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd24 ]; then
. /etc/sysconfig/httpd24
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache24/bin/apachectl
httpd=${HTTPD-/usr/local/apache24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
# chmod +x /etc/rc.d/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on
注意:
想要成功使用該腳本管理服務,要在/etc/httpd24/httpd.conf配置文件中添加如下指令:
PIDFile "/var/run/httpd24.pid"
2、使用通用二進制格式的MariaDB包安裝MariaDB:
# tar xf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
# groupadd -r -g 306 msyql
# useradd -r -u 306 -g mysql mysql
# cd /usr/local
# ln -sv /usr/local/mariadb-5.5.57-linux-x86_64 mysql
# cd mysql
# chown mysql. -R .
# mkdir /mydata/data -pv
# chown mysql. /mydata/data
# cp support-files/my-large.cnf /etc/my.cnf
添加配置條目:
innodb_file_per_table = ON
skip_name_resolve = ON
datadir = /mydata/data
# cp support-files/mysql.server /etc/init.d/mysqld
導出二進制文件:
# vim /etc/profile.d/maria5557.sh
export PATH=/usr/local/mysql/bin:$PATH
# source /etc/profile.d/maria5557.sh
導出庫文件:
mysql-x86_64.conf文件移除或更名爲非.conf結尾的文件名;
# vim /etc/ld.so.conf.d/mariadb5557.conf
/usr/local/mysql/lib
# ldconfig -v
導出頭文件:
# ln -sv /usr/local/mysql/include /usr/include/mysql
初始化數據庫:
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
啓動服務:
# service mysqld start
# chkconfig --add mysqld
# chkconfig mysqld on
3、編譯安裝php-5.6.31:
可能須要依賴於:
libxml2-devel, gd-devel, freetype-devel, libmcrypt-devel
# tar xf php-5.6.31.tar.gz
# cd php-5.6.31
# ./configure --prefix=/usr/local/php56 --enable-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-libxml-dir=/usr --with-zlib --with-apxs2=/usr/local/apache24/bin/apxs --with-config-file-path=/etc/php56.ini --with-config-file-scan-dir=/etc/php56.d --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt
# make -j #
# make install
# cp php.ini-production /etc/php56.ini
# mkdir /etc/php56.d
# cp sapi/fpm/php-fpm.conf /etc/php56.d/
# vim /etc/php56.d/php-fpm.conf
user = nobody
group = nobody
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /fpm-status
pm.max_requests = 500
pid = /usr/local/php56/var/run/php-fpm.pid
pm方式的php進程存儲session的路徑:
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php56/session
# mkdir /var/lib/php56/session
# chown nobody.nobody /var/lib/php56/session
爲php-fpm提供SysV風格腳本,並將其添加至服務列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
修改/etc/rc.d/init.d/php-fpm裏面的內容:
1.添加下列語句
scan_conf_dir=/etc/php56.d
2.修改下列語句:
php_fpm_CONF=${exec_prefix}/php-fpm.conf
改成:
php_fpm_CONF=${scan_conf_dir}/php-fpm.conf
啓動服務:
# service php-fpm start
LAMP(5)
回顧:
FastCGI:php-fpm
C6:httpd-2.2,默認不支持fcgi模塊
解決方法:編譯安裝httpd-2.4
C7:httpd-2.4,默認支持fcgi模塊
使用httpd和fastCGI兼容通訊:
CentOS 7中安裝php-fpm及相關rpm包組件:
# yum install php-fpm php-pdo php-gd php-mbstring php-mysql
配置文件:
服務進程的配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf
服務進程的配置文件:
[global]:
pid = /run/php-fpm/php-fpm.pid
/etc/php-fpm.d/www.conf配置文件中的pool的配置內容:
[www]:
user = apache
group = apache
listen = 127.0.0.1:9000
listen.backlog = 100
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.status_path = /fpm-status
pm.max_requests = 500
配置httpd和php-fpm結合的實例:
httpd的配置:
<VirtualHost 172.16.72.1:80>
DocumentRoot "/myweb/vhosts/www"
ServerName www.qhdlink.com
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php) fcgi://127.0.0.1:9000/myweb/vhosts/www/$1
<Directory "/myweb/vhosts/www">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
設置php加速訪問:
opcode加速器:
APC,eAccelerator,Xcache,...
下載xcache的源代碼 http://xcache.lighttpd.net
編譯xcache:
# tar xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# phpize
# ./configure --enable-xcache --with-php-config=/usr/bin/php-config
# make -j #
# make install
直接使用rpm包安裝,rpm包在EPEL源中:
yum install php-xcache
rsyslog:
日誌:記錄具備必定意義的歷史事件;
事件:時間,事件的自己,事件的級別(事件的關鍵程度)
syslog:
主要用於記錄諸如系統啓動、應用程序啓動、應用程序在運行過程當中產生的一些歷史事件及相關信息等;
klogd:與內核有關的事件
syslogd:與應用程序有關的事件
C/S架構:經過TCP或UDP提供日誌記錄服務;
syslogng:syslog Next Generation,下一代的syslog
rsyslog:
rsyslog的特性:
1.多線程,並行記錄日誌;
2.支持更多的協議,如:TCP、UDP、SSL、RELP
3.支持多種格式的日誌存儲:文件,RDBMS(MySQL,Oracle),...
4.支持強大的日誌過濾機制,實現過濾日誌信息中任何部分的內容
5.自定義輸出格式
ELK Stack:
Elasticsearch:倒排索引的搜索引擎
Logstash:日誌收集工具
Kibina:展現工具,php網頁
rsyslog:
facility:設施,rsyslog收集整理日誌的組件;
priority:優先級,日誌記錄的事件的級別;
facility主要包括:
auth,authpriv,cron,daemon,kern,lpr,mail,mark,news,security,user,uucp,syslog,local0~local7
priority主要包括:
debug,info,notice,warn,err,crit,alert,emerg(panic)
安裝包:rsyslog
程序環境:
配置文件:/etc/rsyslog.conf, /etc/rsyslog.d/*.conf
主程序:/usr/sbin/rsyslogd
服務器的啓動:
C6:service rsyslog {start|restart|stop|status}
C7:systemctl {start|restart|stop|status} rsyslog.service
主配置文件:/etc/rsyslog.conf
由三部分組成:
第一部分:#### MODULES ####
第二部分:#### GLOBAL DIRECTIVES ####
第三部分:#### RULES ####
#### RULES ####部分:
facility:
*:全部的設施
f1,f2,...:由多個設施構建的列表
priority:
*:全部級別
none:不包含任何級別
PRIORITY:包括指定的PRIORITY在內,直到最高級之間的全部級別;
如:warn,意思是:warn,err,crit,alert,emerg
=PRIORITY:僅記錄指定的級別的日誌;
如:=warn,意思是:warn
target:
文件:以絕對路徑的方式給出日誌文件;"-"表示異步寫入;
用戶:將日誌信息通知給指定的用戶;也能夠向全部已經登陸到系統的用戶的終端發送信息;
日誌服務器:@Server_ip,把日誌發送到指定的日誌服務器上;
管道:| COMMAND
回顧:
LAMP架構:httpd和fcgi結合
xcache對opcode加速,
rsyslog:
facility
priority
/etc/rsyslog.conf:三個部分
rsyslog(2)
其餘的日誌文件:
1./var/log/btmp:bad login,當前系統上,用於記錄用戶嘗試登陸失敗相關信息的日誌;
lastb命令查看文件內容;
2./var/log/wtmp:win login,當前系統上,用於記錄用戶正確登陸的信息的日誌文件;
last命令查看文件內容;
經常使用選項:
-n #:僅顯示最近#條記錄;
3./var/log/secure:記錄與用戶帳戶的認證受權有關的信息的日誌文件;
能夠使用各類編輯器或文本處理工具來查看內容;
4./var/log/dmesg:用於記錄系統引導過程當中的全部輸出信息的日誌文件;
能夠使用各類編輯器或文本處理工具來查看內容;
也能夠使用dmesg命令查看;
將rsyslog的日誌記錄於MySQL(MariaDB):
1.安裝rsyslog鏈接至MySQL的驅動;
# yum install rsyslog-mysql
2.在MySQL中建立受權帳戶:
grant all on Syslog.* to 'sladmin'@'127.0.0.1' identified by 'slpass';
grant all on Syslog.* to 'sladmin'@'localhost' identified by 'slpass';
grant all on Syslog.* to 'sladmin'@'172.16.%.%' identified by 'slpass';
3.使用SQL腳本建立數據庫和數據表:
mysql -usladmin -hlocalhost -p < /usr/share/doc/rsyslog-7.4.7/mysql-createDB.sql
4.在rsyslog的配置文件中配置使用MySQL:
### MODULES ###
$ModLoad ommysql
### RULES ###
facility.priority :ommysql:DB_HOST,DB_NAME,DB_USER,DB_PASS
5.重啓rsyslog服務;
提供Web GUITAR工具:loganalyzer
1.須要LAMP架構平臺;
2.安裝loganalyzer
# tar loganalyzer-4.1.5.tar.gz
# cd loganalyzer-4.1.5
# cp -a src /PATH/TO/SOME_VHOST/loganalyzer
# cp contrib/*.sh /PATH/TO/SOME_VHOST/loganalyzer
# cd /PATH/TO/SOME_VHOST/loganalyzer
# chmod +x *.sh
# ./configure.sh
# ./secure.sh
# chmod 666 config.php
3.經過瀏覽器訪問:
http://HOST/loganalyzer
Source Type:
DiskFile:分析本地的某個日誌文件;
MySQL Native:從MySQL中讀取日誌內容;
若是選擇DiskFile,下面要指定:
Syslog file爲具體的日誌文件路徑
若是選擇漏洞MySQL Native,下面要指定:
MonitorWare
Database Host
Database Name
Database Tablename
Database User
Database Password