Category: IT


RJ-45自製網路線

測線器,一個發射端,一個接收端,上面8顆燈號

發射端會依序打出信號 1~8號燈,然後看接收器 1~8號燈 有沒有亮。

沒亮 = 線材中間斷蕊

亮的燈號順序不對 = 壓頭蕊線顏色排列錯誤,重壓

rj45

rj45-2

Reference: http://blog.xuite.net/axian/blog/224348022-%E8%87%AA%E5%B7%B1%E5%8B%95%E6%89%8B+DIY+RJ45+%E7%B6%B2%E8%B7%AF%E7%B7%9A%E6%8E%A5%E9%A0%AD%E5%90%A7%EF%BC%81

廣告

Mac: Reset home folder permissions

This is for Mountain Lion.

http://www.fixkb.com/2011/08/reset-home-folder-permissions.html

  1. In Terminal, type sudo bash and press Enter.
  2. You will need to enter your password and press Enter.
    • It won’t show any characters when you type.
    • If you do not have a password then set one first.
  3. Type in the following (case-sensitive), pressing Enter at the end of each line.
    Replace “username” with the name of your home folder.
    sudo chmod -R -v -N ~
    sudo chown -R username:staff ~
    sudo chmod -R -v 700 ~
    sudo chmod -v 755 ~

Generating Video Thumbnails With FFMPEG

Check out flowplayer’s – http://flowplayer.org/tutorials/generating-thumbs.html

In short,

ffmpeg -i [video_file] -f image2 -vframes 1 [output_image].jpg

For example,

ffmpeg -ss 12 -i flowplayer.mov -f image2 -vframes 1 flowplayer-12.jpg

MySQL 5.x Repair Cheat Sheet

If you upgrade MySQL or move the database around, you are most likely need to do those operations:

Backup

mysqldump -u root -p --default-character-set=utf8 databasename > data.sql

Restore

mysqldump -u root -p --default-character-set=utf8 databasename < data.sql
if database is larger then 100MB, this works better:
mysql -u root -p
#mysql> use the_database
#mysql> source data.sql

Check, Repair & Optimize All Tables in All Databases

If you need database server up, use mysqlcheck:
mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

Or you can make it offline and do a better check:
service mysqld stop
myisamchk /var/lib/mysql/the_database/*.MYI
service mysqld start

Repair single table

mysql -u root -p
#mysql> use the_database
#mysql> repair table the_table

Reference:
http://www.felipecruz.com/repair-mysql-database.php

A few app requires PHP 5.2.x but major repositories is yet support anything higher than 5.1.6 at this time. Recompile PHP is a pain also.

Remi maintains a repository that can save your 1 day or 2 if you have such need.

cd /etc/yum.repos.d/
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

You now have Remi repository on your system. It’s disabled by default, and I recommend you leave it as is. To install from remi, run the following:

yum --enablerepo=remi update php

I use remi to install php and its related stuff like GD, mcrypt, etc. As well as MySQL. The repository rocks!

I’ve put together old hardware pieces at home for a download & file sharing box. It got 4 old disks (30G, 250G, 500G, 80G) together. Knowing that disks will out of its life sooner or later, I rsync important stuff to the mac next to it. Couple weeks ago, shit finally happen.

The broken disk is the 30G, so most of stuff are still in the other disks. To recover, I put into a new disk, re-install CentOS, so the box is bootable again. Now I need to re-activate and mount the old disks.

Re-install CentOS
1.Put in the new disk, go to Bios and make sure CD-ROM is having first boot priority, and the new disk is the boot disk in Hard Disk boot priority setting.
2.Put in the CentOS DVD, boot from it. In the install process, make sure you don’t re-partition the old disks.
3.If you are not sure what to do, you can un-plug the power cores of all old disks, install on the new disk first. Once the installation is finished, plug back the power of old disks, boot from DVD again, and reset the boot loader.
4.Now you’ve got a bootable box with all the disks in place.

RHEL systems like Red Hat, CentOS or Fedora, partition the disks automatically at install time. By default, it sets up the partitions using LVM for the root device.
By default, the OS set up a volume group called VolGroup00, with two logical volumes, LogVol00 and LogVol01, the first for the root directory and the second for swap.

Since the new disk is big enough, I set up the new disk (not using the volume). As you can see in the partition layout of physical disks below (/dev/sda is the new disk):
[root@xxx]# sfdisk -l

Disk /dev/hda: 19457 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/hda1 * 0+ 19456 19457- 156288321 8e Linux LVM
/dev/hda2 0 - 0 0 0 Empty
/dev/hda3 0 - 0 0 0 Empty
/dev/hda4 0 - 0 0 0 Empty

Disk /dev/hdc: 24792 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/hdc1 * 0+ 24791 24792- 199141708+ 8e Linux LVM
/dev/hdc2 0 - 0 0 0 Empty
/dev/hdc3 0 - 0 0 0 Empty
/dev/hdc4 0 - 0 0 0 Empty

Disk /dev/sda: 38913 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 12 13- 104391 83 Linux
/dev/sda2 267 38912 38646 310423995 83 Linux
/dev/sda3 13 266 254 2040255 82 Linux swap / Solaris
/dev/sda4 0 - 0 0 0 Empty

Disk /dev/sdb: 60801 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sdb1 * 0+ 60800 60801- 488384001 8e Linux LVM
/dev/sdb2 0 - 0 0 0 Empty
/dev/sdb3 0 - 0 0 0 Empty
/dev/sdb4 0 - 0 0 0 Empty

To re-activate and re-mount
vgchange is the utility to update/change your volume group attribute. Since one of the disk in previous volume is missing, I need to vgchange –ay –partial to activate the volume.

[root@xxx]# vgchange –ay –partial
Couldn't find device with uuid 'AiegxE-NfQy-AA5E-OUcn-bvpY-UG3o-5oT1gY'.
/dev/mapper/VolGroup00-LogVol00-missing_3_0: read failed after 0 of 4096 at 0: Input/output error
/dev/mapper/VolGroup00-LogVol01-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
/dev/VolGroup00/LogVol01: read failed after 0 of 4096 at 0: Input/output error
Couldn't find device with uuid 'AiegxE-NfQy-AA5E-OUcn-bvpY-UG3o-5oT1gY'.
2 logical volume(s) in volume group "VolGroup00" now active

Well, a lot of error due to the missing disk, but the volume is active now. You can verify by:

[root@xxx]# lvscan
/dev/VolGroup00/LogVol00: read failed after 0 of 4096 at 892413607936: Input/output error
/dev/VolGroup00/LogVol00: read failed after 0 of 4096 at 892413665280: Input/output error
/dev/mapper/VolGroup00-LogVol01-missing_0_0: read failed after 0 of 4096 at 2080309248: Input/output error
/dev/mapper/VolGroup00-LogVol01-missing_0_0: read failed after 0 of 4096 at 4096: Input/output error
/dev/mapper/VolGroup00-LogVol01-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
/dev/VolGroup00/LogVol01: read failed after 0 of 4096 at 2080309248: Input/output error
/dev/VolGroup00/LogVol01: read failed after 0 of 4096 at 2080366592: Input/output error
Couldn't find device with uuid 'AiegxE-NfQy-AA5E-OUcn-bvpY-UG3o-5oT1gY'.
/dev/mapper/VolGroup00-LogVol00-missing_3_0: read failed after 0 of 4096 at 0: Input/output error
/dev/VolGroup00/LogVol01: read failed after 0 of 4096 at 0: Input/output error
Couldn't find device with uuid 'AiegxE-NfQy-AA5E-OUcn-bvpY-UG3o-5oT1gY'.
/dev/mapper/VolGroup00-LogVol00-missing_3_0: read failed after 0 of 4096 at 0: Input/output error
/dev/VolGroup00/LogVol01: read failed after 0 of 4096 at 0: Input/output error
Couldn't find device with uuid 'AiegxE-NfQy-AA5E-OUcn-bvpY-UG3o-5oT1gY'.
ACTIVE '/dev/VolGroup00/LogVol00' [831.12 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.94 GB] inherit

Now you can mount the active volume by:
[root@xxx]# mount /dev/VolGroup00/LogVol00 /mnt

The old volume is now accessible at /mnt
[root@xxx]# ls –al /mnt

What Next
I copy the stuff I want to recover. What to do with the old drives? I need to think about…Having a old box on all time is actually costly (in term of electric bill). But having a box on is handy in many occurrences..

Ref:
http://www.linuxjournal.com/article/8874
http://fedoraforum.org/forum/archive/index.php/t-64964.html

Network Time (NTP) service in CentOS

Synchronize the clocks is standard now-da-day. If you don’t have NTP for some reason, here’s how you set it up in CentOS.

First Install the NTP Package on your server as root.

# yum install ntp
Loading “fastestmirror” plugin
Loading mirror speeds from cached hostfile
* base: mirror.steadfast.net
* updates: mirrors.liquidweb.com
* addons: pubmirrors.reflected.net
* extras: pubmirrors.reflected.net
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
–> Running transaction check
—> Package ntp.i386 0:4.2.2p1-8.el5.centos.1 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

=================================================================
Package Arch Version Repository Size
=================================================================
Installing:
ntp i386 4.2.2p1-8.el5.centos.1 base 1.3 M

Transaction Summary
=================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): ntp-4.2.2p1-8.el5. 100% |=========================| 1.3 MB 00:19
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: ntp ######################### [1/1]

Installed: ntp.i386 0:4.2.2p1-8.el5.centos.1
Complete!

Next set it to start automatically on a reboot

# chkconfig ntpd on

Tell it which NTP server it should update it’s time from

# ntpdate pool.ntp.org
4 Aug 12:32:43 ntpdate[9540]: step time server 64.202.112.75 offset 1256.453048 sec

Verify that the Time & Date are correct

# date
Mon Aug 4 12:33:04 EDT 2008

Finally start the service

# service ntpd start
Starting ntpd: [ OK ]

Mono 2.x on CentOS 5

Mono no longer packages for Red Hat distribution but still provide sources. Here we will grab the source code, and install manually on a Cent OS 5.2 box.

First off, make sure you have all the development tools installed:

Pre-Software requirement

yum groupinstall "Development Tools"
yum install httpd build-essential gcc bzip bison pkgconfig glib-devel \
glib2-devel httpd-devel libpng-devel libX11-devel freetype fontconfig \
pango-devel ruby ruby-rdoc gtkhtml38-devel wget

At this time, Mono 2.0.1 is the latest. You can always check for new build at http://ftp.novell.com/pub/mono/sources-stable/

Getting all the needed Mono software

cd /root
wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.0.1.tar.bz2
wget http://ftp.novell.com/pub/mono/sources/xsp/xsp-2.0.tar.bz2
wget http://ftp.novell.com/pub/mono/sources/mod_mono/mod_mono-2.0.tar.bz2
wget http://ftp.novell.com/pub/mono/sources/libgdiplus/libgdiplus-2.0.tar.bz2

Unlike many other tutorials, we will install using “Java" style – the version # is included:

mkdir /opt/mono-2.0.1

Let’s make a desult symlink:,

ln -s /opt/mono-2.0.1 /opt/mono

This is needed when building xsp:

export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/opt/mono/lib/pkgconfig/:/usr/lib/
Set path (even we don’t actually have it yet)

export PATH=/opt/mono/bin:$PATH

Now we are ready to compile:

tar jvfx mono-2.0.1.tar.bz2

cd mono-2.0.1
./configure --prefix=/opt/mono-2.0.1
make; make install

tar jvfx xsp-2.0.tar.bz2
cd ~/xsp-2.0
./configure --prefix=/opt/mono
make; make install

tar jvfx mod_mono-2.0.tar.bz2
cd ~/mod_mono-2.0
./configure --prefix=/opt/mono --with-mono-prefix=/opt/mono --with-apr-config=/usr/lib/httpd/modules
make; make install

tar jvfx libgdiplus-2.0.tar.bz2
cd ~/libgdiplus-2.0
./configure
make; make install

You should now have mod_mono.so in /usr/lib/httpd/modules. Also you should have mod_server in /opt/mono/bin.
You directories should look like those:

Directory contents are as follows:

ls /opt/mono/bin/

al                    mono-api-info
al2 mono-api-info2
asp-state monodis
asp-state2 mono-find-provides
caspol mono-find-requires
cert2spc monograph
certmgr monolinker
chktrust monop
cilc monop2
dbsessmgr mono-service
dbsessmgr2 mono-service2
disco mono-shlib-cop
dtd2rng mono-test-install
dtd2xsd mono-xmltool
fastcgi-mono-server mozroots
fastcgi-mono-server2 nunit-console
gacutil nunit-console2
genxs pedump
gmcs permview
httpcfg prj2make
ilasm resgen
ilasm2 resgen2
installvst secutil
jay setreg
macpack sgen
makecert signcode
mbas smcs
mconfig sn
mcs soapsuds
mjs sqlsharp
mkbundle wsdl
mkbundle2 wsdl2
mod-mono-server xbuild
mod-mono-server2 xsd
mono xsp
mono-api-diff xsp2

ls /opt/mono/lib/

libgdiplus.a             libmono-profiler-aot.so.0
libgdiplus.la libmono-profiler-aot.so.0.0.0
libgdiplus.so libmono-profiler-cov.a
libgdiplus.so.0 libmono-profiler-cov.la
libgdiplus.so.0.0.0 libmono-profiler-cov.so
libikvm-native.a libmono-profiler-cov.so.0
libikvm-native.la libmono-profiler-cov.so.0.0.0
libikvm-native.so libmono.so
libmono.a libmono.so.0
libmono.la libmono.so.0.0.0
libMonoPosixHelper.a libMonoSupportW.a
libMonoPosixHelper.la libMonoSupportW.la
libMonoPosixHelper.so libMonoSupportW.so
libmono-profiler-aot.a mono
libmono-profiler-aot.la pkgconfig
libmono-profiler-aot.so xsp

ls /usr/lib/httpd/modules/

libphp5.so              mod_file_cache.so
mod_actions.so mod_filter.so
mod_alias.so mod_headers.so
mod_asis.so mod_ident.so
mod_auth_basic.so mod_imagemap.so
mod_auth_digest.so mod_include.so
mod_authn_alias.so mod_info.so
mod_authn_anon.so mod_ldap.so
mod_authn_dbd.so mod_log_config.so
mod_authn_dbm.so mod_log_forensic.so
mod_authn_default.so mod_logio.so
mod_authn_file.so mod_mem_cache.so
mod_authnz_ldap.so mod_mime_magic.so
mod_authz_dbm.so mod_mime.so
mod_authz_default.so mod_mono.so
mod_authz_groupfile.so mod_mono.so.0.0.0
mod_authz_host.so mod_negotiation.so
mod_authz_owner.so mod_proxy_ajp.so
mod_authz_user.so mod_proxy_balancer.so
mod_autoindex.so mod_proxy_connect.so
mod_cache.so mod_proxy_ftp.so
mod_cern_meta.so mod_proxy_http.so
mod_cgid.so mod_proxy.so
mod_cgi.so mod_rewrite.so
mod_dav_fs.so mod_setenvif.so
mod_dav.so mod_speling.so
mod_dbd.so mod_status.so
mod_deflate.so mod_suexec.so
mod_dir.so mod_unique_id.so
mod_disk_cache.so mod_userdir.so
mod_dumpio.so mod_usertrack.so
mod_env.so mod_version.so
mod_expires.so mod_vhost_alias.so
mod_ext_filter.so

And the mod_mono config file should be like this:

ls /etc/httpd/conf/mod_mono.conf
vi
/etc/httpd/conf/mod_mono.conf

<ifmodule>
LoadModule mono_module /usr/lib/httpd/modules/mod_mono.so
AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
</ifmodule>

Let’s move it to CentOS style:

mv /etc/httpd/conf/mod_mono.conf /etc/httpd/conf.d/mod_mono.conf

Restart web server

service httpd restart

Make a simple test file named default.aspx:
<%Response.Write("mono on centos - it works");%>

If you see that message at http://localhost/default.aspx, congrad, there you have it!

trac-10.4 繁體中文版

trac-10.4-zh_TW Traditional Chinese translation
trac-10.4 繁體中文版

Modified from ZoomQuiet version, this version provides translation for Traditional Chinese.

To download: http://trac-hacks.org/wiki/TraditionalChineseTranslation

Recently I set up a virtual server to use as a development machine. It runs on CentOS 5 and hosts several Subversion repositories with associated Trac projects.

There are many guides and plenty of help on the net to help you setup such a system. However, when I tried to do it I came across a few problems and I hope this post may help at least a few people trying to do the same as me. I am not going to rewrite the great tutorials out there, I will just point you to them and note what things I did differently.

This ‘guide’ should get you from a fresh install of CentOS 5 linux to one or more working Subversion (SVN) repositories and associated Trac wiki’s. Apache/WebDAV is used as the network layer. I have only tested this on a fresh install of CentOS 5.

The Environment

I am aiming for the following:

  • CentOS 5, SVN installed. Apache2 as the network layer using mod_dav_svn.
  • Trac running on Apache with mod_python
  • SVN repositories located at: /srv/svn (e.g. /srv/svn/my-project), accessible via http://server/svn/my-project
  • Trac projects located at: /srv/trac (e.g /srv/trac/my-project) accessible via http://server/trac/my-project

How I did it

Not all the steps are vital (probably) but this is how I got it working. Feel free to skip any non-relevant steps (i.e. there is probably no need for a fresh install). Replace any occurence of with the name of your first project.

1. Fresh install of CentOS. I followed most of the Perfect Setup Guide, except the mail and ISPConfig stuff. The important part is setting up the Apache2 web server.

2. Make sure SVN and mod_dav_svn are installed. As root:

yum install subversion mod_dav_svn
vim /etc/httpd/conf/httpd.conf

If the following two lines are not present, add them:

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

3. Install Trac: Follow Nick’s guide with the alternative Clearsilver installation below. Skip the Apache Configuration part.

Follow all of parts 1 and 2. Instead of part 3 do:

wget http://dag.wieers.com/rpm/packages/clearsilver/clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i clearsilver-0.10.4-1.el5.rf.i386.rpm
wget http://dag.wieers.com/rpm/packages/clearsilver/python-clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm

Continue with parts 4.1 and 4.2 of Nick’s guide. Remember, leave out Apache configuration section.

4. Create your first SVN Repository:

svnadmin create --fs-type fsfs /srv/svn/project_name

5. Initialise a Trac project for your new repository:

trac-admin /srv/trac/project_name initenv

For the trac-admin command use the defaults if not sure, giving a descriptive name for the project. The `Path to repository` is: /srv/svn/project_name.

6. Set the correct file permissions for apache


chown -R apache.apache /srv/svn/project_name
chown -R apache.apache /srv/trac/project_name

7. Tell apache where to find the new repository. Here we create an additional Apache configuration file specifically for the SVN repositories.

vim /etc/httpd/conf.d/subversion.conf

Add the following directive:


<location>
DAV svn
SVNPath /srv/svn/project_name
AuthType Basic
AuthName "My SVN Repository"
AuthzSVNAccessFile /srv/svn/svn-acl-conf
AuthUserFile /srv/svn/.htpasswd
Require valid-user
</location>

8. Add a repository user:


touch /srv/svn/.htpasswd
htpasswd -m /srv/svn/.htpasswd username

9. Create the Access Control List for the SVN Repository


vim /srv/svn/svn-acl-conf

Add the following directives:


[project_name:/]
username = rw

Where username represents the username of the repository user you created earlier.

10. Tell apache where to find the new Trac project. Here we create an additional Apache configuration file specifically for the Trac projects.

vim /etc/httpd/conf.d/trac.conf

Add the following directives:



<location>
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /srv/trac/project_name
PythonOption TracUriRoot /trac/

<location/login>
AuthType Basic
AuthName "trac"
AuthUserFile /srv/trac/.htpasswd
Require valid-user
</location>
</location>

11. Add a Trac user:

touch /srv/trac/.htpasswd
htpasswd -m /srv/trac/.htpasswd

12. Give admin permissions to the Trac user you just created:

trac-admin /srv/trac/ permission add  TRAC_ADMIN

Where represents the username of the Trac user you just created.

13. Restart Apache:

service httpd restart

You should now have SVN and Trac installed. You will have an SVN repository setup (http://server/svn/) and the Trac wiki (http://server/trac/) associated with the repository.

Please let me know if this helped you. If you come across any problems I will be happy to try and help.

Resources

The last part of CentOS HowTos: Subversion will give you a quick introduction on how to use SVN.

Subversion setup guides: here and here

Trac setup guides: here and here.

ClearSilver template system (used by Trac).

Setting up CentOS 5.0