部署Discuz:
1.编码乱码的解决方法:
AddDefaultCharset GB2312
FastCGI:
php-fpm:php-fpm-VERSION-release.rpm
安装软件包:可信任的软件包:
1.OS的发行商发布的rpm包(光盘镜像中)
2.OS的发行商的官方站点中额外扩展的包
3.EPEL源中的包
注意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;
一、编译安装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"
二、使用通用二进制格式的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
三、编译安装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的配置:
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
Options None
AllowOverride None
Require all granted
设置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