tag:blogger.com,1999:blog-69873782743718109692024-03-19T12:26:57.366+08:00Linux, Unix, ShellGao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.comBlogger50125tag:blogger.com,1999:blog-6987378274371810969.post-63641560384269696292016-04-01T22:25:00.000+08:002016-04-01T22:25:25.729+08:00Zabbix: Received value is not suitable for value type [Numeric (unassigned)] and data type [Decimal]Recently I was told one of our monitoring item is broken. <br />At first I thought maybe zabbix server was busy, but only one host is having issue. <br />My second thought: maybe that host was busy and zabbix agent couldn't return value. But all other items are working fine, only item "<i><span style="font-family: "Courier New",Courier,monospace;">product_diff</span></i>" is broken.<br />I tried zabbix_get manually, I could get value without problem.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ zabbix_get -s centos-1.local.vb -k product_diff</span><br /><span style="font-family: "Courier New",Courier,monospace;">-398</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ zabbix_get -s centos-1.local.vb -k product_diff<br />-205</span></blockquote>
And in the zabbix_server.log, I saw entries like this:<br /><span style="font-family: "Courier New",Courier,monospace;"><i> 31168:20160322:095648.251
item "centos-1.local.vb:product_diff" became not supported: Received
value [-299] is not suitable for value type [Numeric (unsigned)] and
data type [Decimal]</i></span><br />So centos-1.local.vb returned negative values while zabbix server was expecting <i><span style="font-family: "Courier New",Courier,monospace;">Numeric (unassigned)</span></i>.<br /><br />It
turns out that, we configured zabbix to monitor product_diff on
centos-1.local.vb, initially we were only interested in the absolute
difference. But recently production team felt the real difference makes
more sense to them. So they replaced the script on centos-1.local.vb.<br />But inside zabbix server, the item configuration was not changed<br /><br />In item configuration, product_diff is configured like this:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG3oVKvBPlSH6JGAqLuj9YO89Czn6O6QgpgQJiaHfafGkupYtPbe76VcFOfDnyeQ4fKV0UlEgUqBaI8L2tRjKhxHlCgOZZizmCxPZeaISxdQDlmoaCOZpZPaoIolmfrygzVsdngBtYT_s/s1600/zabbix_1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG3oVKvBPlSH6JGAqLuj9YO89Czn6O6QgpgQJiaHfafGkupYtPbe76VcFOfDnyeQ4fKV0UlEgUqBaI8L2tRjKhxHlCgOZZizmCxPZeaISxdQDlmoaCOZpZPaoIolmfrygzVsdngBtYT_s/s1600/zabbix_1.PNG" /></a></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
I updated "Type of Information" from "Numeric (unassigned)" to "Numeric (float)"<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2-xx2lq6Lmbogt6uwR5URgm-pf2x-F03ysgm-otzua8gUQNq39MiFxWsTX8g11A7gkGWeKmOvKiRaHf4GKz8Et7eqIQD5HPxkeTdG9XWCvqitvMtbKulD78lv1Wi5AZ3NC_HNymRXrm8/s1600/zabbix_2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2-xx2lq6Lmbogt6uwR5URgm-pf2x-F03ysgm-otzua8gUQNq39MiFxWsTX8g11A7gkGWeKmOvKiRaHf4GKz8Et7eqIQD5HPxkeTdG9XWCvqitvMtbKulD78lv1Wi5AZ3NC_HNymRXrm8/s1600/zabbix_2.PNG" /></a></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
Monitoring should work now, but it doesn't, and I still see errors in zabbix_server.log<br />In zabbix, all the configurations are kept in database, so maybe the changes made on web UI didn't update database.<br />Logging in to zabbix database, check the item table:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">MYSQL> select key_, value_type from items where key_ = 'product_diff';</span><br /><span style="font-family: "Courier New",Courier,monospace;">+---------------------------+</span><br /><span style="font-family: "Courier New",Courier,monospace;">| key_ | value_type |</span><br /><span style="font-family: "Courier New",Courier,monospace;">+---------------------------+</span><br /><span style="font-family: "Courier New",Courier,monospace;">| product_diff | 3 |</span><br /><span style="font-family: "Courier New",Courier,monospace;">+--------------+------------+</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />In
zabbix value_type 3 represents Numeric (unassigned), 0 represents
Numeric (float). So we need to update this table, setting value_type to
0.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">MYSQL> update items set value_type = 0 key_ = 'product_diff';</span></blockquote>
<br />After that, monitoring started working again!Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-2270171768423496742014-09-25T20:48:00.002+08:002014-09-25T20:48:57.907+08:00Configure ILOM for Remote Server Management - SUN serversILOM stands for Integrated Lights Out Manager, all T-series servers come with ILOM.<br />Using ILOM we can remotely manage the server including power off and power on, just like we are in front of the server.<br /><br />But to access ILOM remotely, we need to configure it first. Items needed for remote access include:<br />
<ol>
<li>IP address</li>
<li>Netmask</li>
<li>Gateway</li>
</ol>
Additionally we can also give a friendly name for ILOM.<br /><br />Let's assume our out-of-band access is in <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">192.168.200.0/255.255.255.0</span></span>, the gateway for this network is <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">192.168.200.254</span></span><br />We are going to setup ILOM for a new server <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">websvr01</span></span>, with remote access IP <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">192.168.200.1</span></span>.<br /><br />Before ILOM is configured, we have to access it in the data center. Connect your laptop to the Serial Console. Login with default userid/password: <span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">root/changeme</span></span>.<br />Once you are inside, you can setup ILOM.<br /><br />To setup a friendly name: <br />
<blockquote class="tr_bq">
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">cd /SP</span><br /><span style="font-family: "Courier New",Courier,monospace;">set hostname=websvr01-ilom</span></span></blockquote>
To setup network:<br />
<blockquote class="tr_bq">
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">cd /SP/network</span><br /><span style="font-family: "Courier New",Courier,monospace;">set pendingipaddress=192.168.200.1</span><br /><span style="font-family: "Courier New",Courier,monospace;">set pendingipnetmask=255.255.255.0</span><br /><span style="font-family: "Courier New",Courier,monospace;">set pendingipgateway=192.168.200.254</span><br /><span style="font-family: "Courier New",Courier,monospace;">set pendingipdiscovery=static</span><br /><span style="font-family: "Courier New",Courier,monospace;">set commitpending=true</span></span></blockquote>
Instead of setting IP, netmask, gateway separately, we can also configure them in one command:<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">set pendingipaddress=192.168.200.1 pendingipnetmask=255.255.255.0 pendingipgateway=192.168.200.254</span></span><br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"></span></span></blockquote>
<br />
After that connecting Net Management port to proper port on switch, you will be able login remotely.<br /><br />To access remotely:<br />
<blockquote class="tr_bq">
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">ssh 192.168.200.1</span></span></blockquote>
<br />After keying in user id and password, you will see the same interface as logging in through serial console.Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-43336694190591292492014-04-18T14:58:00.000+08:002014-04-18T14:58:10.849+08:00Sync data using Veritas Volume ManagerI have been using rsync to do data migration, recently I need to do data migration again.<br /><br />Since this time the data resides in Veritas volumes, I want to try the Veritas way.<br /><br />My setup in the old server is like this:<br />
<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxprint -g ftpdg<br />TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0<br />dg ftpdg ftpdg - - - - - -<br /><br />dm ftpdg01 tagmastore-usp0_0 - 461350656 - - - -<br />dm ftpdg02 tagmastore-usp0_1 - 31439616 - - - -<br /><br />v volb gen ENABLED 461314816 - ACTIVE - -<br />pl volb-01 volb ENABLED 461314816 - ACTIVE - -<br />sd ftpdg01-01 volb-01 ENABLED 461314816 0 - - -<br /><br />v vols gen ENABLED 31438848 - ACTIVE - -<br />pl vols-01 vols ENABLED 31438848 - ACTIVE - -<br />sd ftpdg02-01 vols-01 ENABLED 31438848 0 - - -</span></span><br /><br /><br />I allocated two LUNs from storage, they are identified as tagmastore-usp0_2 and tagmastore-usp0_3.<br />
<br />
<br />
<br />To enable the new disks <br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdctl enable</span></span><br /><br />
My <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">privlen</span></span> for old disks was 2048, so set the same value for new disks<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdisksetup -i tagmastore-usp0_2 privlen=2048<br /># vxdisksetup -i tagmastore-usp0_3 privlen=2048</span></span><br /><br />Add the new disks to disk group:<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdg -g ftpdg adddisk ftpdg03=tagmastore-usp0_2<br /># vxdg -g ftpdg adddisk ftpdg04=tagmastore-usp0_3</span></span><br /><br />Create sub disk and plex<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxmake -g ftpdg sd ftpdg03-01 ftpdg03,0,461314816<br /># vxmake -g ftpdg plex volb-02<br /><br /># vxmake -g ftpdg sd ftpdg04-01 ftpdg04,0,31438848<br /># vxmake -g ftpdg plex vols-02</span></span><br /><br />Attach the plex to volumes<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxplex -g ftpdg att volb volb-02<br /># vxplex -g ftpdg att vols vols-02</span></span><br /><br />After attaching the plex, both old and new disks should have identical data, we can detach the new disks and add it to our new server.<br /><br />Detach the new plex<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxplex -g ftpdg det volb-02<br /># vxplex -g ftpdg det vols-02</span></span><br />Disassociate the new plex<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxplex -g ftpdg dis volb-02<br /># vxplex -g ftpdg dis vols-02</span></span><br /><br />Create new volume using the detached plex<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxmake -g ftpdg vol newb plex=volb-02<br /># vxmake -g ftpdg vol news plex=vols-02</span></span><br /><br />Split the diskgroup<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdg split ftpdg ftpdg2 newb news</span></span><br /><br />At this step, we will have a diskgroup <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">ftpdg2</span></span>, inside it there are two volumes: newb and news.<br />We are planning to use the same volume names on new server, so rename the volumes in ftpdg2<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxedit -g ftpdg2 rename newb volb<br /># vxedit -g ftpdg2 rename news vols</span></span><br />We can deport ftpdg2 from our old server:<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdg deport ftpdg2</span></span><br /><br />On new server we can import ftpdg2 as ftpdg<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxdg import -n ftpdg ftpdg2</span></span><br /><br />We also need to start the volumes<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># vxvol -g ftpdg start volb<br /># vxvol -g ftpdg start vols</span></span><br /><br />The device path for the volumes are:<br /><span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">/dev/vx/dsk/ftpdg/volb<br />/dev/vx/dsk/ftpdg/vols</span></span><br /><br />we can mount the volumes and start using it!Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-18969448374374050412014-01-21T12:03:00.000+08:002014-01-21T12:03:53.868+08:00407 Proxy Authentication RequiredRecently I installed an Ubuntu box, following my windows configuration, I set my proxy as <span style="font-family: "Courier New",Courier,monospace;">http://proxyhost:8080</span><br />
But when I tried to wget something, I got this error:<br />"407 Proxy Authentication Required"<br /><br />It turns out the proxy server requires my windows AD username/password. After googling around I found the software Cntlm (<a href="http://cntlm.sourceforge.net/">http://cntlm.sourceforge.net</a>)<br />The installation and setup steps are quite straightforward:<br />
<ol>
<li>Download cntlm_0.92.3_amd64.deb from <a href="http://cntlm.sourceforge.net/">http://cntlm.sourceforge.net</a> <br /></li>
<li>Installing cntlm<br /><span style="font-family: "Courier New",Courier,monospace;"># dpkg -i cntlm_0.92.3_amd64.deb</span> <br /></li>
<li>Configure /etc/cntlm.conf<br /><span style="font-family: "Courier New",Courier,monospace;">Username linuxscripter<br />Domain windows-domain<br />Proxy proxyhost:8080<br />NoProxy localhost, 127.0.0.*, 10.*, 192.168.*<br />Listen 3128</span> <br /></li>
<li>Generate encrypted password:<br /><span style="font-family: "Courier New",Courier,monospace;"># cntlm -H -M http://proxyhost:8080 -c /etc/cntlm.conf</span><br />You will be prompted for Password, key in your windows AD password, and copy the command output and paste in <span style="font-family: "Courier New",Courier,monospace;">/etc/cntlm.conf</span> <br /></li>
<li>Restart cntlm service:<br /><span style="font-family: "Courier New",Courier,monospace;"># /etc/init.d/cntlm restart</span> <br /></li>
<li>Set proxy to <span style="font-family: "Courier New",Courier,monospace;">http://127.0.0.1:3128</span></li>
</ol>
My Ubuntu is ready to connect to outside world!Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com1tag:blogger.com,1999:blog-6987378274371810969.post-62348649700955433842013-12-13T10:53:00.001+08:002013-12-13T10:53:41.749+08:00Migrate sun4u to sun4v using FLARFLAR stands for FLash ARchive. If we need to install a few Solaris servers and customize them in a similar way.<br />
Instead of installing and configuring one by one, we can install and configure one server first, then create FLAR on this server, and install the other servers using this FLAR.<br />FLAR can also be used for server migration.<br />
<br />The steps of creating FLAR and installing from FLAR is very straight forward. However if we are migrating from servers with older CPU to servers with different CPU architecture, we have to do some extras steps.<br />Recently I migrated a few servers from sun4u to sun4v using FLAR, Here are my migration steps:<br />
create FLAR image on sun4u server<br />
<ol>
<li>By default FLAR created on sun4u cannot be used on sun4v servers, we have to add sun4v as a supported architecture for FLAR.<span style="font-family: "Courier New",Courier,monospace;"><br /># echo "PLATFORM_GROUP=sun4v" >> /var/sadm/system/admin/.platform</span><span style="font-family: "Courier New",Courier,monospace;"><br /># flarcreate -n "migration flar" -c -S -x /flar -x /export/home /flar/migration.flar</span><br />Alternatively we can add -U flag to create FLAR with sun4v support<span style="font-family: "Courier New",Courier,monospace;"><br /># flarcreate -n "migration flar" -U "content_architectures=sun4u,sun4v" -c -S -x /flar -x /export/home /flar/migration.flar</span> <br /> </li>
<li>Verify our FLAR can be used on sun4v machines:<span style="font-family: "Courier New",Courier,monospace;"><br /># flar -i /flar/migration.flar | grep content_architectures<br /></span></li>
<li> Now move the FLAR to a storage accessible from sun4v machines, this can either be NFS, HTTP, or a local hard drive.<br /></li>
<li>Boot sun4v machine, choose Flash Install, and select the migration.flar we created in step 1.<br /></li>
<li>After installation completes, reboot server, we will get this error:<br /><span style="font-family: "Courier New",Courier,monospace;">cannot open boot_archive</span> <br /></li>
<li>To boot the server properly, we need to upgrade the sun4v machine:<br />boot sun4v machine from DVD or Jumpstart, select Upgrade, after upgrade finishes, reboot server.</li>
</ol>
We have successfully migrated sun4u to sun4v machine!<br /><br />Reference:<br /><a href="http://docs.oracle.com/cd/E19253-01/821-0436/samekernel/index.html">http://docs.oracle.com/cd/E19253-01/821-0436/samekernel/index.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-32266225467803113292013-11-26T14:37:00.000+08:002013-11-27T11:14:33.376+08:00Using tmpfs to improve Nagios performanceNagios is an excellent monitoring tool. We can monitor servers, network devices using Nagios.<br />
Besides many of the useful plugins at nagios exchange (<a href="http://exchange.nagios.org/">http://exchange.nagios.org</a>) , we can also write our own plugins using shell scripts.<br />
<br />
We can set up Nagios monitoring server by following <a href="http://linuxscripter.blogspot.com/2013/09/setting-up-nagios-monitoring-server.html" target="_blank">Setting up Nagios monitoring server</a>, the default setting and configuration is sufficient if we are only monitoring a few servers. However as the number of monitored hosts and services increases, we will notice the check latencies.<br />
This is because Nagios needs continuously updating some files on disk, when there are more items to monitor, there are also more disk I/O required, eventually I/O will become the bottle neck, it's slowing down the Nagios check.<br />
<br />
To solve this problem, we need to improve IO performance or reduce IO requests, we can install Nagios on SSD disk, but it's not cost effective.<br />
<br />
In an earlier post <a href="http://linuxscripter.blogspot.com/2013/09/using-tmpfs-to-improve-postgresql.html" target="_blank">using tmpfs to improve PostgreSQL performance</a>, to boost the performance of PostgreSQL, we pointed stats_temp_directory to tmpfs.<br />
Similarly, if some files are only needed when Nagios is running, we can move them to tmpfs, thus reduce IO requests.<br />
In Nagios there are a few key files that affect disk I/O, they are:<br />
1. <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/var/status.data</span>, this status file stores the current status of all monitored services and hosts, it's being consistently updated as defined by status_update_interval, in my default nagios installation, status_file is updated every 10 seconds.<br />
The contents of the status file are deleted every time Nagios restarts, so it's only useful when nagios is running.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/etc]# grep '^status' nagios.cfg</span><br />
<span style="font-family: "Courier New",Courier,monospace;">status_file=/usr/local/nagios/var/status.dat</span><br />
<span style="font-family: "Courier New",Courier,monospace;">status_update_interval=10</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
2. <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/var/objects.cache</span>, this file is a cached copy of object definitions, and CGIs read this file the get the object definitions.<br />
the file is recreated every time Nagios starts, So objects.cache doesn't need to be on non-volatile storage.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/etc]# grep objects.cache nagios.cfg</span><br />
<span style="font-family: "Courier New",Courier,monospace;">object_cache_file=/usr/local/nagios/var/objects.cache</span></blockquote>
<br />
3. <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/var/spool/checkresults</span>, all the incoming check results are stored here, while Nagios is running, we will notice that files are being created and deleted constantly, so checkresults can also be moved to tmpfs<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/etc]# grep checkresults nagios.cfg</span><br />
<span style="font-family: "Courier New",Courier,monospace;">check_result_path=/usr/local/nagios/var/spool/checkresults</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/etc]#</span></blockquote>
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/var/spool/checkresults]# ls</span><br />
<span style="font-family: "Courier New",Courier,monospace;">checkP2D5bM cn6i6Ld cn6i6Ld.ok</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/var/spool/checkresults]# head -4 cn6i6Ld</span><br />
<span style="font-family: "Courier New",Courier,monospace;">### Active Check Result File ###</span><br />
<span style="font-family: "Courier New",Courier,monospace;">file_time=1385437541</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">### Nagios Service Check Result ###</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos /usr/local/nagios/var/spool/checkresults]#</span></blockquote>
<br />
So we can move <span style="font-family: "Courier New",Courier,monospace;">status.data</span>, <span style="font-family: "Courier New",Courier,monospace;">objects.cache</span> and <span style="font-family: "Courier New",Courier,monospace;">checkresults</span> to tmpfs, but before that we need to mount the file system first<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# mkdir -p /mnt/nagvar</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# mount -t tmpfs tmpfs /mnt/nagvar -o size=50m</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# df -h /mnt/nagvar</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Filesystem Size Used Avail Use% Mounted on</span><br />
<span style="font-family: "Courier New",Courier,monospace;">tmpfs 50M 0 50M 0% /mnt/nagvar</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# mount | grep nagvar</span><br />
<span style="font-family: "Courier New",Courier,monospace;">tmpfs on /mnt/nagvar type tmpfs (rw,size=50m)</span></blockquote>
<br />
create directory for checkresults<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# mkdir -p /mnt/nagvar/spool/checkresults</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# chown -R nagios:nagios /mnt/nagvar</span></blockquote>
<br />
modify nagios.cfg<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">status_file=/mnt/nagvar/status.dat</span><br />
<span style="font-family: "Courier New",Courier,monospace;">object_cache_file=/mnt/nagvar/objects.cache</span><br />
<span style="font-family: "Courier New",Courier,monospace;">check_result_path=/mnt/nagvar/spool/checkresults</span></blockquote>
<br />
restart nagios so our changes will take effect<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# service nagios restart</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Running configuration check...done.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Stopping nagios: done.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Starting nagios: done.</span></blockquote>
<br />
we can see, nagios is using /mnt/nagvar <br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# tree /mnt/nagvar/</span><br />
<span style="font-family: "Courier New",Courier,monospace;">/mnt/nagvar/</span><br />
<span style="font-family: "Courier New",Courier,monospace;">├── objects.cache</span><br />
<span style="font-family: "Courier New",Courier,monospace;">├── spool</span><br />
<span style="font-family: "Courier New",Courier,monospace;">│ └── checkresults</span><br />
<span style="font-family: "Courier New",Courier,monospace;">│ ├── ca8JfZI</span><br />
<span style="font-family: "Courier New",Courier,monospace;">│ └── ca8JfZI.ok</span><br />
<span style="font-family: "Courier New",Courier,monospace;">└── status.dat</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">2 directories, 4 files</span></blockquote>
<br />
We can configure <span style="font-family: "Courier New",Courier,monospace;">/etc/fstab</span> to mount <span style="font-family: "Courier New",Courier,monospace;">/mnt/nagvar</span> everytime system reboots.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# echo <<EOF >> /etc/fstab</span><br />
<span style="font-family: "Courier New",Courier,monospace;">tmpfs /mnt/nagvar tmpfs defaults,size=50m 0 0</span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span></blockquote>
<br />
But the directory <span style="font-family: "Courier New",Courier,monospace;">/mnt/nagvar/spool/checkresults</span> will be gone after <span style="font-family: "Courier New",Courier,monospace;">/mnt/nagvar</span> is re-mounted, so we need to create this directory before starting up Nagios.<br />
we can update <span style="font-family: "Courier New",Courier,monospace;">/etc/init.d/nagios</span>, add this lines after the first line:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">mkdir -p /mnt/nagvar/spool/checkresults</span><br />
<span style="font-family: "Courier New",Courier,monospace;">chown -R nagios:nagios /mnt/nagvar</span></blockquote>
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# sed -i '1a\</span><br />
<span style="font-family: "Courier New",Courier,monospace;">mkdir -p /mnt/nagvar/spool/checkresults\</span><br />
<span style="font-family: "Courier New",Courier,monospace;">chown -R nagios:nagios /mnt/nagvar' /etc/init.d/nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
Since we have moved the files to tmpfs, there is no disk I/O on these files, we can see great performance improvement of Nagios.<br />
<br />
Reference:<br />
<a href="http://assets.nagios.com/downloads/nagiosxi/docs/Utilizing_A_RAM_Disk_In_NagiosXI.pdf">http://assets.nagios.com/downloads/nagiosxi/docs/Utilizing_A_RAM_Disk_In_NagiosXI.pdf</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com1tag:blogger.com,1999:blog-6987378274371810969.post-70429380729667676172013-11-21T14:41:00.001+08:002013-11-22T09:41:52.110+08:00setup nginx web server with PHPNginx (engine x) is a high performance lightweight HTTP server, more and more sites are using nginx, according to Netcraft survey (<a href="http://news.netcraft.com/archives/2013/11/01/november-2013-web-server-survey.html">http://news.netcraft.com/archives/2013/11/01/november-2013-web-server-survey.html</a>), nginx powers 15% of the busies sites in November 2013.<br />
<br />
Nginx installation is very straight forward, we can download latest source code from <a href="http://nginx.org/en/download.html">http://nginx.org/en/download.html</a> or point our yum source to <a href="http://nginx.org/packages/OS/OSRELEASE/$basearch/">http://nginx.org/packages/OS/OSRELEASE/$basearch/</a> and install using yum.<br />
Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5” or “6”, for 5.x or 6.x versions, respectively. <br />
So for CentOS 6.3, we can point our YUM source to: <a href="http://nginx.org/packages/OS/OSRELEASE/$basearch/">http://nginx.org/packages/centos/6/$basearch/</a><br />
<br />
<a name='more'></a>If we install nginx using YUM, its binary is at /usr/sbin/nginx and configuration file at /etc/nginx/nginx.conf<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# cat /etc/sysconfig/nginx</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># Configuration file for the nginx service.</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">NGINX=/usr/sbin/nginx</span><br />
<span style="font-family: "Courier New",Courier,monospace;">CONFFILE=/etc/nginx/nginx.conf</span></blockquote>
We can use service command to start and stop nginx service:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# service nginx stop</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Stopping nginx: [ OK ]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# service nginx start</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Starting nginx: [ OK ]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# service nginx status</span><br />
<span style="font-family: "Courier New",Courier,monospace;">nginx (pid 2518) is running...</span></blockquote>
In Apache, the most common way of running PHP is through php5_module, we need to compile PHP against Apache and load mod_php module in Apache configuration files.<br />
Unlike Apache, the most common way of running PHP in Nginx is through fastcgi <br />
To configure fastcgi, add these lines to nginx.conf<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"> location ~ \.php$ {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> root /usr/share/nginx/html;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> fastcgi_pass 127.0.0.1:9000;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span></blockquote>
Restart nginx to make our changes take effect<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos conf.d]# service nginx restart</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Stopping nginx: [ OK ]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Starting nginx: [ OK ]</span></blockquote>
All the requests to PHP will be served by fastcgi running localhost port 9000, to start fastcgi on localhost, run this command<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos conf.d]# php-cgi -b 127.0.0.1:9000 &</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
Confirm php-cgi is listening on port 9000<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos conf.d]# netstat -pan | grep 9000</span><br />
<span style="font-family: "Courier New",Courier,monospace;">tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3209/php-cgi</span></blockquote>
<br />
Now create our info.php in directory /usr/share/nginx/html<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos conf.d]# cat <<EOF > /usr/share/nginx/html/info.php</span><br />
<span style="font-family: "Courier New",Courier,monospace;">> <?php</span><br />
<span style="font-family: "Courier New",Courier,monospace;">> phpinfo();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">> ?></span><br />
<span style="font-family: "Courier New",Courier,monospace;">> EOF</span></blockquote>
<br />
Launch web browser and visit http://localhost/info.php, the value of <b>Server API</b> should be <b>CGI/FastCGI</b><br />
FastCGI Process Manager (FPM) provides more features useful for heavy load sites, in production we should use FPM instead.<br />
Since PHP 5.3.3, FPM is included in the PHP cores, we can use --enable-fpm to turn on php-fpm when installing PHP.<br />
<br />
References: <br />
<a href="http://nginx.org/">http://nginx.org</a><br />
<a href="http://news.netcraft.com/archives/2013/11/01/november-2013-web-server-survey.html">http://news.netcraft.com/archives/2013/11/01/november-2013-web-server-survey.html</a><br />
<a href="http://php-fpm.org/download/">http://php-fpm.org/download/</a><br />
<a href="http://www.php.net/manual/en/install.fpm.install.php">http://www.php.net/manual/en/install.fpm.install.php</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-86074005005507495772013-11-05T10:02:00.000+08:002013-11-05T10:10:15.022+08:00How to recover deleted open filesIn Linux, a file is deleted completed when:<br />
<ol>
<li>No more hard link reference to the file</li>
<li>Processes opening the file is terminated</li>
</ol>
From why du and df show different filesystem usage (<a href="http://linuxscripter.blogspot.com/2013/11/why-du-and-df-show-different-filesystem.html">http://linuxscripter.blogspot.com/2013/11/why-du-and-df-show-different-filesystem.html</a>), we know that if we delete an open file, Linux won't release its space until the opening processes are stopped. <br />
<br />
So if we delete an open file by mistake, is there a way to recover it?<br />
YES, we can check which process is opening the file, and recover file content by checking the process file descriptor.<br />
<br />
Again, let's assume our Apache error_log is deleted, we can check which process is opening this file:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos ~]# lsof | sed -n '1p;/error_log.*deleted/p'<br />COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME<br />httpd 3155 root 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3157 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3158 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3159 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3160 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3161 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3162 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3163 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)<br />httpd 3164 apache 2w REG 253,0 370 15396 /var/log/httpd/error_log (deleted)</span></blockquote>
<br />
From the output we know that, process 3155 still opens this file. Go to /proc/3155/fd/ to confirm this, 2w means error_log is opened for write, and we need to check softlink "2" in /proc/3155/fd.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos ~]# cd /proc/3155/fd/</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos fd]# ls -l 2</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">l-wx------ 1 root root 64 Nov 5 09:46 2 -> /var/log/httpd/error_log (deleted)</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos fd]# tail 2</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[Tue Nov 05 09:46:35 2013] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[Tue Nov 05 09:46:35 2013] [notice] Digest: generating secret for digest authentication ...</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[Tue Nov 05 09:46:35 2013] [notice] Digest: done</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[Tue Nov 05 09:46:35 2013] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations</span></blockquote>
<br />
To recover the content of error_log, we can just copy 2 to a temporary location, stop Apache and rename copy of 2 to /var/log/httpd/error_log<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos fd]# cp 2 /tmp/error_log</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos ~]# service httpd stop<br />Stopping httpd: [ OK ]<br />[root@centos ~]# mv /tmp/error_log /var/log/httpd/error_log</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@centos ~]# service httpd start<br />Starting httpd: [ OK ]</span></blockquote>
Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-22270606353239673732013-11-04T10:45:00.001+08:002013-11-05T11:00:03.647+08:00why du and df show different filesystem usageToday I saw a forum post asking on his system, why df shows over 200G space used, while du only shows 50G ussed.<br />
Most probably this is caused by open files being deleted.<br />
When a file is opened by a process, deleting the file won't release the space occupied by it. we also need to terminate the process, otherwise df and du will show different filesystem usage.<br />
<br />
Let's assume du and df show huge difference for /var, we can check which open files are deleted and the processes opening them.<br />
<br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[root@linux ~]# lsof | sed -n '1p;/var.*deleted/p'<br />COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME<br />httpd 1779 root 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1810 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1811 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1812 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1813 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1814 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1815 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1816 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)<br />httpd 1817 apache 10w REG 253,0 22034 8117 /var/log/httpd/access_log (deleted)</span><br />
From the output we can see that access_log is deleted, but Apache was not restarted, httpd process still has this file open.<br />
to release the space, we can restart httpd process:<br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">[root@linux ~]# service httpd restart<br />Stopping httpd: [ OK ]<br />Starting httpd: [ OK ]</span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">Now check again</span></span><br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">[root@linux ~]# lsof | sed -n '1p;/var.*deleted/p'<br />COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME</span></span><br />
And du df report same file system usage.<br />
<br />
Before we restart httpd process, Linux won't release the space used by access_log, if access_log is deleted by mistake, is there a way to recover it?<br />
Yes, I will demo how to recover deleted open files in <a href="http://linuxscripter.blogspot.com/2013/11/how-to-recover-deleted-open-files.html" target="_blank">http://linuxscripter.blogspot.com/2013/11/how-to-recover-deleted-open-files.html </a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-88846888496143189472013-11-02T16:30:00.000+08:002013-11-05T10:45:52.043+08:00Use puppet to manage linux serversPuppet is a configuration management system, using puppet we can easily manage thousands of Linux servers. If we have configured our system using epel source, we can directly install puppet using YUM. Alternatively we can download the software from puppetlabs.org and follow document to install it.<br /><br />
To install manually, our system must have ruby installed, ruby rpm files can be found on linux installation media, if we have a local yum repository, we can install ruby using yum.<br /><br />After ruby is installed, we can download and install puppet, facter is also required for puppet. we download the stable versions is facter-1.7.2.tar.gz and puppet-3.2.2.tar.gz.<br /><br /><br /> 1. Install puppet on both puppet master and agent<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf facter-1.7.2.tar.gz</span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd facter-1.7.2</span><br /><span style="font-family: "Courier New",Courier,monospace;"># ruby install.rb </span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd .. </span><br /><span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf puppet-3.2.2.tar.gz </span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd puppet-3.2.2 </span><br /><span style="font-family: "Courier New",Courier,monospace;"># ruby install.rb</span></blockquote>
<br />
2. start puppet master<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># puppet master</span></blockquote>
<br /> 3. on agent, edit /etc/puppet/puppet.conf<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[main]<br />server = centos.local.vb
<br />certificate_revocation = false
<br />ssldir=/var/lib/puppet/ssl</span></blockquote>
<br />4. connect puppet master for the first time, this will generate an ssl signing request <br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># puppet agent --no-daemonize --onetime --verbose</span><br /><span style="font-family: "Courier New",Courier,monospace;">Info: Creating a new SSL certificate request for centos-1.local.vb</span><br /><span style="font-family: "Courier New",Courier,monospace;">Info: Certificate Request fingerprint (SHA256): B8:67:94:4C:2A:23:2F:90:D8:4E:34:CC:AF:48:B0:04:BA:82:7F:D2:E3:7F:B7:9A:78:35:18:87:EB:05:D5:61</span><br /><span style="font-family: "Courier New",Courier,monospace;">Exiting; no certificate found and waitforcert is disabled</span></blockquote>
<br /><br /> 5. On puppet master, sign the ssl request from puppet agent<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# puppet cert list</span><br /><span style="font-family: "Courier New",Courier,monospace;"> "centos-1.local.vb" (SHA256) B8:67:94:4C:2A:23:2F:90:D8:4E:34:CC:AF:48:B0:04:BA:82:7F:D2:E3:7F:B7:9A:78:35:18:87:EB:05:D5:61</span><br /><span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# puppet cert sign "centos-1.local.vb"</span><br /><span style="font-family: "Courier New",Courier,monospace;">Notice: Signed certificate request for centos-1.local.vb</span><br /><span style="font-family: "Courier New",Courier,monospace;">Notice: Removing file Puppet::SSL::CertificateRequest centos-1.local.vb at '/var/lib/puppet/ssl/ca/requests/centos-1.local.vb.pem'</span></blockquote>
<br /><br /> 6. Now we can manage our linux servers from puppet master. If we want to manage httpd service, we can create an httpd module<br /><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># mkdir -p /etc/puppet/modules/httpd</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />Every module stores its configuration in manifests/init.pp file, so we need to create /etc/puppet/modules/httpd/manifests/init.pp<br /><br /><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">class httpd {</span><br /><span style="font-family: "Courier New",Courier,monospace;"> package { "httpd":</span><br /><span style="font-family: "Courier New",Courier,monospace;"> ensure => installed,</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;"> service { "httpd":</span><br /><span style="font-family: "Courier New",Courier,monospace;"> ensure => running,</span><br /><span style="font-family: "Courier New",Courier,monospace;"> enable => true,</span><br /><span style="font-family: "Courier New",Courier,monospace;">}</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;"> file { "/var/www/html/index.html":</span><br /><span style="font-family: "Courier New",Courier,monospace;">ensure => present,</span><br /><span style="font-family: "Courier New",Courier,monospace;">group => "root",</span><br /><span style="font-family: "Courier New",Courier,monospace;">owner => "root",</span><br /><span style="font-family: "Courier New",Courier,monospace;">mode => "0644",</span><br /><span style="font-family: "Courier New",Courier,monospace;">source => "puppet:///modules/httpd/puppet.index.html"</span><br /><span style="font-family: "Courier New",Courier,monospace;">}</span><br /><span style="font-family: "Courier New",Courier,monospace;">}</span></blockquote>
<br />source => "puppet:///modules/httpd/puppet.index.html" is telling puppet agent that it needs to get index.html from puppet master, the file location on master is: /etc/puppet/modules/httpd/files/puppet.index.html<br /><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># echo i am from puppet index.html ! > /etc/puppet/modules/httpd/files/puppet.index.html</span> </blockquote>
we have a httpd module, to manage agent, we also need to define our node files, we can define this in /etc/puppet/manifests/site.pp<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">node centos-1 {</span><br /><span style="font-family: "Courier New",Courier,monospace;"> include httpd</span><br /><span style="font-family: "Courier New",Courier,monospace;">}</span></blockquote>
<br />
7. test our configuration on centos-1:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-1 html]# puppet agent --no-daemonize --onetime --verbose</span><br /><span style="font-family: "Courier New",Courier,monospace;">Info: Retrieving plugin</span><br /><span style="font-family: "Courier New",Courier,monospace;">Info: Caching catalog for centos-1.local.vb</span><br /><span style="font-family: "Courier New",Courier,monospace;">Info: Applying configuration version '1383379216'</span><br /><span style="font-family: "Courier New",Courier,monospace;">Notice: /Stage[main]/Httpd/Service[httpd]/ensure: ensure changed 'stopped' to 'running'</span><br /><span style="font-family: "Courier New",Courier,monospace;">Notice: /Stage[main]/Httpd/File[/var/www/html/index.html]/ensure: defined content as '{md5}33f97919a4e508801272b7889f34e332'</span><br /><span style="font-family: "Courier New",Courier,monospace;">Notice: Finished catalog run in 0.70 seconds</span></blockquote>
Puppet supports regular expressions in its configuration files, if all the servers centos-1 centos-2 centos-999 have same configuration, instead of repeating the node definitions 999 times, we can represent them using one regular expression.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">node /^centos-\d$/</span></blockquote>
Puppet also supports import in its configuration files, if all our agents have different configuration files, besides constructing a big site.pp, we can have 1 configuration file for each agent, centos-1.pp centos-2.pp centos-999.pp, and then import them from site.pp<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">import "nodes/*"</span></blockquote>
As the environment grows, we will have more and more configuration files in nodes directory, it's not very efficient to manage many files, puppet has a feature called External Node Classifier (ENC), using ENC we can replace text-based node definition files with LDAP, database, or whatever data sources suitable for our environment.<br /><br /> Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-31822353481468027122013-10-11T16:30:00.000+08:002013-10-22T12:58:03.032+08:00use HAProxy as HTTP load balancerHAProxy can provide high availability, load balancing, and proxying for TCP and HTTP based application.<br />
<br />
In my lab setup of HAProxy, I have 3 servers<br />
<br />
centos-1, running apache<br />
centos-2, running apache<br />
centos, running HAProxy, HTTP requests to it will be forwarded to the other 2 servers<br />
<br />
Here are my steps of setting up HAProxy to load balance between to HTTP servers.<br />
<br />
1. on centos-1 and centos-2: install apache<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># yum -y install httpd</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
create index.html for apache<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># hostname -s > /var/www/html/index.html</span></blockquote>
disable iptables, start apache<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># service iptables stop</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># service httpd start</span></blockquote>
<br />
2. on centos, download HAProxy, the latest stable version is 1.4.24<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># ./haproxy -v</span><br />
<span style="font-family: "Courier New",Courier,monospace;">HA-Proxy version 1.4.24 2013/06/17</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Copyright 2000-2013 Willy Tarreau <w@1wt.eu></span></blockquote>
<br />
3. edit haproxy configuration file, my sample haproxy.cfg, note this is for testing only, for complete configuration options, refer to http://cbonte.github.io/haproxy-dconv/configuration-1.4.html<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">global</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> daemon</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> maxconn 256</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">defaults</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> mode http</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> timeout connect 5000ms</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> timeout client 50000ms</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> timeout server 50000ms</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">frontend http-in</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> bind *:80</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> default_backend servers</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">backend servers</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> balance roundrobin</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> server server1 centos-1:80 maxconn 32</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> server server2 centos-2:80 maxconn 32</span></blockquote>
<br />
4. start HAProxy<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># ./haproxy -f haproxy.cfg</span></blockquote>
<br />
5. launch web browser, visit http://192.168.100.100, you will see the page displaying "centos-1", this shows our request is being served by centos-1<br />
refresh the page again, page will display "centos-2", our request is being served by centos-2 this time.<br />
<br />
If we change <span style="font-family: "Courier New",Courier,monospace;">balance roundrobin</span> to <span style="font-family: "Courier New",Courier,monospace;">balance source</span>, our request will always being served by the same host, but using sticky session is still the preferred way to make sure clients always connect to the same backend server.<br /><br />
The setup is done, but it needs more tweaks before it can be used in production environment.things to check:<br />
1. check backend server aliveness.<br />
2. sticky session.<br />
3. we need to change apache LogFormat on centos-1 centos-2 to reflect the real HTTP client address.<br />
<br />
In our setup centos is the only server running HAProxy, it will be a single point of failure, we can setup centos cluster, and make HAProxy listening on the VIP.<br />
<br />
<br />
reference: <br />
<a href="http://haproxy.1wt.eu/" target="_blank">http://haproxy.1wt.eu/</a> <br />
<a href="http://cbonte.github.io/haproxy-dconv/configuration-1.4.html">http://cbonte.github.io/haproxy-dconv/configuration-1.4.html</a> Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-652766856964183002013-09-24T14:02:00.002+08:002013-11-26T15:08:35.072+08:00Using tmpfs to improve PostgreSQL performanceIn PostgreSQL, the statistics collector collects the following information:<br />
<ol>
<li>statistics about table and index accesses</li>
<li>usage of user-defined functions</li>
<li>current command executed by any server process.</li>
</ol>
<br />
The statistics collector then passes the information to backends using temporary files, location of the temporary files are defined by <span style="font-family: "Courier New",Courier,monospace;">stats_temp_directory</span> in <span style="font-family: "Courier New",Courier,monospace;">postgresql.conf</span>, by defaults it points to <span style="font-family: "Courier New",Courier,monospace;">$PGDATA/pg_stat_tmp</span><br />
As PostgreSQL is running, there are continuous I/O in <span style="font-family: "Courier New",Courier,monospace;">stats_temp_directory</span>, the disk IO may affect database performance. PostgreSQL recommends to point <span style="font-family: "Courier New",Courier,monospace;">stats_temp_directory</span> to RAM-based file system, decreasing physical I/O, thus increasing database performance.<br />
<br />
We can use either ramfs or tmpfs, for the differences of the two, see <a href="http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/">http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/</a><br />
<br />
I will use tmpfs for <span style="font-family: "Courier New",Courier,monospace;">stats_temp_directory</span>, here are my steps <br />
1. create directory for our new mount point:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"># mkdir /mnt/tmp</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
2. mount tmpfs<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"># mount -t tmpfs tmpfs /mnt/tmp/ -o size=200m</span></blockquote>
now we have a file system of 200M.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"># df -h /mnt/tmp/</span><span style="font-size: small;"><br /><span style="font-family: "Courier New",Courier,monospace;">Filesystem Size Used Avail Use% Mounted on</span><br /><span style="font-family: "Courier New",Courier,monospace;">tmpfs 200M 8.0K 200M 1% /mnt/tmp</span></span></blockquote>
every time the server reboots, <span style="font-family: "Courier New",Courier,monospace;">/mnt/tmp</span> will be gone, to make the configuration persistent, add this line to <span style="font-family: "Courier New",Courier,monospace;">/etc/fstab</span><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">tmpfs /mnt/tmp tmpfs defaults,size=200m 0 0</span></blockquote>
<br />
<br />
3. edit <span style="font-family: "Courier New",Courier,monospace;">postgres.conf</span>, add this line:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">stats_temp_directory = '/mnt/tmp'</span></blockquote>
<br />
4. restart database<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">$ pg_ctl -D /var/lib/pgsql/data restart</span></blockquote>
<br />
5. confirm we are using the tmpfs<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[postgres@linux ~]$ psql</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">psql (8.4.11)</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">Type "help" for help.</span><br />
<span style="font-size: small;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">postgres=# show stats_temp_directory;</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> stats_temp_directory</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">----------------------</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> /mnt/tmp</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">(1 row)</span><br />
<span style="font-size: small;"><br /></span>
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">postgres=# \q</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[postgres@linux ~]$ ls -lh /mnt/tmp/</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">total 8.0K</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">-rw------- 1 postgres postgres 6.0K Sep 24 13:41 pgstat.stat</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;">[postgres@linux ~]$</span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"></span></span></blockquote>
Similarly, we can <a href="http://linuxscripter.blogspot.com/2013/11/using-tmpfs-to-improve-nagios.html" target="_blank">use tmpfs to improve the performance of Nagios server</a>. <br />
reference:<br />
<a href="http://www.postgresql.org/docs/9.1/static/monitoring-stats.html">http://www.postgresql.org/docs/9.1/static/monitoring-stats.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com2tag:blogger.com,1999:blog-6987378274371810969.post-23902473480141951082013-09-10T16:49:00.002+08:002013-09-10T16:49:21.510+08:00How to install Zabbix agent and monitor remote linux serversI installed Zabbix server in my previous post: <a href="http://linuxscripter.blogspot.com/2013/09/how-to-install-zabbix-server-on-linux.html">http://linuxscripter.blogspot.com/2013/09/how-to-install-zabbix-server-on-linux.html</a><br />
To monitor remote servers, we can install Zabbix agent.<br />
Installing Zabbix agent is quite straight forward<br />
<br />
Here are my installation steps:<br />
1. create user account for zabbix<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># useradd zabbix</span></span></blockquote>
2. download current stable version zabbix-2.0.8.tar.gz from www.zabbix.com<br />
3. configure and install zabbix agent<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf zabbix-2.0.8.tar.gz</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># cd zabbix-2.0.8</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># ./configure --enable-agent --prefix=/usr/local/zabbix</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># make install</span></span></blockquote>
4. modify <span style="font-family: "Courier New",Courier,monospace;">/usr/local/zabbix/etc/zabbix_agentd.conf</span><br />
In previouse post, we installed zabbix server on <span style="font-family: "Courier New",Courier,monospace;">192.168.100.100</span>, so modify the Server parameter<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">Server=192.168.100.100</span></blockquote>
5. restart zabbix_agentd to reload the new configuration file<br />
now we can monitor this host from zabbix server.<br />
<br />
To monitor remote host, all the configuration are done in the Zabbix web interface.<br />
1. open web browser, go to <a href="http://zabbix-server/zabbix">http://zabbix-server/zabbix</a><br />
2. <b>Configuration</b> -> <b>Hosts</b> -> <b>Create host</b><br />
Enter the host name, IP address, choose "Linux servers" as the host group.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-GH8ZkXbF_Orw0JE5VrGB1Zl8sAWNPB0l3wBEp-Ny0-tT5ziwSw81aUAQBgrtwlSUMdtxTTaGSLMEmqMsus4dC_ukW1ve4cUqM8uC1Ni8-2wJaNraOqlKenioLH0W5eO7j8VrZnPfYvk/s1600/zabbix1.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-GH8ZkXbF_Orw0JE5VrGB1Zl8sAWNPB0l3wBEp-Ny0-tT5ziwSw81aUAQBgrtwlSUMdtxTTaGSLMEmqMsus4dC_ukW1ve4cUqM8uC1Ni8-2wJaNraOqlKenioLH0W5eO7j8VrZnPfYvk/s640/zabbix1.PNG" width="640" /></a></div>
<br />
<br />
3. After saving, you will see the host linux-1 is monitored by zabbix now.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZW6IuKSvshdgmRIxjE3fLIpGbJsafz7Rvp5ECG2lmFTQXuQg2Rsy2Ber0oU_ry_Tfo9TDPoQovYbIiJgSeL-wftYtWNyIqeiUJoMpMm65t-cUBl52DAsmbOtOU0reAmN7tYr42hr7zCU/s1600/zabbix2.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="134" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZW6IuKSvshdgmRIxjE3fLIpGbJsafz7Rvp5ECG2lmFTQXuQg2Rsy2Ber0oU_ry_Tfo9TDPoQovYbIiJgSeL-wftYtWNyIqeiUJoMpMm65t-cUBl52DAsmbOtOU0reAmN7tYr42hr7zCU/s640/zabbix2.PNG" width="640" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
4. At the monitoring dashboard, you will see issues are shown in different colors </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBar88Ng-7_MZZ-W7rMXcCPCII6nuk0Ln-jQse6x5NjFdctD1UIkX0X3Q7d9BjSSxSfMzf35HWcEozuoTFuamxtyAg20SnS8KrnKC0vR7v5esE3Az6MfndPFWoqV13wCW_KJiRY1FwvkM/s1600/zabbix3.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="378" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBar88Ng-7_MZZ-W7rMXcCPCII6nuk0Ln-jQse6x5NjFdctD1UIkX0X3Q7d9BjSSxSfMzf35HWcEozuoTFuamxtyAg20SnS8KrnKC0vR7v5esE3Az6MfndPFWoqV13wCW_KJiRY1FwvkM/s640/zabbix3.PNG" width="640" /></a></div>
<br />
<br />
Reference: <a href="https://www.zabbix.com/documentation/2.0/manual/installation/install#from_the_sources">https://www.zabbix.com/documentation/2.0/manual/installation/install#from_the_sources</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-71839193644217265882013-09-10T16:10:00.001+08:002013-09-10T16:10:44.230+08:00How to install Zabbix server on Linux serverZabbix is an open source monitoring server, besides monitoring the service status, it also stores the historical status of service, so we can generate graphs easily from Zabbix. I have been using Nagios for many years, recently I decided to give Zabbix a try.<br /><br />Here are the steps I installed server.<br /><br />First we need to download zabbix software, current stable version is 2.0.8, so I downloaded zabbix-2.0.8.tar.gz<br /><br />1. create OS account for running zabbix server<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># useradd zabbix</span> </span></blockquote>
2. <br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf zabbix-2.0.8.tar.gz</span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd zabbix-2.0.8</span></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
3. Zabbix uses databases as its data storage, it supports MySQL, PostgreSQL, Oracle, DB2 and SQLite. In my setup I use MySQL.<br />Before Installing zabbix, we need to configure the database properly.<br />Follow instructions on this link to setup the database <a href="https://www.zabbix.com/documentation/2.0/manual/appendix/install/db_scripts">https://www.zabbix.com/documentation/2.0/manual/appendix/install/db_scripts</a><br />For MySQL:<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">mysql> create database zabbix character set utf8 collate utf8_bin;</span></span></blockquote>
<blockquote>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">mysql> grant all privilegs on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';<br />mysql> exit;</span></span></blockquote>
<blockquote>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql</span><br /><span style="font-family: "Courier New",Courier,monospace;"># mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql</span><br /><span style="font-family: "Courier New",Courier,monospace;"># mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql</span></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />4. <br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># ./configure --enable-server --with-mysql --with-net-snmp \<br /> --with-libcurl --prefix=/usr/local/zabbix</span><br /><span style="font-family: "Courier New",Courier,monospace;"># make install</span></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />5. start zabbix server<br />
<blockquote>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># /usr/local/zabbix/sbin/zabbix_server</span></span></blockquote>
<br />6. Install zabbix web interface:<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># mkdir /var/www/html/zabbix/</span></span></blockquote>
<blockquote>
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"># cp -pr frontends/php/* /var/www/html/zabbix/</span></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />7. Installing zabbix frontend<br />Open browser, go to <a href="http://localhost/zabbix">http://localhost/zabbix</a>, follow the instructions for frontend installation wizard to complete the installation.<br /><br />8. After Installing, you will be able to login zabbix system, the default login ID is <b>Admin</b>, password is <b>zabbix</b>.<br />
<br />
Next we need to install zabbix agent on remote hosts and zabbix server to monitor remote hosts.<br />
<br />
Reference: <a href="https://www.zabbix.com/documentation/2.0/manual/installation/install#from_the_sources">https://www.zabbix.com/documentation/2.0/manual/installation/install#from_the_sources</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-59475268132121277752013-09-03T15:05:00.000+08:002013-09-04T15:18:42.238+08:00Using Subversion to maintain programsI am using subversion to keep all my shell scripts, it helps to maintain the scripts change history:<br />
<br />
To use subversion, first we need to create a repository, on svn server<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># svnadmin create /usr/local/scripts</span><br />
<span style="font-family: "Courier New",Courier,monospace;">cat <<EOF > /usr/local/scripts/conf/svnserve.conf</span><br />
<span style="font-family: "Courier New",Courier,monospace;">anon-access = none</span><br />
<span style="font-family: "Courier New",Courier,monospace;">auth-access = write</span><br />
<span style="font-family: "Courier New",Courier,monospace;">password-db = passwd</span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
The rest of the parts are all done on clients:<br />
To add files to subversion repository, we can run<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">svn import /usr/local/scripts/check_mem.sh \<br />svn+ssh://lnxscrpt@linux/usr/local/scripts/check_mem.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Adding /usr/local/scripts/check_mem.sh</span></blockquote>
Alternatively, we can check out an SVN copy, update on our local copy, then check in whatever changes done on local copy to SVN repository<br />
1. To check out<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ mkdir ~/work; cd ~/work</span><br />
<span style="font-family: "Courier New",Courier,monospace;">$ svn co svn+ssh://lnxscrpt@linux/usr/local/scripts</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Checked out revision 0.</span></blockquote>
<br />
We will have ~/work/scripts directory now<br />
<br />
After we check out, other people may have made some changes to the repository, it's always a good practice to update our local copy before changing anything.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ svn up scripts</span><br /><span style="font-family: "Courier New",Courier,monospace;">At revision 0.</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
2. To add check_load.sh, copy check_load.sh to ~/work/scripts, and run <br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ svn add scripts/check_load.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;">A scripts/check_load.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br /></blockquote>
3. Commit our changes:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ svn ci scripts/</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Adding scripts/check_load.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Transmitting file data .</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Committed revision 1.</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
4. Make sure check_load.sh is in SVN repository:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ svn ls svn+ssh://lnxscrpt@linux/usr/local/scripts</span><br />
<span style="font-family: "Courier New",Courier,monospace;">check_load.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;">check_mem.sh</span></blockquote>
<br />
5. check svn log<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">$ svn log svn+ssh://lnxscrpt@linux/usr/local/scripts/check_load.sh</span><br /><span style="font-family: "Courier New",Courier,monospace;">------------------------------------------------------------------------</span><br /><span style="font-family: "Courier New",Courier,monospace;">r1 | lnxscrpt | 2013-09-03 14:25:11 +0800 (Tue, 03 Sep 2013) | 2 lines</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">added check_load.sh at 2:25pm</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">------------------------------------------------------------------------</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">$ svn log svn+ssh://lnxscrpt@linux/usr/local/scripts/check_mem.sh</span><br /><span style="font-family: "Courier New",Courier,monospace;">------------------------------------------------------------------------</span><br /><span style="font-family: "Courier New",Courier,monospace;">r5 | lnxscrpt | 2013-09-03 14:44:38 +0800 (Tue, 03 Sep 2013) | 2 lines</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">import check_mem.sh</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">------------------------------------------------------------------------</span></span></blockquote>
<br />
Note: whenever we svn commands, we will be prompted the password for lnxscrpt@linux, we can set up password ssh login by following: <a href="http://linuxscripter.blogspot.com/2012/05/set-up-password-less-ssh-login-using.html">http://linuxscripter.blogspot.com/2012/05/set-up-password-less-ssh-login-using.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-42039311876096867552013-09-02T14:39:00.001+08:002013-09-02T14:39:22.207+08:00Using Nagios and NRPE to monitor remote hostsWe have setup Nagios to monitor our localhost centos, but how to monitor remote hosts? We can monitor remote hosts using SNMP or NRPE<br />In our testing environment, we will setup Nagios to monitor host centos-1 and centos-2 using NRPE.<br />To use NRPE, we need to install NRPE on both monitoring host and remote hosts:<br /><br />Steps to setup remote hosts for NRPE monitoring:<br />1. Download nagios-plugins-1.4.16.tar.gz, nrpe-2.14.tar.gz<br />2. Create account for NRPE service<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># useradd nagios</span><br /><span style="font-family: "Courier New",Courier,monospace;"># passwd nagios</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />3. Install nagios-plugs<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar zxpf nagios-plugins-1.4.16.tar.gz</span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd nagios-plugins-1.4.16</span><br /><span style="font-family: "Courier New",Courier,monospace;"># ./configure --with-nagios-user=nagios \<br /> --with-nagios-group=nagios</span><br /><span style="font-family: "Courier New",Courier,monospace;"># make</span><br /><span style="font-family: "Courier New",Courier,monospace;"># make install</span><br /><span style="font-family: "Courier New",Courier,monospace;"># chown nagios:nagios /usr/local/nagios</span></blockquote>
<br />4. Install NRPE<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar zxpf nrpe-2.14.tar.gz<br /># cd nrpe-2.14<br /># ./configure<br /># make all<br /># make install-plugin<br /># make install-daemon<br /># make install-daemon-config</span></blockquote>
<br />5. Modify <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/etc/nrpe.cfg</span> to allow host centos(192.168.100.100) to connect to NRPE<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">allowed_hosts=127.0.0.1,192.168.100.100</span></blockquote>
<br />6. Start NRPE, enable autostart to NRPE<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># /usr/local/nagios/bin/nrpe -c \<br /> /usr/local/nagios/etc/nrpe.cfg -d</span><br /><span style="font-family: "Courier New",Courier,monospace;"># echo '/usr/local/nagios/bin/nrpe -c \<br /> /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local</span></blockquote>
<br />7. Verify NRPE is working properly<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># /usr/local/nagios/libexec/check_nrpe -H localhost</span><br /><span style="font-family: "Courier New",Courier,monospace;">NRPE v2.14</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />Steps to setup monitoring host for NRPE monitoring<br />1. Download nrpe-2.14.tar.gz<br />2. Install NRPE<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf nrpe-2.14.tar.gz</span><br /><span style="font-family: "Courier New",Courier,monospace;"># cd nrpe-2.14</span><br /><span style="font-family: "Courier New",Courier,monospace;"># ./configure</span><br /><span style="font-family: "Courier New",Courier,monospace;"># make all</span><br /><span style="font-family: "Courier New",Courier,monospace;"># make install-plugin</span></blockquote>
<br />3. Enable monitoring of centos-1<br />Update <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/etc/objects/commands.cfg</span> to enable command <span style="font-family: "Courier New",Courier,monospace;">check_nrpe</span><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># ‘check_nrpe’ command definition</span><br /><span style="font-family: "Courier New",Courier,monospace;">define command{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> command_name check_nrpe</span><br /><span style="font-family: "Courier New",Courier,monospace;"> command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$</span><br /><span style="font-family: "Courier New",Courier,monospace;">}</span></blockquote>
<br />update<span style="font-family: "Courier New",Courier,monospace;"> /usr/local/nagios/etc/nagios.cfg</span> to include this line<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">cfg_file=/usr/local/nagios/etc/objects/centos-1.cfg</span></blockquote>
<br />4. Edit <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/etc/objects/centos-1.cfg</span><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">define host{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> use linux-server</span><br /><span style="font-family: "Courier New",Courier,monospace;"> host_name centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> alias centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> address 192.168.100.101</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">define hostgroup{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> hostgroup_name centos</span><br /><span style="font-family: "Courier New",Courier,monospace;"> alias centos</span><br /><span style="font-family: "Courier New",Courier,monospace;"> members centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">define service{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> use generic-service</span><br /><span style="font-family: "Courier New",Courier,monospace;"> host_name centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> service_description PING</span><br /><span style="font-family: "Courier New",Courier,monospace;"> check_command check_ping!100.0,20%!500.0,60%</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">define service{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> use generic-service</span><br /><span style="font-family: "Courier New",Courier,monospace;"> host_name centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> service_description Server Load</span><br /><span style="font-family: "Courier New",Courier,monospace;"> check_command check_nrpe!check_load</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">define service{</span><br /><span style="font-family: "Courier New",Courier,monospace;"> use generic-service</span><br /><span style="font-family: "Courier New",Courier,monospace;"> host_name centos-1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> service_description /rhiso Usage</span><br /><span style="font-family: "Courier New",Courier,monospace;"> check_command check_nrpe!check_rhiso</span><br /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />5. Restart Nagios service<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># service nagios restart</span></blockquote>
<br />Steps to enable nrpe commands check_load and check_rhiso on remote host centos-1<br />Edit <span style="font-family: "Courier New",Courier,monospace;">/usr/local/nagios/etc/nrpe.cfg</span>, add these 2 lines:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20</span><br /><span style="font-family: "Courier New",Courier,monospace;">command[check_rhiso]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% /rhiso</span></blockquote>
<br />restart nrpe daemon<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># pkill nrpe</span><br /><span style="font-family: "Courier New",Courier,monospace;"># /usr/local/nagios/bin/nrpe -c \<br /> /usr/local/nagios/etc/nrpe.cfg -d</span></blockquote>
<br />Login to http://centos/nagios again, you will see now we have host centos-1 monitored, similarly we can setup the monitoring of centos-2<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyjoviRE_dx1OHyh1TMiuMzk9N6mUPAxOvbOpa4qVHcFKdZjxH9AAJ6x8SFy52nS7U7KjFLtlemn-Un-eMCtdyEmWw-q5LyouUmg1bT9S-l7vxZhsvgUNQ0ClV7Drguifv2FzY8_SFFFA/s1600/nagios.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="65" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyjoviRE_dx1OHyh1TMiuMzk9N6mUPAxOvbOpa4qVHcFKdZjxH9AAJ6x8SFy52nS7U7KjFLtlemn-Un-eMCtdyEmWw-q5LyouUmg1bT9S-l7vxZhsvgUNQ0ClV7Drguifv2FzY8_SFFFA/s640/nagios.PNG" width="640" /></a></div>
<br />Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-13383979364216386042013-09-02T13:50:00.000+08:002013-09-03T09:17:24.827+08:00Setting up Nagios monitoring serverNagios is an open-source monitoring software, you can monitor different host resources like host UP/down status, disk usage, system load, logfile.<br />
Setting up Nagios on Linux is very straight forward.<br />
<br />
In our test environment, we will setup host centos as our monitoring host.<br />
<br />
Steps to install Nagios on centos:<br />
1. Download nagios core, nagios plugins<br />
<a href="http://www.nagios.org/download/core">http://www.nagios.org/download/core</a>, choose DIY option.<br />
<a href="http://www.nagios.org/download/plugins">http://www.nagios.org/download/plugins</a>, download latest stable version.<br />
<br />
2. Create nagios account:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># useradd nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># passwd nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># groupadd nagcmd</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># usermod -a -G nagcmd nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># usermod -a -G nagcmd apache</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
3. Install Nagios<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf nagios-3.5.0.tar.gz</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># cd nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># ./configure --with-command-group=nagcmd</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># make all</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># make install</span></blockquote>
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;"># make install-init</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># make install-config</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># make install-commandmode</span></blockquote>
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;"># make install-webconf</span></blockquote>
<br />
4. Create nagiosadmin account, this account will be used to login to nagios web interface<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># htpasswd -c /usr/local/nagios/etc/htpasswd.users \<br /> nagiosadmin</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
5. Edit /etc/httpd/conf.d/nagios.conf, pointing AuthUserFile to /usr/local/nagios/etc/htpasswd.users<br />
<br />
6. Start apache<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># service httpd restart</span></blockquote>
<br />
7. Install Nagios Plugins<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"># tar -zxpf nagios-plugins-1.4.16.tar.gz</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># cd nagios-plugins-1.4.16</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># ./configure --with-nagios-user=nagios \<br /> --with-nagios-group=nagios</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># make; make install</span></blockquote>
<br />
8. Enable autostart of Nagios and start Nagios service<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;"># chkconfig --add nagios<br /># chkconfig nagios on</span><br />
<span style="font-family: "Courier New",Courier,monospace;"># service nagios start</span></blockquote>
9. Login to http://centos/nagios, you will see we already have centos monitored by Nagios<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYfDwk6VpYvSjt1lS5IYg24-vqryfTW4zPdS7BlbfoPMNE8ps1xfuEDOMCQnIVohG_WEyDGdEZ0vwFF0nZ6HlJ_PTMUiJog0-gy1rhl2zVg2sxCEr7EevpHk7zwAUkQHq1DKFEfLOuLFE/s1600/nagios.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="144" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYfDwk6VpYvSjt1lS5IYg24-vqryfTW4zPdS7BlbfoPMNE8ps1xfuEDOMCQnIVohG_WEyDGdEZ0vwFF0nZ6HlJ_PTMUiJog0-gy1rhl2zVg2sxCEr7EevpHk7zwAUkQHq1DKFEfLOuLFE/s640/nagios.PNG" width="640" /></a></div>
<br />
In the next post <a href="http://linuxscripter.blogspot.com/2013/09/using-nagios-and-nrpe-to-monitor-remote.html">http://linuxscripter.blogspot.com/2013/09/using-nagios-and-nrpe-to-monitor-remote.html</a>, I will discuss how to monitor remote hosts using Nagios and NRPE.<br />
<br />
Reference: <a href="http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html">http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com2tag:blogger.com,1999:blog-6987378274371810969.post-18442746472184968082013-06-26T11:11:00.003+08:002013-06-26T11:15:13.920+08:00How to setup MySQL replicationMySQL replication is the technique to replicate one mysql database (master) to one or more databases (slave), using replication, we can:<br />
<br />
1) Separate read and write<br />
Write is only done on master server, all the read operations are done one the slave servers. We can also run expensive report on slave servers without affecting the performance of master and other slaves.<br />
<br />
2) backup.<br />
MySQL stores all the files used for database/tables in data/ directory, to backup mysql, we can backup the data/ directory. However backing up data/ while MySQL is running will give us an inconsistent copy of data/. To make consistent backup, we need to stop MySQL first, and this will cause downtime.<br />
In MySQL replication environment, we can stop one slave and do the backup on slaves. Master and other slaves are still online during our backup.<br />
<br />
<br />
To setup MySQL replication, each server in the replication needs to have a unique server-id. The valid range of server-id is 0 to 2^32-1, but replication only allows positive server-id.<br />
<br />
I have 3 servers called: centos, centos-1, centos-2. All servers have MySQL freshly installed.<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# getent hosts | grep centos</span><br />
<span style="font-family: "Courier New",Courier,monospace;">192.168.100.100 centos</span><br />
<span style="font-family: "Courier New",Courier,monospace;">192.168.100.101 centos-1</span><br />
<span style="font-family: "Courier New",Courier,monospace;">192.168.100.102 centos-2</span></blockquote>
<br />
Below are the steps I did to setup replication from centos to centos-1 and centos-2.<br />
1. update /etc/my.cnf and restart MySQL<br />
on centos:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# cat <<EOF > /etc/my.cnf</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[mysqld]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">server-id = 100</span><br />
<span style="font-family: "Courier New",Courier,monospace;">log-bin = master-bin.log </span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF </span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos ~]# service mysql restart</span></blockquote>
<br />
on centos-1:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-1 ~]# cat <<EOF > /etc/my.cnf</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[mysqld]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">server-id = 101</span><br />
<span style="font-family: "Courier New",Courier,monospace;">relay-log-index = slave-relay-bin.index</span><br />
<span style="font-family: "Courier New",Courier,monospace;">relay-log = slave-relay-bin</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=mysql.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=information_schema.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=performance_schema.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-1 ~]# service mysql restart</span></blockquote>
<br />
on centos-2:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-2 ~]# cat <<EOF > /etc/my.cnf</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[mysqld]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">server-id = 102</span><br />
<span style="font-family: "Courier New",Courier,monospace;">relay-log-index = slave-relay-bin.index</span><br />
<span style="font-family: "Courier New",Courier,monospace;">relay-log = slave-relay-bin</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=mysql.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=information_schema.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">replicate-wild-ignore-table=performance_schema.%</span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-2 ~]# service mysql restart</span></blockquote>
<br />
2. Get master bin log and position.<br />
<span style="font-family: "Courier New",Courier,monospace;">mysql> flush table with read lock;<br />Query OK, 0 rows affected (0.00 sec)<br /><br />mysql> show master status;</span><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">+-------------------+----------+--------------+------------------+</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">+-------------------+----------+--------------+------------------+</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">| <b>master-bin.000007</b> | <b>272</b> | | |</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;">+-------------------+----------+--------------+------------------+</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<span style="font-family: "Courier New",Courier,monospace;">1 row in set (0.00 sec)<br /><br />mysql> unlock tables;<br />Query OK, 0 rows affected (0.00 sec)</span><br />
<br />
3. On master, create account used for replication. Slave uses this account to connect to master. Multiple clients can share the same account, we can also create one account for each slave. This account need to have privilege "REPLICATION SLAVE".<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">mysql> CREATE USER <b>'repl'@'%'</b> IDENTIFIED BY '<b>slavepass</b>';</span><br />
<span style="font-family: "Courier New",Courier,monospace;">mysql> GRANT REPLICATION SLAVE ON *.* TO <b>'repl'@'%'</b>;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">mysql> FLUSH PRIVILEGES;</span></blockquote>
<br />
4. Setup slave using the information found in step 2 and 3.<br />
On both centos-1 and centos-2<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">mysql> change master to</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_host='192.168.100.100',</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_port=3306,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_user='<b>rep1</b>',</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_password='<b>slavepass</b>',</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_log_file='<b>master-bin.000007</b>',</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> -> master_log_pos=<b>272</b>;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">mysql> start slave;</span></blockquote>
5. Confirm replication is working:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-1 data]# tail -1 centos-1.err</span><br />
<span style="font-family: "Courier New",Courier,monospace;">130626 9:47:16 [Note] Slave I/O thread: connected to master 'rep1@192.168.100.100:3306',replication started in log 'master-bin.000007' at position 272</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[root@centos-2 data]# tail -1 centos-2.err</span><br />
<span style="font-family: "Courier New",Courier,monospace;">130626 9:48:04 [Note] Slave I/O thread: connected to master 'rep1@192.168.100.100:3306',replication started in log 'master-bin.000007' at position 272</span></blockquote>
<br />
we can also insert some data on master, querying on any slave will show us the data we inserted on master.<br />
<br />
We are done! MySQL replication is up and running.<br />
<br />
reference: <br />
<a href="http://dev.mysql.com/doc/refman/5.6/en/replication-howto.html" target="_blank">http://dev.mysql.com/doc/refman/5.6/en/replication-howto.html</a><br />
<a href="http://top-performance.blogspot.com/2012/03/how-to-setup-mysql-replication-in-11.html" target="_blank">http://top-performance.blogspot.com/2012/03/how-to-setup-mysql-replication-in-11.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-58885219619726683892013-05-26T10:04:00.005+08:002013-06-26T16:04:17.580+08:00bash string manipulationBash supports many ways of string manipulation, it includes substring, substring replacement, substring removal, string length.<br />
<br />
In <a href="http://linuxscripter.blogspot.com/2012/03/massive-rename-files.html" target="_blank">how to rename multiple files in one command</a>, one of the ways I shared to rename *.txt to *.sh is<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">for f in *.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;">do</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> mv $f ${f/.txt/.sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">done</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
<span style="font-family: inherit;">How ${f/.txt/.sh}</span> is doing the magic? Actually this is string replacement in bash.<br />
<br />
<span style="font-family: inherit;">${f/.txt/.sh}</span> means replacing ".txt" in string $f with ".sh", so for f=abc.txt, <span style="font-family: inherit;">${f/.txt/.sh}</span> will produce abc.sh<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ f=abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo $f{f/.txt/.sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
But the example I gave in <a href="http://linuxscripter.blogspot.com/2012/03/massive-rename-files.html" target="_blank">rename multiple files in one command</a> was not so correct.<br />
For f=abc.txt.txt, <span style="font-family: inherit;">${f/.txt/.sh}</span> will produce abc.sh.txt instead of abc.txt.sh<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ f=abc.txt.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo $f{f/.txt/.sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
To correct this, we need to use <span style="font-family: inherit;">${f/%.txt/.sh}</span><br />
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ f=abc.txt.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo $f{f/%.txt/.sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
The syntax of string replacement includes:<br />
1. ${var/Pattern/Replacement} : replacing the first match of "Pattern" with "Replacement"<br />
2. ${var//Pattern/Replacement} : replacing every match of "Pattern" with "Replacement"<br />
3. ${var/#Pattern/Replacement} : if $var starts with "Pattern", replace "Pattern" with "Replacement"<br />
4. ${var/%Pattern/Replacement} : if $var ends with "Pattern", replace "Pattern" with "Replacement"<br />
<br />
Some examples will make the syntax clearer.<br />
<br />
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ f=abc.txt.abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ ### testing syntax 1</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f/txt/sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.sh.abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ ### testing syntax 2</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f//txt/sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.sh.abc.sh</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ ### testing syntax 3, </span><span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f/#txt/sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.abc.txt<br /><br />[linuxscripter@localhost ~]$ ### testing syntax 3,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f/#abc/sh}<br />sh.txt.abc.txt<br /><br />[linuxscripter@localhost ~]$ ### testing syntax 4, </span><span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f/%abc/sh}</span><span style="font-family: "Courier New",Courier,monospace;"><br />abc.txt.abc.txt</span></blockquote>
<blockquote>
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ ### testing syntax 4</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f/%txt/sh}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.abc.sh</span></blockquote>
<br />
At first these syntax may not appear very intuitive, I found this method help to understand and memorize them.<br />
Variable is referred by add '$' infront of it<br />
1. '/' is used for replacement, same as what we do in awk and sed<br />
2. Once we know '/' is for replacement, '//' should be too difficult for us.<br />
3. On keyboard, '#' is at the left of '$', so '#' is used to replace the left side of the variable.<br />
4. On keyboard, '%' is at the right of '$', so '%' is used to replace the right side of the variable.<br />
<br />
Besides string replacement, of course there are a lot more bash can do.<br />
${#var} returns length of $var<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo {#f}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">15</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
${var:pos:len} returns substring of $var, starting at position "pos", with length upto "len", if len is empty or len is too big, return substring starting at position "pos" until to the end of the string.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f:2:5} ${f:2:100} ${f:2}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">c.txt c.txt.abc.txt c.txt.abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
${var#substring} delete shortest match of "substring" from front of $var<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f#abc}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">.txt.abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f#*txt}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">.abc.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
${var##substring} delete longest match of "substring" from front of $var<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f##*abc}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">.txt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
${var%substring} delete longest match of "substring" from back of $var<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f%txt}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.abc.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f%abc*}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.txt.</span></blockquote>
<br />
${var%%substring} delete longest match of "substring" from back of $var<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[linuxscripter@localhost ~]$ echo ${f%%txt*}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">abc.</span></blockquote>
<br />
<a href="http://tldp.org/LDP/abs/html/string-manipulation.html" target="_blank">http://tldp.org/LDP/abs/html/string-manipulation.html</a><br />
<a href="http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=218853&page=7">http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=218853&page=7</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-83772537258071385992013-05-17T23:12:00.001+08:002013-05-18T07:06:28.113+08:00Use HTML pre tag to keep email display formatIn my servers, I have some shell scripts to send system status reports to my email address.<br />
It's very easy to implement, just run script to generage the report and send the report using sendmail, mail, or mailx.<br />
<br />
e.g. if I need to email the output of w, I can simply put it in this way:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">w | mail linuxscripter@myemail.com</span></blockquote>
<br />
but it doesn't have any subject, To fields.<br />
<br />
Personally I prefer sendmail, so I added the email headers in this way.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">(cat <<EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">From: linuxscripter@myserver.com</span><br />
<span style="font-family: "Courier New",Courier,monospace;">To: linuxscripter@myemail.com</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Subject: output of w</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">w)| sendmail -t</span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<br />
This looked pretty ok, and the email displayed nicely in my outlook express 5.<br />
<br />
But in 2006, my company upgraded email client to outlook express 6, all the report format were gone, things should appear in the same column didn't.<br />
<br />
How should I preserve the report format when displayed in outlook express 6?<br />
I worked as a PHP web developer for 3 years, so the first thing came to my mind is html <pre> tag.<br />
To use html tag in email, I need to set the email MIME type as text/html<br />
<br />
This was how I did.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">(cat <<EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">From: linuxscripter@myserver.com</span><br />
<span style="font-family: "Courier New",Courier,monospace;">To: linuxscripter@myemail.com</span><br />
<span style="font-family: "Courier New",Courier,monospace;">Subject: output of w</span><br />
<span style="color: blue;"><span style="font-family: "Courier New",Courier,monospace;">Content-Type: text/html;</span></span><br />
<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;">EOF</span><br />
<span style="font-family: "Courier New",Courier,monospace;">echo "<span style="color: blue;"><html><pre></span>"; w; echo "<span style="color: blue;"></pre></html></span>")| sendmail -t</span></blockquote>
<br />
My email reports became nicely formatted again!Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-90894259337387183622013-04-30T17:24:00.000+08:002013-04-30T17:29:53.130+08:00ESXi: how to install virtual machine using VMware vSphere ClientIn earliest post, I demoed <a href="http://linuxscripter.blogspot.sg/2013/04/how-to-install-vmware-esxi-51-and.html" target="_blank">How to install VMware ESXi 5.1 and vSphere Client</a>.<br />
This articles will show how to create and virtual machine and install centos as guest OS on ESXi host.<br />
<br />
1. Login to VMware vSphere Client<br />
<br />
2. Click "File -> New -> Virtual Machine .." or press ctrl-N.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqp9TMyGMk3Fw75hYGqFQ2uqVUfgG0K5H82DzEzcxolBAEgMdLuUdM0-88Ho73Repz1Ncv3bHEGG26w2MUm9hmvfM1dqmUlPDGc2O18f2Kml_9Ehfc3AkvOimq_x4zh8ogwIB-GBJ7cII/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqp9TMyGMk3Fw75hYGqFQ2uqVUfgG0K5H82DzEzcxolBAEgMdLuUdM0-88Ho73Repz1Ncv3bHEGG26w2MUm9hmvfM1dqmUlPDGc2O18f2Kml_9Ehfc3AkvOimq_x4zh8ogwIB-GBJ7cII/s320/1.png" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
3. Choose Typical configuration. <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRQHIZSGBUQRjozjupEZas29eHYVFa5K-Bw6rBKMAPPk8w9gIgA0rKODSDo0j7Es3FVYCFm9WqAHnXI8oL7ge3-Fi6kNSc2NhbzKagUcZcMftCuZ6STpX6wqaClQMurec_S66fHGPwpDk/s1600/2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="120" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRQHIZSGBUQRjozjupEZas29eHYVFa5K-Bw6rBKMAPPk8w9gIgA0rKODSDo0j7Es3FVYCFm9WqAHnXI8oL7ge3-Fi6kNSc2NhbzKagUcZcMftCuZ6STpX6wqaClQMurec_S66fHGPwpDk/s320/2.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
4. Specify a name for our virtual machine, here I put "vmcentos". <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjan5b1zzLo8UTtBrE7nTQbzePZ5Zwl9G33i6lF6sRgit5Vi4fgvW6w8SX8Ouo2wS9SdgI9Bcw3OlaxAHr8CFMEs1zTrLhdS4JiotiVTwNPd-TIlmqnfX1V4BbKGx03a1TcPQ-SShDIDPk/s1600/3.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="116" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjan5b1zzLo8UTtBrE7nTQbzePZ5Zwl9G33i6lF6sRgit5Vi4fgvW6w8SX8Ouo2wS9SdgI9Bcw3OlaxAHr8CFMEs1zTrLhdS4JiotiVTwNPd-TIlmqnfX1V4BbKGx03a1TcPQ-SShDIDPk/s320/3.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
5. Choose guest OS and version, I am installing centos, so choose "Linux" and "CentOS 4/5/6 (32bit)"<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq4Fr63QkL9Tm3hpWf954Wc6NgQpYFj9vFywM0gV6GubO5rEftRCzWym5vgS_58lvO5oykUbxDs10uTlO47WgpxN10pZv9I6ch-E2uKUh2n0EoXSOpdamlb13wEmUHKcXa0iMvfN7WxFI/s1600/4.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="140" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq4Fr63QkL9Tm3hpWf954Wc6NgQpYFj9vFywM0gV6GubO5rEftRCzWym5vgS_58lvO5oykUbxDs10uTlO47WgpxN10pZv9I6ch-E2uKUh2n0EoXSOpdamlb13wEmUHKcXa0iMvfN7WxFI/s320/4.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
6. Create a disk, I am installing Centos minimal, 5G should be more than enough, leave the other option unchanged. <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyBaf_iHhG-d6f39hjI9cIdeAUjDB3wzr_TEkHsy0d2ASmj-m3014mBCLZSdnBlcI8e32OcyG5ydYsVMZ7HFi42cXUy9i6RtOrZZkWyi_JjZx4i9LX1dZ3eW1U00lMm4vu-10vzWp6770/s1600/5.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="131" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyBaf_iHhG-d6f39hjI9cIdeAUjDB3wzr_TEkHsy0d2ASmj-m3014mBCLZSdnBlcI8e32OcyG5ydYsVMZ7HFi42cXUy9i6RtOrZZkWyi_JjZx4i9LX1dZ3eW1U00lMm4vu-10vzWp6770/s320/5.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
7. Review VM configurations before finishing, attach CD/DVD to the virtual machine. Earlier I have copied CentOS-6.3-i386-minimal.iso into ESXi using winscp, so I just attach the iso file. Under "device status" remember to check "connect at power on" , otherwise VM cannot boot up properly in step 9.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH-OwsUmH4-gQm1SX9Zfd-FF4O-DfyqRItkWQmTReHpGXVCUw_faZCnZY3WWMZet_GFPge4oVvEGdzRGdR7U_VlpcgvOW9f6p8ovZu7IiLOU1BJVHIZJAqULAnjL59hqdhJ8qkoVlTuBY/s1600/6.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH-OwsUmH4-gQm1SX9Zfd-FF4O-DfyqRItkWQmTReHpGXVCUw_faZCnZY3WWMZet_GFPge4oVvEGdzRGdR7U_VlpcgvOW9f6p8ovZu7IiLOU1BJVHIZJAqULAnjL59hqdhJ8qkoVlTuBY/s320/6.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
8. Open VM console: "Inventory -> Virtual Machine -> Open Console" <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-6kRCgV404U3HGAcQHQ14LbT0FXhn_Z3HZyjRcNrhiVrEFkQhwlYYIVBHK-WMc2axRit-vmvrdG6iFW44G0teMFVuJxOA5g9z_dT5s75KrIdgrqZ8LZidImQj9uixmfcoHEj50UR2F6E/s1600/7.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="166" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-6kRCgV404U3HGAcQHQ14LbT0FXhn_Z3HZyjRcNrhiVrEFkQhwlYYIVBHK-WMc2axRit-vmvrdG6iFW44G0teMFVuJxOA5g9z_dT5s75KrIdgrqZ8LZidImQj9uixmfcoHEj50UR2F6E/s320/7.png" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
9. Press green button to boot up VM, alternatively you can click "Inventory -> Virtual Machine -> Power -> Power On" . <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNayZOrCvLCTz3K1aBZswx169Im6gY3zxbYqQqcSx6JfKTN9FGNrRqN0AYxolHXaZ-hMss5gZ4vdGVCzzIbMUpy2zfm3Oosx8Fol65WDkW-DwPw2v1NztgCRXjx-5IqvwlZz8csboXWU8/s1600/8.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNayZOrCvLCTz3K1aBZswx169Im6gY3zxbYqQqcSx6JfKTN9FGNrRqN0AYxolHXaZ-hMss5gZ4vdGVCzzIbMUpy2zfm3Oosx8Fol65WDkW-DwPw2v1NztgCRXjx-5IqvwlZz8csboXWU8/s320/8.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
10. Once we see the CentOS installation page, the following steps should be no difference from installing a physical machine.Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com1tag:blogger.com,1999:blog-6987378274371810969.post-73435280018496173352013-04-24T19:24:00.001+08:002013-04-30T17:32:54.743+08:00How to install VMware ESXi 5.1 and vSphere clientUnlike VMware work station, Virtualbox, ESXi is a bare-metal hyper-visor, which means you don't need an operating system before you can install ESXi.<br />
<br />
This blog article shows how I installed ESXi 5.1. The installation process is quite straight forward, and is quite similar to typical Linux installation.<br />
<br />
There is no spare physical computer for me to test the installation, so I created a VM in my Virtualbox, from Virtualbox I installed ESXi.<br />
<br />
1. First we need to download ESXi from VMware website, the one I downloaded is: VMware-VMvisor-Installer-5.1.0-799733.x86_64.iso<br />
<br />
2. Start machine with the iso downloaded in step 1.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmlxzak_WUYsQirBdVZSlbgtz6xX5FjWZ-2PtOr3ISJYH-WbX8cy_XvfNsjVqi_SE7NV5V0rslQdMlMEE8v_O3pC1PkJpC_NREPwuSUIwVPKauoTSmeHHwBYAh8mF8hKr3QKFev3QZwfI/s1600/1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="174" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmlxzak_WUYsQirBdVZSlbgtz6xX5FjWZ-2PtOr3ISJYH-WbX8cy_XvfNsjVqi_SE7NV5V0rslQdMlMEE8v_O3pC1PkJpC_NREPwuSUIwVPKauoTSmeHHwBYAh8mF8hKr3QKFev3QZwfI/s320/1.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
3. After ESXi installer loaded some stuffs, we are greeted with this welcome screen and End User License Agreement (EULA).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJGh13QYxhQlNKSxNYmS7Y8pBEngrxbqZbjGd4aliW1n8VrQm-oesO6eLbIcfIChXExcVz2N5xA19p4_GASQf5lAmGjGTjfCYPSTinb56pkH416BbazZ4Aps7hVkqWGi58f8PWRTqqQmU/s1600/6.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="138" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJGh13QYxhQlNKSxNYmS7Y8pBEngrxbqZbjGd4aliW1n8VrQm-oesO6eLbIcfIChXExcVz2N5xA19p4_GASQf5lAmGjGTjfCYPSTinb56pkH416BbazZ4Aps7hVkqWGi58f8PWRTqqQmU/s320/6.PNG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieRlvSs5IxgD9u8fZILKZVXrdg9_JMARDrj6A593SZkzLVI7OJKwrVdjJDBwDwCY9lR8QeLKBswQeIVW-W4vJQcj-bX4yuEjRpLduvwcHrRFwRekTlgAU-_0n51GjWoLJZITfHzojcNnM/s1600/7.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieRlvSs5IxgD9u8fZILKZVXrdg9_JMARDrj6A593SZkzLVI7OJKwrVdjJDBwDwCY9lR8QeLKBswQeIVW-W4vJQcj-bX4yuEjRpLduvwcHrRFwRekTlgAU-_0n51GjWoLJZITfHzojcNnM/s320/7.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
4. Select the disk to install ESXi.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzoBGhMSfSvKsc-yoDKC6ZrNlFSHpAJpvYdMM_8psS7VbqyIJTiAV0NtJ3maCU1e8Hfoc8mu1jS8lMzyAjb0jdeNoDO4a92slu2qgF2n5zT4hM1OU41D-eEoVHfKcAqNHIsloazTytv_0/s1600/8.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzoBGhMSfSvKsc-yoDKC6ZrNlFSHpAJpvYdMM_8psS7VbqyIJTiAV0NtJ3maCU1e8Hfoc8mu1jS8lMzyAjb0jdeNoDO4a92slu2qgF2n5zT4hM1OU41D-eEoVHfKcAqNHIsloazTytv_0/s320/8.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
5. Choose keyboard layout <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Hok0pKZMfkPcGHosoBsehkEHDywMd_3FTQsNQ0dzjJ4SWt-1I9Qhu5Xbv8e2jc3mP1GHNWNIH0XZQYL5LI09bLoV2eRMU2xqFRK8T5cK-ThC0tUDov8SIzAVanQ0EW_CUaK8cU7_zXE/s1600/9.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Hok0pKZMfkPcGHosoBsehkEHDywMd_3FTQsNQ0dzjJ4SWt-1I9Qhu5Xbv8e2jc3mP1GHNWNIH0XZQYL5LI09bLoV2eRMU2xqFRK8T5cK-ThC0tUDov8SIzAVanQ0EW_CUaK8cU7_zXE/s320/9.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
6. Set root password<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhObD7Fk-OnqQQSRrGCUINGirZcQW3jjaIV87nkSV-6b53NtmesVWB_pXbBsOIJ7OXL6eP5hhM0XImfO4RirCyOOdD1Y8rslmvX7KJl4jHt4P4VMJ5QIOkzepKc5It8ZCuTgOIz1wGnNdo/s1600/10.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="134" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhObD7Fk-OnqQQSRrGCUINGirZcQW3jjaIV87nkSV-6b53NtmesVWB_pXbBsOIJ7OXL6eP5hhM0XImfO4RirCyOOdD1Y8rslmvX7KJl4jHt4P4VMJ5QIOkzepKc5It8ZCuTgOIz1wGnNdo/s320/10.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
7. Installation started.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUbCmHTlZ89ozuc88q3IVlIIV3u-kPyFy7XzQOcZkFLst10bAGyWSKx6ZkrVPV0ZL5lNhDfFpHGYADrFy-crRZVE2ADT1t-9AKukI-Nc6lpvlOT9AcI34ageMYZSBFi3rlWmeymIVjbPM/s1600/11.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="56" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUbCmHTlZ89ozuc88q3IVlIIV3u-kPyFy7XzQOcZkFLst10bAGyWSKx6ZkrVPV0ZL5lNhDfFpHGYADrFy-crRZVE2ADT1t-9AKukI-Nc6lpvlOT9AcI34ageMYZSBFi3rlWmeymIVjbPM/s320/11.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
8. Installation completed.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0LNlSMCDB7ttf0UrZNLhD8KA8a5rO_us0wCJrkiF7JdsTDwmQ6FTPhn38hYhQiRBj2NKoBe9FmJeP4ILb2-kptGM-OPuNWvdnTqE1rv1b2svujSucNjIc3VDaeJU4p77bPFgcX3rehLU/s1600/12.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="172" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0LNlSMCDB7ttf0UrZNLhD8KA8a5rO_us0wCJrkiF7JdsTDwmQ6FTPhn38hYhQiRBj2NKoBe9FmJeP4ILb2-kptGM-OPuNWvdnTqE1rv1b2svujSucNjIc3VDaeJU4p77bPFgcX3rehLU/s320/12.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
9. Hit Enter to reboot ESXi, after rebooting, we are given this screen.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCTEQCrrFsyoNUo_rHnljXwW47chs3r_9HR7RuICS6Gvv9ywE8bA_CJ2S5D4i_wlffvDcZBdvxI5mL8SK5g4Ju0FOmz68TF5bOHEVPWHHN-OnnXXqcMolIXFSAEPKUkTswVBa-r2fAaXo/s1600/13.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="236" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCTEQCrrFsyoNUo_rHnljXwW47chs3r_9HR7RuICS6Gvv9ywE8bA_CJ2S5D4i_wlffvDcZBdvxI5mL8SK5g4Ju0FOmz68TF5bOHEVPWHHN-OnnXXqcMolIXFSAEPKUkTswVBa-r2fAaXo/s320/13.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
10. Open web browser, key in the URL given in step 9. Click "Download vSpere Client" to install vSphere Client on our windows machine.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4QdRHrZDIYtyoZizQs6SrGo-eBCMQM92hOFMyPS8I2xHthhZ7Rl_j2J0CP-hyBLfHQKXtFtXph0IkFAPw6o1wQMEgnFjoviAlXcarfp-e1oljm7YEx681B6OGhbqtzboEM1ICZwkIaLQ/s1600/15.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="204" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4QdRHrZDIYtyoZizQs6SrGo-eBCMQM92hOFMyPS8I2xHthhZ7Rl_j2J0CP-hyBLfHQKXtFtXph0IkFAPw6o1wQMEgnFjoviAlXcarfp-e1oljm7YEx681B6OGhbqtzboEM1ICZwkIaLQ/s320/15.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
11. Launch vSpere Client, key in the IP adress, username, and password.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM4Vl5DvOfwJYF4QaLgpobaXpZczJDXpS4X2AS2eLbzxldbLjepndvNb-ZpH74WuLwUPxKkWn70RFuzHYFjLHIX_lMRti9rR8K0hpDkNTXLmaeucz686HpV9Yba9AZQRfemxFXRInjk-I/s1600/client.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="285" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM4Vl5DvOfwJYF4QaLgpobaXpZczJDXpS4X2AS2eLbzxldbLjepndvNb-ZpH74WuLwUPxKkWn70RFuzHYFjLHIX_lMRti9rR8K0hpDkNTXLmaeucz686HpV9Yba9AZQRfemxFXRInjk-I/s320/client.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
12. After logging in, a message popup displaying "Your evaluation license will expire in 60 days", for the time being just ignore it first.<br />
We can create or manage VMs on ESXi remotely now!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjunLFSPIM0cP_eUi9C_q-TpyIxWpq7dEN7PM4JfOc1SETrltGJHhWkIMXfVq47G757QTRUPp1dmeSl5Rcoi45e1Ybdk4bEF2ptsXZVenSnDzD9Ra6RrVbq7jpNMSbvcm6yweSGlkYZRAE/s1600/vspere.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="189" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjunLFSPIM0cP_eUi9C_q-TpyIxWpq7dEN7PM4JfOc1SETrltGJHhWkIMXfVq47G757QTRUPp1dmeSl5Rcoi45e1Ybdk4bEF2ptsXZVenSnDzD9Ra6RrVbq7jpNMSbvcm6yweSGlkYZRAE/s320/vspere.PNG" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
13. Once we login vSphere Client, we can create and manage our virtual machines. In <a href="http://linuxscripter.blogspot.sg/2013/04/esxi-how-to-install-virtual-machine.html">http://linuxscripter.blogspot.sg/2013/04/esxi-how-to-install-virtual-machine.html</a>, I will demo how to create VM and install guest OS.<br />
<br />Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com1tag:blogger.com,1999:blog-6987378274371810969.post-13227411509396545722013-04-24T14:51:00.000+08:002013-04-24T14:56:11.252+08:00Expired storage battery causes database performance slowEarly Monday morning, I was told our data warehouse loading process took much longer than before.<br />
The application has been running fine for months, and there was no recent changes made on application, system, or database. The data volume is about the same as before.<br />
AWR reports showed that the bottleneck was on system IO, looks like storage IO performance is much worse than before. So I asked the storage engineer the check storage battery status of StorageTek.<br />
<br />
Yes, our batteres expired!<br />
<br />
Vendor is delivering new batteries for us, replacing batteries should solve our issue.<br />
<br />
A few years ago, when I first started as a DBA, I encountered similar issue on an OLTP database. <br />
All of sudden, one database became very slow. I spent much more time, but still couldn't figure out what went wrong. Only after a few days, our storage engineer noticed the battery expiration in HDS.<br />
After replacing new batteries, database performance became normal again.<br />
<br />
Why expired batteries affect the system I/O?<br />
Joshua Townsend has a very good article on storage basics.<br />
In storage, there is some amount of cache RAM acting as a buffer to physical disks, I/O operations on cache is much faster than the disks.<br />
In case of battery expiration, storage will disable the cache, all the I/O operations directly goes to the disks, which are much slower than cache RAM.<br />
<br />
For details, please visit Joshua's blog:<br />
<a href="http://vmtoday.com/2010/03/storage-basics-part-v-controllers-cache-and-coalescing/">http://vmtoday.com/2010/03/storage-basics-part-v-controllers-cache-and-coalescing/</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-74270288661082289342013-04-12T00:12:00.000+08:002013-04-12T00:12:53.284+08:00How to check NIC speed in UnixFast Ethernet connection is essential for some operations to work properly.<br />backup, oracle RAC all require fast Ethernet connection.<br /><br />Different OS provides different commands to check the network speed currently running.<br /><br />
In Linux, we can run<span style="font-family: "Courier New",Courier,monospace;"> mii-tool</span> or <span style="font-family: "Courier New",Courier,monospace;">ethtool</span> to check the network speed. Both commands require root access<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@localhost eth0]# mii-tool eth0</span><br /><span style="font-family: "Courier New",Courier,monospace;">eth0: no autonegotiation, 100baseTx-FD, link ok</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span></blockquote>
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">[root@localhost eth0]# ethtool eth0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Settings for eth0:</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Supported ports: [ TP ]</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Supported link modes: 10baseT/Half 10baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> 100baseT/Half 100baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> 1000baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Supports auto-negotiation: Yes</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Advertised link modes: 10baseT/Half 10baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> 100baseT/Half 100baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> 1000baseT/Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Advertised pause frame use: No</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Advertised auto-negotiation: Yes</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Speed: 1000Mb/s</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Duplex: Full</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Port: Twisted Pair</span><br /><span style="font-family: "Courier New",Courier,monospace;"> PHYAD: 0</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Transceiver: internal</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Auto-negotiation: on</span><br /><span style="font-family: "Courier New",Courier,monospace;"> MDI-X: Unknown</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Supports Wake-on: umbg</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Wake-on: d</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Current message level: 0x00000007 (7)</span><br /><span style="font-family: "Courier New",Courier,monospace;"> Link detected: yes</span></blockquote>
<br />In Solaris, we can run <span style="font-family: "Courier New",Courier,monospace;">kstat</span> or <span style="font-family: "Courier New",Courier,monospace;">dladm</span> to check the network speed<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ kstat -m igb -i 0 | egrep 'link_autoneg|link_speed|link_duplex'</span><br /><span style="font-family: "Courier New",Courier,monospace;"> link_autoneg 1</span><br /><span style="font-family: "Courier New",Courier,monospace;"> link_duplex 2</span><br /><span style="font-family: "Courier New",Courier,monospace;"> link_speed 100</span></blockquote>
The output shows that, igb0 is running autonegotiation, 100 Mbps full-duplex<br /><br />if we have root access, we can run <span style="font-family: "Courier New",Courier,monospace;">dladm</span> or <span style="font-family: "Courier New",Courier,monospace;">ndd</span> to check the network speed.<br /><br />In AIX, we can run <span style="font-family: "Courier New",Courier,monospace;">entstat</span> to check network speed.<br />if we want to check the speed of en0<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ entstat -d en0 | egrep '^Device|^Media'</span><br /><span style="font-family: "Courier New",Courier,monospace;">Device Type: 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)</span><br /><span style="font-family: "Courier New",Courier,monospace;">Media Speed Selected: Auto negotiation</span><br /><span style="font-family: "Courier New",Courier,monospace;">Media Speed Running: 100 Mbps Full Duplex</span></blockquote>
<br />We can see that en0 supports upto 1000 Mbps, but it's running 100 Mbps Full Duplex.<br /><br />In HP-UX, we can run <span style="font-family: "Courier New",Courier,monospace;">lanadmin</span> or <span style="font-family: "Courier New",Courier,monospace;">nwmgr</span> to check the network speed.<br />lanadmin output is shorter<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ /usr/sbin/lanadmin -x 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Speed = 1000 Full-Duplex.</span><br /><span style="font-family: "Courier New",Courier,monospace;">Autonegotiation = On.</span></blockquote>
<br />we can also use nwmgr to get detailed information<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">$ /usr/sbin/nwmgr --get --stats -C lan -I 0</span><br /><span style="font-family: "Courier New",Courier,monospace;"></span><br /><span style="font-family: "Courier New",Courier,monospace;">*** lan0 64 bit MIB statistics:</span><br /><span style="font-family: "Courier New",Courier,monospace;">Interface Name = lan0</span><br /><span style="font-family: "Courier New",Courier,monospace;">PPA Number = 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Description = lan0 HP PCI 1000Base-T Release B.11.31.0809.01</span><br /><span style="font-family: "Courier New",Courier,monospace;">Interface Type = 1000Base-T</span><br /><span style="font-family: "Courier New",Courier,monospace;">MTU Size = 1500</span><br /><span style="font-family: "Courier New",Courier,monospace;">Speed = 1 Gbps</span><br /><span style="font-family: "Courier New",Courier,monospace;">Station Address = 0x0A527E583C90</span><br /><span style="font-family: "Courier New",Courier,monospace;">Administration Status = UP</span><br /><span style="font-family: "Courier New",Courier,monospace;">Operation Status = UP</span><br /><span style="font-family: "Courier New",Courier,monospace;">Last Change = Wed Mar 20 05:58:50 2013</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Octets = 166627219743</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Unicast Packets = 975967141</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Multicast Packets = 1124454</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Broadcast Packets = 6566058</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Discards = 1821280</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Errors = 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Inbound Unknown Protocols = 1124769</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Octets = 185484791114</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Unicast Packets = 968101273</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Multicast Packets = 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Broadcast Packets = 1618</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Discards = 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Outbound Errors = 0</span><br /><span style="font-family: "Courier New",Courier,monospace;">Counter Discontinuity Time = Wed Mar 20 05:58:50 2013</span><br /><span style="font-family: "Courier New",Courier,monospace;">Physical Promiscuous Mode = FALSE</span><br /><span style="font-family: "Courier New",Courier,monospace;">Physical Connector Present = TRUE</span><br /><span style="font-family: "Courier New",Courier,monospace;">Interface Alias =</span><br /><span style="font-family: "Courier New",Courier,monospace;">Link Up/Down Trap Enable = Enabled</span></blockquote>
<br />Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com0tag:blogger.com,1999:blog-6987378274371810969.post-45801813624344357242013-03-18T23:07:00.000+08:002013-03-18T23:09:06.246+08:00Redhat Linux: how to add/remove hard disk without rebooting serverA few years ago, I managed a few hundred of Redhat Linux servers, most of them are DELL PowerEdge 1750, 1850, and 1950.<br />
Sometimes I needed to move the harddisk between servers. Removing or adding hardisks normally requires system reboot.<br />
But I used this way to remove or add disk without rebooting:<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">echo 'scsi remove-single-device 0 0 1 0' > /proc/scsi/scsi</span><br />
<span style="font-family: "Courier New",Courier,monospace;">echo 'scsi add-single-device 0 0 1 0' > /proc/scsi/scsi</span></blockquote>
<br />
Recently I was asked to add a new harddisk without reboot system. It's a Redhat in VMware, as I was not managing VMware, so not clear about the hostadaptor, SCSI channel, ID, LUN, manipulating /proc/scsi/scsi may not work.<br />
<br />
After searching around I found that I can let system to rescan the SCSI bus.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">for scsi_host in /sys/class/scsi_host/host*</span><br />
<span style="font-family: "Courier New",Courier,monospace;">do</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> echo '- - -' > $scsi_host/scan</span><br />
<span style="font-family: "Courier New",Courier,monospace;">done</span></blockquote>
<br />
After this, I could see the new hard disk was spinned up in /var/log/message.<br />
<br />
Besides 'scsi remove-single-device 0 0 1 0', we can also do it in this way to remove a hard disk.<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New",Courier,monospace;">echo 1 > /sys/block/sdb/device/delete</span></blockquote>
<br />
Reference:<br />
<a href="http://www.tldp.org/HOWTO/archived/SCSI-Programming-HOWTO/SCSI-Programming-HOWTO-4.html">http://www.tldp.org/HOWTO/archived/SCSI-Programming-HOWTO/SCSI-Programming-HOWTO-4.html</a><br />
<a href="http://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-guest.html">http://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-guest.html</a>Gao Ruifenghttp://www.blogger.com/profile/04264479712940228683noreply@blogger.com1