วันอังคารที่ 18 ธันวาคม พ.ศ. 2555

การทำ Radio Online โดยใช้ CentOS ร่วมกับ SHOUTcast

เริ่มติดตั้ง SHOUTcast โดยโหลดจาก http://yubase.net/depo/  เป็นเวอร์ชั่น sc_serv_1.9.8_Linux.tar.gz
** ลืมบอกไป ผมทำผ่าน  windows น่ะครับ โดยใช้โปรแกรม SSHSecureShellClient   เป็นโปรแกรมเข้าไปทำงานบน server โหลดได้จาก http://www.filewatcher.com/m/SSHSecureShellClient-3.2.9.exe.5517312.0.0.html   เมื่อโหลดมาเก็บไว้ในเครื่องแล้ว ก็ทำการติดตั้งได้เลย  เมื่อติดตั้งเสร็จแล้วโปรแกรมจะมีอยู่ 2 ส่วนน่ะครับ คือ 1. ssh แบบ file transfer   เอาไว้สำหรับโยนไฟล์เข้า  server   2. ssh แบบ เขียนคำสั่งบน server  ขั้นตอนจะมีอยู่2 ขั้นตอนน่ะครับ คือ
1.สร้างโฟลเดอร์ใน Server โดยใช้ ssh shell client
    # cd  /var
 ทำการสร้างโฟลเดอร์ไว้สำหรับเก็บไฟล์ shoutcast  โดยตัวอย่างจะสร้างโฟลเดอร์ชื่อ radio
 # mkdir    radio
 นำไฟล์ shoutcast  ไปไว้ในโฟล์เดอร์ที่สร้างไว้ โดยใช้ ssh file transfer  โฟลเดอร์ที่วางจะอยู่ที่ี var/radio ที่ได้ทำการสร้าง นำไฟล์ sc_serv_1.9.8_Linux.tar.gz  ไปวางได้เลย
ทำการแตกไฟล์ ด้วยคำสั่ง
 # tar svfz sc_serv_1.9.8_Linux.tar.gz  กด Enter
จะได้ไฟล์  3 ไฟล์
- sc_serv   สำหรับ run radio online
- sc_serv.conf สำหรับ config ค่าต่างๆ
- readme.txt คือรายละเอียดโปรแกรม

เริ่มโดยการเปลี่ยนค่า ในไฟล์ config กันเลย
# vim     sc_serv.conf    แก้ไขค่าดังนี้  * เมื่อต้องการแก้ไข ให้กด i ก่อนน่ะครับ
1. MaxUser = 20 (จำนวนผู้ฟังที่ต้องการ)
2. PassWord = 123456789 ( รหัสเข้าไปตั้งค่า)
3. PortBase = 8000 (port ที่ใช้งานน่ะครับ)
4. AdminPassword =123456789 (อย่าลืมเอา ; ออกด้วยน่ะครับ)
จากนั้นก้อ save โดยกด Esc  :wq   เพื่อทำการบันทึก
มากำหนดสิทธิ์ให้กับโฟลเดอร์ เป็น 775
# chmod 775 -R /var/radio      Enter   เริ่มสั่ง start ได้แลย
# ./sc_serv      Enter

เป็นอันเสร็จการตั้งค่าที่ server แล้ว
ส่วนที่2 เป็นการตั้งค่ากับเครื่องที่ใช้ส่งสัญญาณเข้า radio server
โดยเริ่มจาก ติดตั้ง winamp  แล้วทำการโหดล SHOUTcast DSP Plug-In for Winamp
จากเว็บ http://www.shoutcast.com/broadcast-tools  แล้วทำการติดตั้ง ได้เลย  หลังจากที่ติดตั้ง plug in เรียบร้อยแล้ว เข้าไปที่หน้า Preference ของ winamp >> Options >> Preference เลือกหัวข้อ DSP/Effect

หน้าต่างด้านขวาจะแสดง DSP ให้เลือก Nullsoft SHOUTcast DSP v.1.9.0 จากนั้น จะมีหน้าต่างให้ตั้งค่า ของ Nullsoft SHOUTcast DSP v.1.9.0 จะมีอยู่ด้วยกัน 4 tab Output


- ในช่อง Adress  ให้ใส่ไอพีของ server radio
- Port ใส่ port ที่ตั้งค่า ไว้มน server
- Password  ให้ใส่ password ที่ตั่งค่าไว้ใน server

จากนั้น คลิกที่ tab Encode

มีให้เลือกอยู่ 2 เมนูน่ะครับ
Encoder Type เลือกเป็น MP3 Encoder
Encoder Setting  เป็นการตั้งค่าความละเอียดเสียงน่ะครับ 

จากนั้นก็ tab สุดท้ายน่ะครับ 

- ในช่อง Input Device ให้เลือก Soundcard Input
- ในช่อง Inputting  ก็ให้เป็นค่า default ของโปรแกรมน่ะครับ

จากนั้นก็คลิกที่ tab แรกอีกครั้ง แล้วกด Connect ได้เลยครับ

ส่วนการฟังผ่านหน้าเว็บก้อให้นำโค้ดไปวางใน server radio online แล้วเซฟเป็น .html น่ะครับ

<object id="MediaPlayer2" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="247" height="65" type="application/x-oleobject">
<param value="http://ไอพีserver:8000/" name="URL"/>
<param value="True" name="autoStart"/>
<embed pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" autorewind="True" showstatusbar="true" type="application/x-mplayer2" height="65" src="http://ไอพีserver:8000/" showdisplay="False" width="247" showcontrols="True"></embed>
</object>

ใครใช้ Centos ก็ให้เอาไปวางไว้ที่ /var/www/html น่ะครับ    ส่วนการทดสอบรับฟังก็เข้าไปที่ไอพีของ server radio น่ะครับ เช่น http://ไอพี server/radio.html


Blog: ebook-ubuntu.blogspot.com
http://www.learners.in.th/blogs/posts/51511



VSFTPD Virtual users configuration (with MySQL) CentOS 5.x

You will need (if not already installed) VSFTPD and MySQL:

#yum install vsftpd mysql-server

Then Start mysqld if not already:

#service mysqld restart

and create root password for MySQL (if not already done):

#mysqladmin -u root password yourrootsqlpassword

3 Create The MySQL Database For vsftpd

login to mysql:
#mysql -u root -p
enter " yourrootsqlpassword " - Be aware: yourrootsqlpassword IS NOT your user's 'root' password and should be different.

Create database for users:
CREATE DATABASE vsftpd;
GRANT SELECT ON vsftpd.* TO 'vsftpd'@'localhost' IDENTIFIED BY 'vsftpdpassword';
FLUSH PRIVILEGES;
still in the MySQL shell, create the database table needed (there is only one table with usernames and passwords MD5 encrypted):
USE vsftpd;

CREATE TABLE `accounts` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 30 ) NOT NULL ,
`pass` VARCHAR( 50 ) NOT NULL ,
UNIQUE ( `username` )
) ENGINE = MYISAM ;
then you can
#exit;

4 Configure VSFTPD (Very Secure FTP server):

Create a non-privileged user called 'vsftpd' (with the homedir /home/vsftpd) belonging to the group 'users'. Vsftpd will run with this users privileges so risk to the system is minimized and the FTP directories of our virtual users will be in the '/home/vsftpd' directory (e.g. /home/vsftpd/user1, /home/vsftpd/user2, etc.) or as defined in VSFTPD PER USER config file.
useradd -G users -s /sbin/nologin -d /home/vsftpd  vsftpd
Then make VSFTP config settings (make a backup of the original /etc/vsftpd.conf file):
cp -v /etc/vsftpd/vsftpd.conf   /etc/vsftpd/vsftpd.conf-orig
and make our own needed changes:
First we empty the existing file and then open it for editing:
cat /dev/null > /etc/vsftpd/vsftpd.conf
vi /etc/vsftpd/vsftpd.conf
vsftpd.conf   configuration settings (copy this into file):
# No ANONYMOUS users allowed
anonymous_enable=NO
# Allow 'local' users with WRITE permissions (0755)
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES

# if you want to LOG vsftpd activity then uncomment this log_ftp_protocol
# log_ftp_protocol=YES

connect_from_port_20=YES

# uncomment xferlog_file and xferlog_std_format if you DIDN'T use the line above
# with log_ftp_protocol - it must be excluding each other
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# xferlog_std_format Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
# xferlog_std_format=YES

#
# You may change the default value for timing out an idle session (in seconds).
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection (in seconds).
#data_connection_timeout=120
#
# define a unique user on your system which the
# ftp server can use as a totally isolated and unprivileged user.
nopriv_user=vsftpd

chroot_local_user=YES

listen=YES

# here we use the authentication module for vsftpd to check users name and passw
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

# If userlist_deny=YES (default), never allow users in this file
# /etc/vsftpd/user_list , and do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
userlist_deny=yes

# here the vsftpd will allow the 'vsftpd' user to login into '/home/vsftpd/$USER directory
guest_enable=YES
guest_username=vsftpd
local_root=/home/vsftpd/$USER
user_sub_token=$USER
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/vsftpd_user_conf

force_local_data_ssl=NO
force_local_logins_ssl=NO

# PASV - passive ports for FTP (range 44000 - 44100 ; 100 PASV ports, OPEN FIREWALL FOR ALLOWING CONNECTIONS
pasv_enable=YES
pasv_min_port=44000
pasv_max_port=44100
With the user_config_dir option you can specify a directory for per-user configuration files that override parts of the global settings. This is totally optional and up to you if you want to use this feature.
However, create that directory now:
mkdir /etc/vsftpd/vsftpd_user_conf
If you want to have for example: 'user1' to have different 'home dir' other than '/home/vsftpd/user1' then create
vsftpd PER USER configuration file:
vi /etc/vsftpd/vsftpd_user_conf/user1
with configuration settings in it:
dirlist_enable=YES
download_enable=YES
# full path to the directory where 'user1' will have access, change to your needs
local_root=/home/users/user1
write_enable=YES
The 'user1' directory must be created if you want the user to be able to login!
mkdir /home/users/user1
and giving 'user1' the permissions to read, write...:
chmod 700 /home/users/user1
chown vsftpd.users /home/users/user1
So now user1 has 'home dir' in '/home/users/user1' instead of '/home/vsftpd/user1' and it can be changed to whatever you need to in the Per user configuration file ...

Now you must configure PAM (Password Authentication) so that it uses the MySQL database to authenticate your virtual FTP users instead of /etc/passwd and /etc/shadow.
The PAM configuration for vsftpd is in /etc/pam.d/vsftpd.
Make a backup of the original file and create a new one like this:
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd-orig
cat /dev/null > /etc/pam.d/vsftpd
vi /etc/pam.d/vsftpd
the /etc/pam.d/vsftpd contents (note: this should be only 4 lines when you copy it):
#%PAM-1.0
session     optional     pam_keyinit.so     force revoke
auth required pam_mysql.so user=vsftpd passwd=vsftpdpassword host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=3
account required pam_mysql.so user=vsftpd passwd=vsftpdpassword host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=3
AND MAKE SURE that you replace the MySQL 'vsftpdpassword' password with your own one used before in   3 Create The MySQL Database For vsftpd

Now comes that tricky part for CentOS to make it work !
You need pam_mysql.so library, which is not included in CentOS installation or is not YUM installable, so you have to install from RPM (or EPEL repository ... or whichever method you prefer).
 Find here (pbone.net) the RPM pam_mysql module to download it (use 'wget' is simple), at this time of writing it was 'pam_mysql-0.7-0.5.rc1.el5.kb.2.i386.rpm' (watch for the right version i386 or x86_64 if you have 64bit system)
and install it:
rpm -Uvh pam_mysql-0.7-0.5.rc1.el5.kb.2.i386.rpm
It should install without warnings or error... else ... I recommend you use search in google to make it work!

When installed, you should find it:
ls -al /lib/security/pam_m*
-rwxr-xr-x 1 root root 8024 Sep 4 00:51 /lib/security/pam_mail.so
-rwxr-xr-x 1 root root 15848 Sep 4 00:51 /lib/security/pam_mkhomedir.so
-rwxr-xr-x 1 root root 3892 Sep 4 00:51 /lib/security/pam_motd.so
-rwxr-xr-x 1 root root 36920 Feb 28 2008 /lib/security/pam_mysql.so
there it is in the last line in this example ! (you can have more, but should be in there)
This is critical for use virtual users auth with MySQL database
Now 5 Create The First Virtual User
Insert users to database you can use the MySQL shell:
mysql -u root -p
enter password ...
USE vsftpd;
use the database 'vsftpd'
Now create the virtual user 'user1' with the password 'secret' (which will be stored encrypted using MySQL's MD5 function):
INSERT INTO accounts (username, pass) VALUES('user1', md5('secret'));
You should now have one user in database:
mysql> select * from accounts;
+----+-----------+----------------------------------+
| id | username | pass |
+----+-----------+----------------------------------+
| 1 | user1 | 5ebe2294ecd0e0f08eab7690d2a6ee69 |
+----+-----------+----------------------------------+
1 rows in set (0.00 sec)

exit;
Now user1's homedir is '/home/vsftpd/user1' , unfortunately vsftpd doesn't create that directory automatically if it doesn't exist. Therefore create it manually now and make it owned by the vsftpd user and group 'users':
mkdir /home/vsftpd/user1
chown vsftpd:users /home/vsftpd/user1

Now restart/start VSFTPD
service vsftpd restart
อ้างอิง http://centosforserver.blogspot.com/2010/02/virtual-hosting-with-vsftpd-and-mysql.html