Apache鏃ュ織鍒嗗壊

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache鏃ュ織鍒嗗壊相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/php5' title='php5'>php5   util   rpm -ivh   鎸傝浇   cal   date   mct   鐩戝惉绔彛   com   

鏃ュ織鍒嗗壊

闅忕潃缃戠珯鐨勮闂噺澧炲姞锛岄粯璁ゆ儏鍐典笅Apache鐨勫崟涓棩蹇楁枃浠朵篃浼氳秺鏉ヨ秺澶?/strong>
鏃ュ織鏂囦欢鍗犵敤纾佺洏绌洪棿寰堝ぇ
鏌ョ湅鐩稿叧淇℃伅涓嶆柟渚?
瀵规棩蹇楁枃浠惰繘琛屽垎鍓?/strong>
Apache鑷甫rotatelogs鍒嗗壊宸ュ叿瀹炵幇
绗笁鏂瑰伐鍏穋ronolog鍒嗗壊

rotatelogs鍒嗗壊宸ュ叿

閰嶇疆缃戠珯鐨勬棩蹇楁枃浠惰浆浜ょ粰rotatelogs鍒嗗壊澶勭悊
[root@www ~ ]# vim /etc/httpd/conf/httpd.conf
ErrorLog "/usr/local/bin/rotatelogs -|
/var/log/httpd/error %Y%m%d.log 86400"
CustomLog "|/usr/local/bin/rotatelogs -|
/var/log/httpd/access
%Y%m%d.log 86400" combined
[root@www ~]#systemctl restart httpd
[root@www httpd]# II
鎬荤敤閲?0
-rW-r--r-- 1 root root 1814 7鏈? 17:54 access 201 80707.log
-rW-r--r-- 1 root root 584 7鏈? 17:55 error 201 80707.l0g閰嶇疆鏍煎紡涓?br/>ErrorLog "| rotatelogs鍛戒护鐨勭粷瀵硅矾寰?|鏃ュ織鏂囦欢璺緞/缃戠珯鍚?
error%Y%m%d.log 86400"
CustomLog "| rotatelogs鍛戒护璺緞-|鏃ュ織鏂囦欢璺緞/缃戠珯鍚?
access
%Y%m%d.log 86400" combined

婧愮爜缂栬瘧瀹夎cronolog宸ュ叿

閰嶇疆缃戠珯鏃ュ織鏂囦欢杞氦缁檆ronolog鍒嗗壊澶勭悊
閰嶇疆鏍煎紡涓?
ErrorLog "| cronolog鍛戒护鐨勭粷瀵硅矾寰?鏃ュ織鏂囦欢璺緞/缃戠珯鍚?-
error_ %Y%m%d.log"
CustomLog "| cronolog鍛戒护鐨勭粷瀵硅矾寰?鏃ュ織鏂囦欢璺緞/缃戠珯鍚?br/>%Y %m%d.log" combined

鏃ュ織鍒嗗壊瀹為獙

Apache鑷甫鐨勬棩蹇楀垎闅斿伐鍏穜otatelogs

涓€銆佸畨瑁匒pache鏈嶅姟

[root@localhost ~]# yum install httpd -y //瀹夎httpd鏈嶅姟
[root@localhost ~]# cd /usr/sbin //鍒囨崲鍒?usr/sbin鐩綍涓?br/>[root@localhost sbin]# ls rotat* //鏃ュ織鍒嗘瀽宸ュ叿浣嶇疆
rotatelogs
[root@localhost sbin]# vim /etc/httpd/conf/httpd.conf //杩涘叆淇敼Apache閰嶇疆鏂囦欢
Listen 192.168.131.129:80 ##淇敼ipv4鐩戝惉鍦板潃涓烘湰鏈哄湴鍧€
#Listen 80 //灏唅pv6绔彛娉ㄩ噴
ServerName www.kgc.com:80 //淇敼鍩熷悕
[root@localhost named]# systemctl stop firewalld.service //鍏抽棴闃茬伀澧?br/>[root@localhost named]# setenforce 0 //鍏抽棴澧炲己瀹夊叏鍔熻兘
[root@localhost html]# systemctl start httpd.service //鍚姩缃戠粶鏈嶅姟
[root@localhost sbin]# ls /var/log/httpd/ //浠庡惎鍔ㄦ湇鍔¤捣锛屽氨宸茬粡鏈変簡鏃ュ織鏂囦欢
accesslog errorlog

浜屻€侀厤缃甴ttp涓婚厤缃枃浠?/h2>

[root@localhost sbin]# vim /etc/httpd/conf/httpd.conf //杩涘叆淇敼Apache閰嶇疆鏂囦欢
#ErrorLog "logs/errorlog"
ErrorLog "| /usr/sbin/rotatelogs -l logs/www.kgc.com.error%Y%m%dlog 86400"
//姝ゅ娣诲姞宸ュ叿缁濆璺緞锛岀敓鎴愭棩蹇楃殑鏃堕棿
CustomLog "| /usr/sbin/rotatelogs -l logs/www.kgc.com.access_%Y%m%dlog 86400" combined
//姝ゅ娣诲姞宸ュ叿缁濆璺緞锛岀敓鎴愭棩蹇楃殑鏃堕棿

涓夈€侀噸鍚湇鍔★紝鏌ョ湅鏃ュ織鍒嗗壊鎯呭喌

[root@localhost conf]# systemctl stop httpd.service //鍏抽棴http鏈嶅姟
[root@localhost conf]# systemctl start httpd //鍚姩http鏈嶅姟
[root@localhost conf]# cd /var/log/httpd/ //鍒囨崲鍒版棩蹇楃洰褰曚笅鏌ョ湅
[root@localhost httpd]# ls
access_log error_log www.kgc.com.error_20191026log //浠婃棩鐨勬棩蹇楁枃浠?br/>[root@localhost httpd]# date
2019骞?10鏈?26鏃?鏄熸湡鍏?10:26:24 CST
[root@localhost httpd]# date -s 10/26/19 //淇敼鏃堕棿鍒扮浜屽ぉ
2019骞?10鏈?27鏃?鏄熸湡鏃?00:00:00 CST
[root@localhost httpd]# systemctl stop httpd //閲嶅惎鏈嶅姟
[root@localhost httpd]# systemctl start httpd
[root@localhost httpd]# ls //鏌ョ湅鏃ュ織鍒嗗壊鐨勬儏鍐?br/>access_log www.kgc.com.error_20191026log
error_log www.kgc.com.error_20191027log

浣跨敤绗笁鏂瑰伐鍏穋ronolog

1銆佸畨瑁卙ttp鏈嶅姟骞惰繙绋嬫寕杞界涓夋柟宸ュ叿

[root@localhost ~]# mount.cifs //192.168.10.88/LAMP-C7 /mnt
//杩滅▼鎸傝浇杞欢鍖呭埌鏈湴/mnt鐩綍
[root@localhost ~]# cd /mnt/ //鍒囨崲鍒?mnt鐩綍涓?br/>[root@localhost mnt]# ls
apr-1.6.2.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt
apr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gz
awstats-7.6.tar.gz httpd-2.4.29.tar.bz2 php-5.6.11.tar.bz2
[root@localhost mnt]# rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm //瀹夎宸ュ叿

2銆佹煡鐪嬪伐鍏峰苟淇敼http閰嶇疆鏂囦欢

[root@localhost mnt]# cd /usr/sbin
[root@localhost sbin]# ls cronolog*
cronolog
[root@localhost sbin]# vim /etc/httpd/conf/httpd.conf
Listen 192.168.13.128:80 //淇敼鐩戝惉鐨勫湴鍧€涓烘湰鍦板湴鍧€
#Listen 80 //娉ㄩ噴ipv6鐩戝惉绔彛
ServerName www.kgc.com:80 //淇敼鍩熷悕
ErrorLog "| /usr/sbin/cronolog logs/www.kgc.com.error%Y%m%d.log"
CustomLog "| /usr/sbin/cronolog logs/www.kgc.com.access
%Y%m%d.log" combined
//淇敼鏃ュ織鏂囦欢

3銆侀噸鍚湇鍔″苟鏌ョ湅鏃ュ織鏂囦欢

[root@localhost sbin]# systemctl restart httpd ##閲嶅惎http鏈嶅姟
[root@localhost sbin]# ls /var/log/httpd ##鏌ョ湅鏃ュ織鏂囦欢
www.kgc.com.error_20191026.log

以上是关于Apache鏃ュ織鍒嗗壊的主要内容,如果未能解决你的问题,请参考以下文章

mysql 鏃ュ織log

nginx鏃ュ織璇存槑

LINUX7(鏃ュ織绠$悊)

Postgresql鏃ュ織鏀堕泦

Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉

Linux(CentOS)浣跨敤瀹氭椂浠诲姟鍒犻櫎Tomcat鏃ュ織鏂囦欢