Jumat, 11 Februari 2011

Setup MRTG Squid on Ubuntu 10.10

Install MRTG, Apache2, Squid and SNMP
$ sudo apt-get install apache2 snmpd mrtg snmp-mibs-downloader squid

Configure SNMP

Backup /etc/snmp/snmpd.conf
$ sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

Create new /etc/snmp/snmpd.conf
$ sudo nano /etc/snmp/snmpd.conf

and key in these lines:
rocommunity  public
syslocation  "Bukit Batok"
syscontact  xxxxxx@yahoo.com
com2sec public localhost public
group public v1 public
group public v2c public
group public usm public
view all included .1
access public "" any noauth exact all none none

Edit /etc/default/snmpd:
$ sudo nano /etc/default/snmpd

and make sure it contains these lines:
SNMPDRUN=yes
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
SNMPDCOMPAT=yes


Configure Squid

Edit /etc/squid/squid.conf
$ sudo nano /etc/squid/squid.conf

and make sure these lines exist:
snmp_port 3401
acl snmppublic snmp_community public
snmp_access allow snmppublic all

Restart Squid:
$ sudo /usr/sbin/squid -k reconfigure


Configure MRTG

Create configuration file:
$ sudo cfgmaker --global 'WorkDir:/var/www/mrtg' --ifref=name --ifdesc=eth --global 'Options[_]: bits' --output /etc/mrtg.cfg  --snmp-options=:::::1 public@localhost

Edit /etc/mrtg.cfg and make sure these lines exist:
### Global Config Options
WorkDir: /var/www/mrtg
RunAsDaemon: yes
EnableIPv6: no
Options[_]: bits
LoadMIBS: /usr/share/snmp/mibs/SQUID.txt
### Squid Config
Target[proxy-hit]: cacheHttpHits&cacheServerRequests:public@localhost:3401
# If you are using Squid 2.6 or later, uncomment the following line
RouterName[proxy-hit]: cacheUniqName
MaxBytes[proxy-hit]: 100000
Title[proxy-hit]: HTTP Hits
PageTop[proxy-hit]: <H1>proxy Cache Statistics: HTTP Hits/Requests</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>saniya</TD></TR>
   <TR><TD>Maintainer:</TD><TD>kumkum</TD></TR>
   <TR><TD>Description:</TD><TD>Squid Proxy server</TD></TR>
 </TABLE>
Suppress[proxy-hit]: y
LegendI[proxy-hit]:  HTTP hits
LegendO[proxy-hit]:  HTTP requests
Legend1[proxy-hit]:  HTTP hits
Legend2[proxy-hit]:  HTTP requests
YLegend[proxy-hit]: perminute
ShortLegend[proxy-hit]: req/min
Options[proxy-hit]: nopercent, perminute, dorelpercent, unknaszero

Target[proxy-srvkbinout]: cacheServerInKb&cacheServerOutKb:public@localhost:3401
# If you are using Squid 2.6 or later, uncomment the following line
RouterName[proxy-srvkbinout]: cacheUniqName
MaxBytes[proxy-srvkbinout]: 76800
Title[proxy-srvkbinout]: Cache Server Traffic In/Out
PageTop[proxy-srvkbinout]: <H1>Cache Statistics: Server traffic volume (In/Out)</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>saniya</TD></TR>
   <TR><TD>Maintainer:</TD><TD>kumkum</TD></TR>
   <TR><TD>Description:</TD><TD>Squid Proxy server</TD></TR>
 </TABLE>
Suppress[proxy-srvkbinout]: y
LegendI[proxy-srvkbinout]:  Traffic In
LegendO[proxy-srvkbinout]:  Traffic Out
Legend1[proxy-srvkbinout]:  Traffic In
Legend2[proxy-srvkbinout]:  Traffic Out
YLegend[proxy-srvkbinout]: per minute
ShortLegend[proxy-srvkbinout]: b/min
kMG[proxy-srvkbinout]: k,M,G,T
kilo[proxy-srvkbinout]: 1024
Options[proxy-srvkbinout]: nopercent, perminute, unknaszero

Create MRTG index file:
$ sudo indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

Execute MRTG:
$ env LANG=C /usr/bin/mrtg /etc/mrtg.cfg

MRTG will default graph the data every 5 minutes.
To change this interval into 10 minutes, add this line into mrtg.cfg:
Interval : 10

To view MRTG graphs, go to http://localhost/mrtg/

Rabu, 09 Februari 2011

Notes: Setup Ubuntu Web Hosting

This is my little note on web hosting setup.

- Install Ubuntu Server 10.10
- Setup static private IP address
- Install ehcp hosting control panel: ehcp.net
- Configure ehcp: add domain, add ftp user, modify ehcp dns template, modify external IP
- Upload website source code
- Import website database
- Install smbfs: apt-get install smbfs
- Create samba script
- Check .htaccess
- Check dl.php to follow .htaccess path
- Change file upload setting in php.ini:  upload_max_filesize = 200M
- Change file upload setting in php.ini:  post_max_size = 200M

- Setup cronjob

Samba Shell Script

Below is shell script to load Windows' folder share using Ubuntu 10.10:
--
#!/bin/bash
umount /var/www/vhosts/saniya/id-ebook.com/httpdocs/gudang
umount /var/www/vhosts/saniya/id-ebook.com/httpdocs/gudang2
mount.cifs \\\\ubuntu-pc\\z\\gudang /var/www/vhosts/saniya/id-ebook.com/httpdocs/gudang -o uid=www-data,gid=0,user=ubuntu,pass=xxx,rw
mount.cifs \\\\ubuntu-pc\\z\\gudang2 /var/www/vhosts/saniya/id-ebook.com/httpdocs/gudang2 -o uid=www-data,gid=0,user=ubuntu,pass=xxx,rw