Escolar Documentos
Profissional Documentos
Cultura Documentos
4. Select Other
5. ให้ Select Thailand โดยการกดตัว T 5 ครัง
้ นะครับ
6. Select No
7. Select Thailand
8. และ Thailand
9. Select Atl+Shift
30. ทำาการติดตัง
้ ต่อไปครับ
31. เรียบร้อยแล้วครับ เอา CD ออก Select Continue เพื่อ Restart
# nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
# dns-* options are implemented by the resolvconf package,
if installed
dns-nameservers 192.168.0.1
# apt-get -y upgrade
แก้ไข ip_forward
เราต้องทำาให้เครื่องนี้ทำาหน้ าที่เป็ นเราเตอร์เพื่อ Forward packet ทุกครัง้ ที่รบ
ี ูต
เครื่อง
ให้แก้ไขแฟ้ ม /etc/sysctl.conf
# nano /etc/sysctl.conf
ค่าที่ตอบกลับต้องได้ 1
เปิดการทำางาน TUN/TAP device
# nano /etc/modules
loop
lp
fuse
tun >>> เพิ่ม
# modprobe tun
# nano /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the
execution
# bits.
#
# By default this script does nothing.
exit 0
ติดตัง
้ chillispot เรียบร้อยแล้วครับ
เปิดการใช้งาน Chillispot
# nano /etc/default/chillispot
# /etc/default/chillispot
#
# Enable on system start?
# Change to 1 if you want it to be enabled.
# Please make sure you have configured chillispot first.
ENABLED=0 >>> แก้ให้เป็ น ENABLED=1
#
# chillispot default configuration
CHILLICFG=/etc/chilli.conf
#
# daemon arguments
DAEMON_ARGS="--conf $CHILLICFG"
# nano /etc/chilli.conf
# cp /usr/share/doc/chillispot/firewall.iptables
/etc/init.d/chilli.iptables
# chmod a+x /etc/init.d/chilli.iptables
# ln -s ../init.d/chilli.iptables /etc/rcS.d/S41chilli.iptables
# /etc/init.d/chilli.iptables
# /etc/init.d/chillispot restart
แก้ไข File chilli.iptables เพื่อ SSH เข้าทาง eth1 ได้
# nano /etc/init.d/chilli.iptables
EXTIF="eth0"
INTIF="eth1"
# /etc/init.d/chilli.iptables
# /etc/init.d/chillispot restart
ChilliSpot Start เรียบร้อยแล้ว ย้าย Notebook มาต่อกับ Network
วง etc1 ได้ IP Address จาก Server แล้ว
Restart Apache
# /etc/init.d/apache2 restart
สร้าง Database freeradius
# nano /etc/freeradius/sql.conf
sql {
# Database type
# Current supported are: rlm_sql_mysql, rlm_sql_postgresql,
# rlm_sql_iodbc, rlm_sql_oracle, rlm_sql_unixodbc,
rlm_sql_freetds
driver = "rlm_sql_mysql"
# Connect info
server = "localhost"
login = "root"
password = "rootpass" >>> แก้ให้เป็ น Password root ของเรา
# Database table configuration
radius_db = "radius"
# nano /etc/freeradius/clients.conf
# nano /etc/freeradius/users
#
#"John Doe" Cleartext-Password := "hello"
# Reply-Message = "Hello, %u"
#
# Dial user back and telnet to the default host for that port
#
# reboot
# /etc/init.d/freeradius stop
# freeradius -XXX -A
# /etc/init.d/freeradius start
# nano /etc/freeradius/radiusd.conf
#
# Look in an SQL database. The schema of the database
# is meant to mirror the "users" file.
#
# See "Authorization Queries" in sql.conf
# sql >>> แก้ไห้เป็ น sql (# เอาออก)
# /etc/init.d/freeradius restart
# nano /etc/freeradius/sql.conf
#
# Set to 'yes' to read radius clients from the database ('nas'
table)
#readclients = yes >>> แก้ไห้เป็ น readclients = yes (# เอา
ออก)
}
# nano /etc/freeradius/radiusd.conf
#
# Instead of sending the query to the SQL server,
# write it into a log file.
#
# Instead of sending the query to the SQL server,
# write it into a log file.
# /etc/init.d/freeradius restart
สร้าง Certificate
สร้าง Certificate
# /etc/init.d/apache2 force-reload
สร้าง virtualhost ไว้ Link SSL
# nano /etc/apache2/sites-available/hotspot
# /etc/init.d/apache2 reload
Open Port
# nano /etc/apache2/ports.conf
#Listen 80
#
#<IfModule mod_ssl.c>
# Listen 443
#</IfModule>
Listen 192.168.3.1:80 >>> แก้ให้เป็ น IP eth1 ของ Server
Listen 192.168.3.1:443 >>> แก้ให้เป็ น IP eth1 ของ Server
# nano /etc/apache2/sites-available/default
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
127.0.0.1 localhost
192.168.0.100 THAIEN-HOTSPOT >>> แก้ให้เป็ น 192.168.3.1
THAIEN-HOTSPOT
Restart Apache
# /etc/init.d/apache2 restart
Restart Apache
# /etc/init.d/apache2 restart
ติดตัง
้ ezradius
Upload Floder manage จาก โปรแกรมที่ใช้ในการทำา\web\ ไปที่ /var/www/
การเพิม
่ group
ก่อนที่เราจะทำาการเริ่มเพิ่ม group เพื่อแยกการใช้งานของ user ออกเป็ นกลุ่ม
งาน เช่น อาจารย์ , นักเรียน เราต้องมาทำาความรู้จักกับ Attribute ของ radius
ก่อนซึ่งจะทำาหน้าที่ในการ ควบคุมการใช้งานต่าง ๆ ของระบบของเรานะครับ เรา
จะได้ปรับแต่งการใช้งานได้ตามความเหมาะ อย่างเช่น อาจจะอนุญาตให้อาจารย์
หรือหัวหน้างานมีค่าการ download/upload มากกว่านักเรียนหรือผู้ใช้งานทั่วไป
เอาล่ะเรามาดูความหมายของ Attribute ที่จะนำามาใช้งานกันดีกว่านะครับ
ให้เลือกตามรูปเลยนะครับ
Attribute : Simultaneous-Use คือการ login ซ้อนกันในที่น่ี เราไม่อนุญาตให้
กล่มุ นี้ Logig ซ้อนกันนะครับ ดังนั้นให้ค่า
Perator : :=และ Value : 1 (หากต้องการซ้อนกันได้ให้ Value : 0)
จะได้ดังรูป
เพิม
่ /แก้ไข user ไม่ต้องเลือก Cleartext password
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# TAG: macsuffix
# Suffix to add to MAC address in order to form the username.
# Normally you do not need to uncomment this tag.
#macsuffix suffix
# /etc/init.d/chillispot restart
จะได้รายละเอียด ดังรูป
การติดตัง
้ Transparent Proxy
เริ่มต้นติดตั้ง squid สำาหรับทำาหน้าที่เก็บ cache และ sarg ไว้รายงานการใช้
งานผ่านหน้าเว็บ
# nano /etc/squid/squid.conf
โดยให้แก้ไขดังนี้
http_port 3128
#cache_mem 8 MB
#cache_dir ufs /var/spool/squid 100 16 256
#acl our_networks src 192.168.2.0/24
#http_access allow our_networks
access.log /path/access.log squid
#emulate_httpd_log off
# /etc/init.d/squid restart
จากนั้นมาทำาให้ user เข้าใช้งาน proxy นะครับโดยไปแก้ไขที่ไฟล์
chilli.iptables
# nano /etc/init.d/chilli.iptables
>>> เพิ่มเข้าไป
#Allow Tranparent proxy
$IPTABLES -A INPUT -p tcp -m tcp --dport 3128 --syn -j ACCEPT
>>> เพิ่มเข้าไป
#Allow Tranparent proxy
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 3128 --syn -j
DROP
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 192.168.3.0/16 --dport
80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 80 -j REDIRECT
--to-ports 3128
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 88 -j REDIRECT
--to-ports 3128
# nano /etc/init.d/chilli.iptables
# nano /etc/squid/squid.conf
# /etc/init.d/squid restart
# tail /var/log/squid/access.log -f
Ctrl+c ออก
# sarg
จากนั้นก็สามารถเข้าดูรายงานการใช้เว็บได้เลยครับโดยดูจาก IE ได้เลข
โดยพิมพ์ว่า http://192.168.3.1/squid-reports
ตัง
้ เวลาให้ sarg ทำางานผ่าน crontab
# nano /etc/crontab
# nano /etc/logrotate.d/squid
/var/log/squid/access.log {
daily
compress
delaycompress
rotate 2
missingok
nocreate
sharedscripts
# prerotate
# test ! -x /usr/sbin/sarg-maint || /usr/sbin/sarg-maint
# endscript
# postrotate
# test ! -e /var/run/squid.pid || /usr/sbin/squid -k rotate
# endscript
}
>>> แก้เป็ น
/var/log/squid/access.log /var/log/squid/store.log {
daily
compress
# delaycompress
rotate 1
missingok
nocreate
sharedscripts
# prerotate
# test ! -x /usr/sbin/sarg-maint || /usr/sbin/sarg-maint
# endscript
# postrotate
# test ! -e /var/run/squid.pid || /usr/sbin/squid -k rotate
# endscript
}
>>> เพิ่ม
/var/log/squid/cache.log {
weekly
compress
rotate 2
missingok
nocreate
sharedscripts
}
# nano /etc/freeradius/radiusd.conf
detailfile = ${radacctdir}/%{Client-IP-Address}/detail-%Y%m%d
>>> แก้ไห้เป็ น
detailfile = ${radacctdir}/%{Client-IP-Address}/details
# nano /etc/logrotate.d/freeradius
/var/log/freeradius/*.log {
weekly
rotate 52
compress
notifempty
}
>>> แก้เป็ น
/var/log/freeradius/radacct/127.0.0.1/details {
daily
compress
rotate 1
missingok
notifempty
}
# /etc/init.d/freeradius restart
# /etc/cron.daily/logrotate
ในทีน่ ้ี ผมได้สร้าง folder /home/LOG ไว้แล้วนะครับ ใครทีย
่ ังสร้างไม่
เป็ น ก็สร้างตามนี้ เลย
# mkdir /home/LOG
# nano /home/changeaccess.sh
#!/bin/sh
timeaccess=`date +%Y-%m-%d`
cp /var/log/squid/access.log.1.gz /home/LOG/$timeaccess-
access.log.gz
cp /var/log/squid/store.log.1.gz /home/LOG/$timeaccess-
store.log.gz
cp /var/log/freeradius/radacct/127.0.0.1/details.1.gz /home/LOG/
$timeaccess-freeradius.log.gz
# chmod +x /home/changeaccess.sh
เวลาจะเรียกใช้
# cd /home
# ./changeaccess.sh
ตัง
้ เวลาให้ logrotate ทำางานผ่าน crontab
# nano /etc/crontab
TIP ก่อนจบคอร์ส
แก้ไขปั ญหา session ค้าง
ท่านจะนำาไปสร้าง shell scrip ไว้สำาหรับสะดวกในการใช้งานก็ได้นะครับ
# nano /home/clearlog.sh
rm /var/log/freeradius/radutmp
rm /var/log/freeradius/radwtmp
touch /var/log/freeradius/radutmp
touch /var/log/freeradius/radwtmp
chown freerad:freerad /var/log/freeradius/radutmp
chown freerad:freerad /var/log/freeradius/radwtmp
แก้ permittion
เวลาใช้งาน
# cd /home
# ./clearlog.sh
# mii-tool
# du –sh /var/spool/squid
ติดตัง
้ bandwidthd แทน sarg ใน ubuntu
Restart Apache
# /etc/init.d/apache2 restart
# nano /etc/bandwidthd/bandwidthd.conf
meta_refresh 150
เสร็จแล้วสัง่ ให้ทำางาน
# bandwidthd
# /etc/init.d/bandwidthd restart
ดูผลหน้าเวบเลยครับ http://192.168.3.1/bandwidthd
ตัง
้ crontab ให้ bandwidthd อัพเดทข้อมูลทุกวันตอน เทียงคืน 5 นาที
# nano /etc/crontab
#
#sarg squid report
00 * * * root /usr/bin/sarg
#bandwidthd
50 * * * root /usr/bin/bandwidt
#Shut Down
10 0 * * * root shutdown -h now
ติดตัง
้ syslog-ng
# apt-get -y install syslog-ng
# cd /tmp/
# wget http://downloads.sourceforge.net/phpsyslogviewer/phpsyslogviewer-
7.2.1.tar.bz2
ติดตัง
้ โปรแกรม bzip2 ด้วยคำาสัง่ ยังอยู่ใน /tmp/ นะครับ
# apt-get install bzip2
ดาวน์โหลดโปรแกรม speedupd
1. เปลี่ยนไดเร็กทอรี่ไปยังโฟลเดอร์ phpsyslogviwer-7.2.1
# cd phpsyslogviewer-7.2.1
mysql> exit;
5. สร้างตารางข้อมูลด้วยการใช้ script จากไฟล์ install/phpsyslogviewer.
sql ด้วยคำาสั่ง
# nano install/newuser.sql.php
// 02110-1301, USA.
// -------------------------------------------------------------------
// -------------------------------------------------------------------
Save แล้ว Exit ได้เลย
# php install/newuser.sql.php
จัดการเว็บไดเรคทอรีเพื่อให้สามารถเรียกดูข้อมูลผ่านเวบบราวเซอร์ได้ ด้วยการ
สำาเนาไฟล์ ด้วยคำาสั่งดังนี้
# cp -R htdocs /var/www/phpsyslogviewer
แก้ไขไฟล์คอนฟิ กคือ /var/www/phpsyslogviewer/config.php เพื่อกำาหนด
ค่าที่สำาคัญเกี่ยวกับฐานข้อมูลดังนี้
# nano /var/www/phpsyslogviewer/config.php
>>> แก้เป็ น
รันคำาสัง่ ต่อไปนี้
# chown root:www-data /var/www/phpsyslogviewer/config.php
# dpkg-buildpackage –rfakeroot
ตอนนี้ เราจะได้แพ็คเกจตระกูล debian ชื่อว่า speedupd_7.3.0_i386.deb
(สำาหรับ 64 bit OS จะชื่อ speedupd_7.3.0_amd64.deb) ให้ตด ิ ตั้งแพ็คเกจ
และกำาหนดค่าให้กับไฟล์ speedupd.conf ดังนี้
# cd ..
# ls
# dpkg -i speedupd_7.3.0_i386.deb
dbusername = syslog
dbpassword = syslog
dbhostname = localhost
dbdatabase = syslog
>>> แก้เป็ น
dbusername = root
dbpassword = mysqlroot
dbhostname = localhost
dbdatabase = syslogng
Start Speedupd
# /etc/init.d/speedupd start
# nano /etc/syslog-ng/syslog-ng.conf
***options
options {
recv_time_zone (+07:00);
send_time_zone (+07:00);
sync (0);
time_reopen (100);
log_fifo_size (1000);
long_hostnames (off);
use_dns (no);
use_fqdn (no);
create_dirs (yes);
chain_hostnames(yes);
keep_hostname (yes);
};
***source
source s_sys {
file ("/proc/kmsg" log_prefix("kernel: "));
unix-stream ("/dev/log");
internal();
udp(ip(0.0.0.0) port(514));
tcp(ip(0.0.0.0) port(514) keep-alive(yes));
};
***destination
destination d_mysql {pipe("/var/log/mysql.pipe" template("INSERT
INTO logs (host, facility, priority, level, tag, datetime, program, msg)
VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$LEVEL', '$TAG',
'$YEAR-$MONTH-$DAY $HOUR:$MIN:$SEC', '$PROGRAM',
'$MSG' );\n") template-escape(yes));
};
***filter
filter f_kernel { facility (kern); };
filter f_messages { level(info..emerg) and not (facility(mail) or
facility(authpriv) or facility(cron)); };
***log
log {source(s_sys); filter(f_messages); destination(d_mysql); };
log {source(s_sys); filter(f_kernel); destination(d_mysql); };
สร้างสคริปเพื่อทำาไปน์สำาหรับส่งค่าสตรีมจากไปน์สู่ฐานข้อมูล งานนี้
เป็ น bash สคริปครับ ฟั งดูวุ่นวายแต่ทำาจริงง่ายมากครับ ให้
สร้าง script file ด้วยคำาสัง่ ต่อไปนี้
# nano syslog2mysql.sh
#!/bin/bash
if [ ! -e /var/log/mysql.pipe ]
then
mkfifo /var/log/mysql.pipe
fi
while [ -e /var/log/mysql.pipe ]
do
mysql -u root --password=radius syslogng < /var/log/mysql.pipe
>/dev/null
done
ทำาการเปลีย
่ นสิทธิไฟล์ แล้วรันคำาสัง่ ต่อไปนี้
# chmod +x syslog2mysql.sh
# ./syslog2mysql.sh &
# /etc/init.d/syslog-ng start
****หมายเหตุ****
จากการติดตัง
้ phpsyslogviewer แล้ว phpsyslogviewer มีแต้ log
Start,stop ของ Syslog-ng เท่านัน
้
จากนัน
้ ทำาการส่งค่าจาก radiusd ไปยัง syslog ดัง
้ นี้
การตัง
้ ค่าให้ส่งข้อมูลการจราจรคอมพิวเตอร์ จาก squid และ radius
โดยให้ทำางานทุกครัง ้ หลังเปิดเครื่องดัง
้ นี้
# nano /etc/init.d/rc.capture
#!/bin/bash
tail -F /var/log/squid/access.log | logger -t squid -p user.info &
tail -F /var/log/freeradius/radacct/127.0.0.1/details | logger -t
radiusd -p user.info &
# ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
สัง่ ให้ rc.capture ทำางาน
# /etc/init.d/rc.capture
ตรวจสอบ syslog
# tail -f /var/log/syslog
ทดลองใช้งาน Internet
ติดตัง
้ webmin
# cd /var
# cd webmin-1.480
# sh setup.sh
การทำางานของ Samba จะทำางานอยู่บน Port 137,138 และ 139
* 138 Datagram Service : SMB จะใช้ port นี้ ในการ Browse หาชื่อเครื่อง
# nano /etc/init.d/chilli.iptables
ขอแสดงความนับถือ
วิสุทธิ ์ การะเกตุ