Kusprayitna Blogs

Hidup untuk berbagi ilmu :: IT Linux Windows Database Oracle PHP OpenSource

Menambah kemampuan cPanel apache log ke server log terpusat

Posted by kusprayitna on July 4th, 2012

cPanel merupakan paket hosting yang mumpuni dan alhamdulilah sekitar 150 domain terdaftar dalam server di cPanel yang terpakai dikantor sekarang ini.

Untuk memonitor file log apache satu-persatu cukuplah membuat pusing kepala, dengan sudah tersedianya server log yang terpusat seperti dalam postingan mengelola log server dalam cluster secara terpusat, maka tahapan berikutnya adalah memasukkan cPanel ke server log terpusat.

Kalau kita lihat konfigurasi virtual host cpanel, maka dapat kita lihat sebagai berikut :

    ServerName cfis.uii.ac.id
    ServerAlias www.cfis.uii.ac.id
    DocumentRoot /home/cfisuii/public_html
    ServerAdmin webmaster@cfis.uii.ac.id
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/cfis.uii.ac.id combined
    CustomLog /usr/local/apache/domlogs/cfis.uii.ac.id-bytes_log "%{%s}t %I .\n%{%s}t %O ."
Untuk tidak merubah fitur cPanel yang sudah ada, maka kita tidak boleh mematikan fungsi log yang sebelumnya ada, jadi menambah log baru saja.
Karena virtual host cukup banyak, maka diperlukan merubah satu saja, yaitu pada file template virtual host cpanel, yaitu yang terletak di "/var/cpanel/templates/apache2"
Tahapan yang dilakukan yaitu :
1. Sesuaikan konfigurasi rsyslog
Alhamdulillah cpanel sudah menggunakan rsyslog, sehingga tidak perlu intall dahulu.
# vi /etc/rsyslog
....
tambahkan
# Apache log
local6.*                                                @192.168.0.1
....
2. Amankan file default template yang sudah ada, dan buat local template
# cd /var/cpanel/templates/apache2
# cp vhost.default vhost.local
Tujuan dari mengamankan ini adalah apabila terjadi kesalahan perubahan template maka akan bisa dikembalikan ke template default dan cpanel sudah didisain jika ada file *.local maka akan di pakai terlebih dulu dan jika gagal akan dipakai *.default
3. Tambahkan perintah menulis log ke server log
Penambahan ada di template yang berwarna biru
# vi vhost.local
<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %]>
    ServerName [% vhost.servername %]
[% IF vhost.serveralias_array.size -%]
[% FOREACH alias IN vhost.serveralias_array -%]
    ServerAlias [% alias %]
[% END -%]
[% ELSE -%]
    ServerAlias [% vhost.serveralias %]
[% END -%]
    DocumentRoot [% vhost.documentroot %]
[% IF vhost.serveradmin -%]
    ServerAdmin [% vhost.serveradmin %]
[% ELSE %]
    ServerAdmin webmaster@[% vhost.servername %]
[% END -%]
[% IF vhost.usecanonicalname -%]
    UseCanonicalName [% vhost.usecanonicalname %]
[% ELSE %]
    UseCanonicalName Off
[% END -%]
[% IF !vhost.hascgi -%]
        Options -ExecCGI -Includes
        RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
[% END -%]
[% IF logstyle == 'combined' -%]
    [%- IF !enable_piped_logs || !supported.mod_log_config -%]
    CustomLog [% serverroot %]/domlogs/[% vhost.log_servername %] combined
    [%- END %]
[% ELSE %]
    TransferLog [% serverroot %]/domlogs/[% vhost.log_servername %]
[% END -%]
[% IF supported.mod_log_config && supported.mod_logio && !enable_piped_logs -%]
    CustomLog [% serverroot %]/domlogs/[% vhost.log_servername %]-bytes_log "%{%s}t %I .\n%{%s}t %O ."
[% END -%]
    ## Send Log to Log Server
    CustomLog "|/usr/bin/logger -t cpanel.[% vhost.user %] -p local6.info" combined
    ErrorLog "|/usr/bin/logger -t cpanel.[% vhost.user %] -p local6.err"
    ## User [% vhost.user %] # Needed for Cpanel::ApacheConf
[% IF supported.mod_userdir && userdirprotect_enabled && vhost.userdirprotect != '-1' -%]
    UserDir disabled
    UserDir enabled [% vhost.user %] [% vhost.userdirprotect %]
[% END -%]
[% IF supported.mod_suphp -%]
    <IfModule mod_suphp.c>
        suPHP_UserGroup [% vhost.user %] [% vhost.group %]
    </IfModule>
[% END -%]
[% IF phpopenbasedirprotect_enabled && vhost.phpopenbasedirprotect && ( supported.libphp4 || supported.libphp5 ) -%]
    <IfModule concurrent_php.c>
        php4_admin_value open_basedir "[% vhost.homedir %]:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
        php5_admin_value open_basedir "[% vhost.homedir %]:/usr/lib/php:/usr/local/lib/php:/tmp"
    </IfModule>
    <IfModule !concurrent_php.c>
        <IfModule mod_php4.c>
            php_admin_value open_basedir "[% vhost.homedir %]:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
        </IfModule>
        <IfModule mod_php5.c>
            php_admin_value open_basedir "[% vhost.homedir %]:/usr/lib/php:/usr/local/lib/php:/tmp"
        </IfModule>
        <IfModule sapi_apache2.c>
            php_admin_value open_basedir "[% vhost.homedir %]:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp"
        </IfModule>
    </IfModule>
[% END -%]
[% IF vhost.user != 'nobody' -%]
    <IfModule !mod_disable_suexec.c>
        <IfModule !mod_ruid2.c>
            SuexecUserGroup [% vhost.user %] [% vhost.group %]
        </IfModule>
    </IfModule>
    <IfModule mod_ruid2.c>
        RUidGid [% vhost.user %] [% vhost.group %]
    </IfModule>
[% END -%]
[% IF supported.mod_alias -%]
[% IF vhost.hascgi && scriptalias == 1 -%]
    ScriptAlias /cgi-bin/ [% vhost.documentroot %]/cgi-bin/
[% END -%]
[% END -%]
[%- added_include = 0 %]
[%- IF file_test('d', '/usr/local/apache/conf/userdata/') %]
    [%- IF fglob('/usr/local/apache/conf/userdata/*.conf') %]
        [%- added_include = 1 %]
    Include "/usr/local/apache/conf/userdata/*.conf"
    [%- END %]
    [%- IF vhost.owner && fglob('/usr/local/apache/conf/userdata/*.owner-' _ vhost.owner) %]
        [%- added_include = 1 %]
    Include "/usr/local/apache/conf/userdata/*.owner-[% vhost.owner %]"
    [%- END %]
    [%- IF file_test('d', '/usr/local/apache/conf/userdata/std') %]
        [%- IF fglob('/usr/local/apache/conf/userdata/std/*.conf') %]
            [%- added_include = 1 %]
    Include "/usr/local/apache/conf/userdata/std/*.conf"
        [%- END %]
        [%- IF vhost.owner && fglob('/usr/local/apache/conf/userdata/std/*.owner-' _ vhost.owner) %]
            [%- added_include = 1 %]
    Include "/usr/local/apache/conf/userdata/std/*.owner-[% vhost.owner %]"
        [%- END %]
        [%- SET vhost_include_base = '/usr/local/apache/conf/userdata/std/2/' %]
        [%- IF file_test('d',vhost_include_base) %]
            [%- IF fglob(vhost_include_base _ '*.conf') %]
                [%- added_include = 1 %]
    Include "[% vhost_include_base %]*.conf"
            [%- END %]
            [%- IF vhost.owner && fglob(vhost_include_base _ '*.owner-' _ vhost.owner) %]
                [%- added_include = 1 %]
    Include "[% vhost_include_base %]*.owner-[% vhost.owner %]"
            [%- END %]
            [%- IF file_test('d',vhost_include_base _ vhost.user) %]
                [%- IF fglob(vhost_include_base _ vhost.user _ '/*.conf') %]
                    [%- added_include = 1 %]
    Include "[% vhost_include_base %][% vhost.user %]/*.conf"
                [%- END %]
                [%- domains_list = vhost.serveralias.split(' ') %]
                [%- domains_list.push(vhost.servername) %]
                [%- FOREACH domain IN domains_list.unique() %]
                    [%- domain = wildcard_safe(domain) %]
                    [%- IF file_test('d',vhost_include_base _ vhost.user _ '/' _  domain) %]
                        [%- IF fglob(vhost_include_base _ vhost.user _ '/' _ domain _ '/*.conf') %]
                            [%- added_include = 1 %]
    Include "[% vhost_include_base %][% vhost.user %]/[% domain %]/*.conf"
                        [%- END %]
                    [%- END %]
                [%- END %]
            [%- END %]
        [%- END %]
    [%- END %]
[%- END %]
[%- IF !added_include %]
    [%- SET vhost_include_base = '/usr/local/apache/conf/userdata/std/2/' %]
    [%- domain = wildcard_safe(vhost.servername) %]

    # To customize this VirtualHost use an include file at the following location
    # Include "[% vhost_include_base %][% vhost.user %]/[% domain %]/*.conf"
[%- END %]

</VirtualHost>
4. Rubah semua konfigurasi file /etc/httpd/conf/httpd.conf berdasar file template baru
# /scripts/rebuildhttpdconf
5. Restart rsyslog dan  apache
# service rsyslog restart
# service httpd restart
Dan langkah terakhir jangan lupa melihathasilnya .....
dan alhamdulillah berkat izin Allah langsung berhasil ....

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>