บางส่วนของการดำเนินชีวิต

สบาย ๆ ผูกแปลนอนใต้ต้นขี้เหล็ก ฮา

Archive for the ‘ห้องเรียน linux’ Category

Setting up an Ubuntu webcam server

leave a comment »

Sharing a webcam stream in Ubuntu is not the easiest thing, but it’s not too bad if you have some help. This tutorial will explain how to use the package webcam-server. It seems to work pretty well for me. I had to write the startup script myself, but I’m going to share that with you. To use webcam-server to it’s full potential, you should have Apache installed.

Follow up:

The first thing you will want to do is install the webcam-server package:

sudo apt-get install webcam-server

The webcam-server binary will be installed along with the java applet and html needed to host a live stream on a webpage.

Next, you will want to setup the startup script. This will allow you to control your webcam server as a daemon, and also start webcam-server at startup.

Open a new file in the /etc/init.d directory with your favorite editor. Nano is the easiest, so I’ll use that in the example:

sudo nano /etc/init.d/webcam-server

Write a starup script, or simply use this one:

#!/bin/sh

SERVER_BIN=webcam-server
LOCK_FILE=/var/lock/$SERVER_BIN
RTRN=0
OPTIONS=’-v -g 320×240 -p 8888 -c hacktivision.com’

start() {

[ -f $LOCK_FILE ] && echo “$SERVER_BIN already started”
[ -f $LOCK_FILE ] && return

echo -n “Starting $SERVER_BIN: “
export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
nohup $SERVER_BIN $OPTIONS > /dev/null 2>/dev/null &
RTRN=$?
[ $RTRN -eq 0 ] && echo Started! || echo FAIL
[ $RTRN -eq 0 ] && touch $LOCK_FILE
}

stop() {
[ -f $LOCK_FILE ] || echo “$SERVER_BIN is not running”
[ -f $LOCK_FILE ] || return
echo -n “Stopping $SERVER_BIN: “
pkill -f “$SERVER_BIN $OPTIONS”
RTRN=$?
rm -f $LOCK_FILE
[ $RTRN -eq 0 ] && echo Stopped! || echo FAIL
}

case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: $0 {start|stop|restart}”
RTRN=1
esac

exit $RTRN

Now you just need to make your startup script run when Ubuntu starts up. Use the following commands:

cd /etc/rc3.d/
sudo ln -s ../init.d/webcam-server S99webcam-server

Let’s test our webcam server now. We will start it using our script, and then see if we can view the http image stream (we will check out the video stream later).

sudo /etc/init.d/webcam-server start

Open Firefox, or any web browser and navigate to http://localhost:8888/. You should see an image of what your webcam server is pointed at. In Firefox, if you hold down CTRL+SHIFT+R, you can almost get a stream going by constantly refreshing the image.

The rest of this post requires that Apache be installed. If Apache is not installed, install it. Basically, you want to run:

sudo apt-get install apache2

When you installed webcam-server, it put some web files on your hard drive. These files allow for a java app on a webpage to stream your webcam. We will assume that your webroot is /var/www. Replace /var/www with whatever webroot you want to use in the following code.

Copy the web files to your webroot

sudo cp /usr/share/doc/webcam-server/applet/* /var/www/

and test by going to http://localhost/webcam.html.

The java applet in the webcam.html file is, by default, configured to stream at 1 frame per second. It is also configured by default to use “localhost” as the domain. Here’s an example of a webcam.html file with a maximum FPS of 60 and hosted on hacktivision.com:

WebCam

Hacktivision

You should now be all set to show your webcam stream to the world!

Please, use the comments. Let me know if you have any problems. Call out my typos and bad grammar. Link to your site and show me how you use your webcam server.

อ้างถึง http://hacktivision.com/index.php/2009/06/16/setting-up-an-ubuntu-webcam-server?blog=2

Written by อนุสรณ์ จันทสุข

มิถุนายน 18, 2009 at 4:04 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with

Booting from an AoE target

leave a comment »

Place the following two lines in /etc/dhcpd.conf:

filename “”;
option root-path “aoe:eN.M”;

where eN.M is the AoE target name that you selected for your target.

You will probably need to restart your DHCP server for the changes to take effect:

root@chipmunk# /etc/init.d/dhcpd restart

Boot your diskless client using gPXE. If all has gone well, you should see it boot from your AoE target image.

Congratulations on a successful boot from SAN!

อ้างถึง http://www.etherboot.org/wiki/sanboot/aoe_boot

Written by อนุสรณ์ จันทสุข

มิถุนายน 7, 2009 at 11:39 am

บันทึกโพสใน ห้องเรียน linux

Tagged with ,

Exporting disk images via AoE

leave a comment »

Installing the AoE initiator
You need to download and install the Windows AoE initiator (WinAoE). Download the latest WinAoE package from http://winaoe.org/ and extract the contents of the .zip file to a temporary directory.

Start up the Add Hardware Wizard (Start → Control Panel → Add Hardware) and proceed to the “Is the hardware connected?” screen:

Written by อนุสรณ์ จันทสุข

มิถุนายน 7, 2009 at 11:23 am

บันทึกโพสใน ห้องเรียน linux

Using ATA Over Ethernet On Debian Etch

leave a comment »

Imagine you have a machine with all of its disk full and another with unused gigabytes, and you don’t want to move the data from one to the other. Why not using the second’s disk on the first, you can do it with iSCSI but you can do it with ATA over Ethernet (AoE) too. It’s the second method I’ll explain in this article. All of this was made with two computers running Debian Etch.

Prepare The Kernel
First check if your running kernel has AoE, the config option name is CONFIG_ATA_OVER_ETH, have a look at fig1, my kernel has AoE as a module:

host:/# grep ATA_OVER /boot/config-`uname -r`

CONFIG_ATA_OVER_ETH=m
host:/#

If not, configure your kernel and activate AoE in core or in module like you prefer:

Device Drivers –>
|- Block Devices —>
|- ATA over Ethernet support

Ok now you have a kernel with AoE, just load the aoe module:

host:/# modprobe aoe

You can check your syslog to be sure AoE is available:

host:/#tail /var/log/syslog

Oct 10 11:54:07 host kernel: aoe: aoe_init: AoE v22 initialised.
host:/#

Now we’ll call the client ‘client’ and the server ‘server’, funny isn’t it?
In SAN vocabulary we call the client ‘initiator’ and the server ‘target’, I prefer to continue using simplest terms.

The Server Side (Target)

First we need to install the vblade package:

server:/# apt-get install vblade

Reading package lists… Done
Building dependency tree… Done
The following NEW packages will be installed:
vblade
[...]
Unpacking vblade (from …/archives/vblade_11-1_i386.deb) …
Setting up vblade (11-1) …
server:/#

On our server we’ll export the /dev/sdd5 partition which has a size of 5GB, exporting a block device is easy to do:

server:/# vbladed 0 1 eth0 /dev/sdd5

Some explanation about this command, each AoE device is identified by a couple Major/Minor, with major between 0-65535 and minor between 0-255. AoE is based just over Ethernet on the OSI models so we need to indicate which ethernet card we’ll use.

In this example we export /dev/sdd5 with a major value of 0 and minor if 1 on the eth0 interface.

We are ready to use our partition on the network!

Client Side (Initiator)
The client needs the aoe kernel module too, so prepare your kernel as we saw.
The userland tools are present in the package aoetools:

client:/# apt-get install aoetools

Now discover what we can use over our network:

client:/# aoe-discover
client:/# aoe-stat

e0.1 5.000GB eth0 up
client:/#

At this point we have a new block device available on the client box named /dev/etherd/e0.1. If we have a look at the /dev tree a new node appears:

client:/# ls -al /dev/etherd/

total 4
drwxr-xr-x 2 root root 140 2007-10-10 13:30 .
drwxr-xr-x 16 root root 14660 2007-10-10 13:30 ..
c-w–w—- 1 root disk 152, 3 2007-10-10 13:30 discover
brw-rw—- 1 root disk 152, 16 2007-10-10 13:30 e0.1
cr–r—– 1 root disk 152, 2 2007-10-10 13:30 err
c-w–w—- 1 root disk 152, 4 2007-10-10 13:30 interfaces
-rw-r–r– 1 root root 5 2007-10-10 13:00 revalidate

How To Use It
Simply make a filesystem on your block device like:

client:/# mkfs.ext3 /dev/etherd/e0.1

and use it like you do with your /dev/hd* or /dev/sd*. The only difference is that the block device is over the network!

อ้างถึง http://www.howtoforge.com/ata_over_ethernet_debian_etch

Written by อนุสรณ์ จันทสุข

มิถุนายน 7, 2009 at 10:26 am

บันทึกโพสใน ห้องเรียน linux

Tagged with , ,

AOE คืออะไรหนอ

with one comment

พยายามจะทำ thin client สำหรับโรงเรียน ใครทำ AOE UBUNTU แล้ว มี XP อยู่ด้วย ช่วยชี้แนะด้วยจ้า

http://winaoe.org

http://etherboot.org

Written by อนุสรณ์ จันทสุข

มิถุนายน 5, 2009 at 8:17 pm

วิธีแก้ปัญหาภาษาไทยกับ UTF-8

with 2 comments

เพิ่ม mysql_query(“Set names utf8″); อีกหนึ่งบรรทัดใน file ที่จะ connect database

Written by อนุสรณ์ จันทสุข

มีนาคม 2, 2009 at 3:59 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with ,

chilli.iptables

leave a comment »

#!/bin/sh
#
# Firewall script for ChilliSpot
# A Wireless LAN Access Point Controller
#
# Uses $EXTIF (eth0) as the external interface (Internet or intranet) and
# $INTIF (eth1) as the internal interface (access points).
#
#
# SUMMARY
# * All connections originating from chilli are allowed.
# * Only ssh is allowed in on external interface.
# * Nothing is allowed in on internal interface.
# * Forwarding is allowed to and from the external interface, but disallowed
# to and from the internal interface.
# * NAT is enabled on the external interface.

IPTABLES=”/sbin/iptables”
EXTIF=”eth0″
INTIF=”eth1″

#Flush all rules
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -F -t mangle

#Set default behaviour
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT

#Allow related and established on all interfaces (input)
$IPTABLES -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT

##### chalee edit
#Allow releated, established and ssh on $EXTIF. Reject everything else.
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 22 –syn -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 80 –syn -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 3306 –syn -j ACCEPT

#Allow related and established from $INTIF. Drop everything else.
$IPTABLES -A INPUT -i $INTIF -j DROP

#Allow http and https on other interfaces (input).
#This is only needed if authentication server is on same server as chilli
$IPTABLES -A INPUT -p tcp -m tcp –dport 80 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 443 –syn -j ACCEPT

####chalee edit
#Allow 3990 on other interfaces (input).
$IPTABLES -A INPUT -p tcp -m tcp –dport 3990 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 3306 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 22 –syn -j ACCEPT

#Allow ICMP echo on other interfaces (input).
$IPTABLES -A INPUT -p icmp –icmp-type echo-request -j ACCEPT

##Allow transparent proxy (wiboon 1/2)
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT

#Allow everything on loopback interface.
$IPTABLES -A INPUT -i lo -j ACCEPT

##Allow transparent proxy (wiboon 2/2)

$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.0.0/16 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 172.16.0.0/12 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128

# Drop everything to and from $INTIF (forward)
# This means that access points can only be managed from ChilliSpot
$IPTABLES -A FORWARD -i $INTIF -j DROP
$IPTABLES -A FORWARD -o $INTIF -j DROP

#Enable NAT on output device
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

# Drop package wrom Virus Input, Output (chalee1/1)
$IPTABLES -A INPUT -p tcp –dport 135 -j DROP
$IPTABLES -A INPUT -p udp –dport 135 -j DROP
$IPTABLES -A INPUT -p tcp –dport 445 -j DROP
$IPTABLES -A INPUT -p udp –dport 445 -j DROP
$IPTABLES -A INPUT -p tcp –dport 4444 -j DROP
$IPTABLES -A INPUT -p udp –dport 4444 -j DROP
$IPTABLES -A INPUT -p tcp –dport 5554 -j DROP
$IPTABLES -A INPUT -p udp –dport 5554 -j DROP
$IPTABLES -A INPUT -p tcp –dport 9996 -j DROP
$IPTABLES -A INPUT -p udp –dport 9996 -j DROP
$IPTABLES -A INPUT -p tcp –dport 137 -j DROP
$IPTABLES -A INPUT -p udp –dport 137 -j DROP
$IPTABLES -A INPUT -p tcp –dport 138 -j DROP
$IPTABLES -A INPUT -p udp –dport 138 -j DROP
$IPTABLES -A INPUT -p tcp –dport 139 -j DROP
$IPTABLES -A INPUT -p udp –dport 139 -j DROP

$IPTABLES -A OUTPUT -p tcp –dport 135 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 135 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 445 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 445 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 4444 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 4444 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 5554 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 5554 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 9996 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 9996 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 137 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 137 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 138 -j DROP
$IPTABLES -A OUTPUT -p udp –dport 138 -j DROP
$IPTABLES -A OUTPUT -p tcp –dport 139 -j DROP

อ้างถึง http://www.linuxthai.org

Written by อนุสรณ์ จันทสุข

กุมภาพันธ์ 24, 2009 at 4:01 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with

Block Bittorrent แบบ 100% โดยใช้ chilli.iptables

leave a comment »

1. #nano -w /etc/init.d/chilli.iptables
2. ให้เพิ่ม rule นี้ลงไปครับ
iptables -I INPUT -s 0.0.0.0/0 -m string –string “torrent” –algo bm -j DROP
iptables -I INPUT -s 0.0.0.0/0 -m string –string “announce” –algo bm -j DROP
iptables -I INPUT -s 0.0.0.0/0 -m string –string “info_hash” –algo bm -j DROP
3. #/etc/init.d/chilli.iptables

อ้างถึง www.linuxthai.org

Written by อนุสรณ์ จันทสุข

กุมภาพันธ์ 24, 2009 at 3:09 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with ,

Linux Terminal Server Project

leave a comment »

Ubuntu LTSP — CD installation

With the Hardy Heron (8.04.1) release the LTSP installer functionality developed in Edubuntu was moved to the Ubuntu alternate CD.

You can get the ISO from http://releases.ubuntu.com/releases/8.04.1/.

The installer will set up an out of the box working LTSP install for you if your server has two network cards built in. If that is not the case it will tell you what to modify to run with a single network card.

Once you boot up the CD, hit F4. The “Modes” menu will pop up. Select “Install an LTSP Server”. Now just move on with the install.

Towards the end of the install the installer will start to build the client environment from the packages on the CD, which then will be compressed into an image.

If the installer is done and has rebooted into your new system you will be able to boot your first Thin Client right away.

Ubuntu LTSP — Installing on an existing system

You need to set up one static network interface where you will attach the thin clients, install two packages and run one command.

Configure your spare interface for the thin clients to have the IP 192.168.0.1 (and make sure it is up and running), then follow the instructions below.

sudo apt-get install ltsp-server-standalone openssh-server

Now create your Thin Client environment on the server with:

sudo ltsp-build-client

If you are on a 64-bit system but your clients have another architecture use the –arch option e.g.

sudo ltsp-build-client –arch i386

After that, you will be able to boot your first thin client.

Note that if you want to use another IP than the above, you need to edit the /etc/ltsp/dhcpd.conf file to match the IP values and restart the DHCP server.

อ้างถึง http://www.ltsp.org/~sbalneav/LTSPManual.html#id2523360

Written by อนุสรณ์ จันทสุข

มกราคม 27, 2009 at 1:44 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with

ubuntu ไม่สามารถ mount HD ntfs ต่อนอกได้

leave a comment »

ไปที่ terminal
sudo mount -t ntfs-3g /dev/พาทิชั่น /media/disk -o force

ตัวอย่าง
sudo mount -t ntfs-3g /dev/sdb1 /media/disk -o force

Written by อนุสรณ์ จันทสุข

มกราคม 8, 2009 at 2:28 pm

บันทึกโพสใน ห้องเรียน linux

Tagged with , ,

Follow

Get every new post delivered to your Inbox.