2011年4月25日 星期一

CentOS 5.6 / LVM 調整

模擬環境: 新增一顆硬碟 , 將他加入現有之LVM , 並加大目前LVM之容量


 


[root@mt ~]# fdisk -l


Disk /dev/hda: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14       10011    80308935   8e  Linux LVM


Disk /dev/hdb: 122.9 GB, 122942324736 bytes
16 heads, 63 sectors/track, 238216 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes


   Device Boot      Start         End      Blocks   Id  System


 



[root@mt ~]# fdisk /dev/hdb


The number of cylinders for this disk is set to 238216.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-238216, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-238216, default 238216):
Using default value 238216


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@mt ~]# partprobe


 




[root@mt ~]# pvdisplay
  /dev/hdd: open failed: No medium found
  --- Physical volume ---
  PV Name               /dev/hda2
  VG Name               VolGroup00
  PV Size               76.59 GB / not usable 26.69 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              2450
  Free PE               0
  Allocated PE          2450
  PV UUID               dfXZbc-pfev-YMTz-XfiR-BveL-HUrl-fmd7Fu


[root@mt ~]# pvcreate /dev/hdb1
  Physical volume "/dev/hdb1" successfully created
[root@mt ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/hda2
  VG Name               VolGroup00
  PV Size               76.59 GB / not usable 26.69 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              2450
  Free PE               0
  Allocated PE          2450
  PV UUID               dfXZbc-pfev-YMTz-XfiR-BveL-HUrl-fmd7Fu


  "/dev/hdb1" is a new physical volume of "114.50 GB"
  --- NEW Physical volume ---
  PV Name               /dev/hdb1
  VG Name
  PV Size               114.50 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               f82VID-oKsl-ShjT-BZed-enmP-Tum4-ZbAIpM


 


加大VG及調整LV


以上步驟已用fdisk新增一LVM分割區 /dev/hdb1 並利用 pvcreate 轉成 PV


[root@mt ~]# vgdisplay


  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               76.56 GB
  PE Size               32.00 MB
  Total PE              2450
  Alloc PE / Size       2450 / 76.56 GB
  Free  PE / Size       0 / 0
  VG UUID               yd3K0H-5IWd-N5AX-q5dZ-j9MP-2xHh-4qPRj2


[root@mt ~]# vgextend VolGroup00 /dev/hdb1
  Volume group "VolGroup00" successfully extended
[root@mt ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               191.03 GB
  PE Size               32.00 MB
  Total PE              6113
  Alloc PE / Size       2450 / 76.56 GB
  Free  PE / Size       3663 / 114.47 GB
  VG UUID               yd3K0H-5IWd-N5AX-q5dZ-j9MP-2xHh-4qPRj2



[root@mt ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                41mdX5-GhDO-8xUU-cqY8-SrMr-HfME-EnkfsL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                74.62 GB
  Current LE             2388
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                4k7mr6-1qkt-5p35-6oD7-IwPB-lN3V-ixf56I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


 


 




[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       73G  2.7G   66G   4% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


[root@mt ~]# cat /etc/fstab


/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0


[root@mt ~]# lvextend -L +100G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 174.62 GB
  Logical volume LogVol00 successfully resized


 



[root@mt ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                41mdX5-GhDO-8xUU-cqY8-SrMr-HfME-EnkfsL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                174.62 GB
  Current LE             5588
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                4k7mr6-1qkt-5p35-6oD7-IwPB-lN3V-ixf56I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       73G  2.7G   66G   4% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


 


 




[root@mt ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 45776896 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 45776896 blocks long.


 


 




[root@mt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      170G  2.8G  158G   2% /
/dev/hda1              99M   19M   76M  20% /boot
tmpfs                 489M     0  489M   0% /dev/shm


 


 


2011年4月18日 星期一

CentOS 新增第三方 yum Repositories

CentOS在套件管理上和Fedora相比


預設的repositories 只有放官方測試過的程式


有些好用的軟體都必須自己去抓source下來編譯安裝


所以我們可以新增一個第三方repositories 去擴充 yum 可用的套件


至於有那些repositories可用,


可參考CentOS 官方 wiki : http://wiki.centos.org/AdditionalResources/Repositories


 


以下介紹 rpmforge 的安裝方式


1.  先確認系統核心


# uname -i
x86_64 

 


2. 下載對應核心版本 rpm forege 



# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

 


3. 匯入DAG's GPG KEY


# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt


4. 驗證下載的rpm來源是否正確


# rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK


5.  安裝 rpmforge 


# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.*.rpm
Preparing...                ########################################### [100%]
   1:rpmforge-release       ########################################### [100%]
 


6. 測試yum reposititores 是否已加入 rpmforge


# yum clean all

隨便下指令安裝個什麼東西來看看是否已加入成功


# yum install htop
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror01.idc.hinet.net
 * base: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * rpmforge: fr2.rpmfind.net
 
* updates: mirror01.idc.hinet.net
addons                                                             |  951 B     00:00
addons/primary                                                     |  204 B     00:00
atrpms                                                             | 3.0 kB     00:00
atrpms/primary_db                                                  | 1.2 MB     00:02
base                                                               | 2.1 kB     00:00
base/primary_db                                                    | 2.2 MB     00:02
extras                                                             | 2.1 kB     00:00
extras/primary_db                                                  | 241 kB     00:00
rpmforge                                                           | 1.1 kB     00:00
rpmforge/primary                                                   | 2.2 MB     00:03
rpmforge                                                                      10480/10480

updates                                                            | 1.9 kB     00:00
updates/primary_db                                                 | 335 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package htop.x86_64 0:0.9-1.el5.rf set to be updated
--> Finished Dependency Resolution


Dependencies Resolved


==========================================================================================
 Package          Arch               Version                   Repository            Size
==========================================================================================
Installing:
 htop             x86_64             0.9-1.el5.rf              rpmforge              84 k


Transaction Summary
==========================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)


Total download size: 84 k
Is this ok [y/N]:

 


這樣就完成囉!


 


2011年4月17日 星期日

CentOS 5.5 設定SNMP

學校最近在測What's UP


於是找了一台Linux來設定SNMP測試看看 :)


 


1. 使用yum 安裝 snmp 相關套件


# yum -y install net-snmp net-snmp-utils


 


第一步驟安裝完,使用預設的設定檔啟動snmp就可以了


設定檔的位置在 /etc/snmp/snmpd.conf


2. 啟動snmp


# service snmp start


 


3. 檢查snmp 啟動狀態


3.1 使用 snmpwalk 工具測試


# snmpwalk -c public -v 2c localhost system


3.2 檢查port是否開啟
# netstat -tnlup | grep snmpd
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      7279/snmpd
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               7279/snmpd


2011年4月6日 星期三

no available legacy port

學校的NAT主機壞了,臨時抓了一台PC裝CentOS5.5 做NAT


安裝的時候就有跑出怪怪的訊息,但我沒理他


格式化的時候特別慢


結果裝好重開機後再核心的地方就出現錯誤訊息了 : no available legacy port


跑起來也頓頓的


查了一下google的結果是說有些PC裝centos會誤把SATA硬碟認成IDE硬碟,


於是去看了一下 /dev 的裝置, 果然把硬碟認成hdx


解決的方式是修改開機核心參數,在kernel 那一行的最後面加入 ide0=noprobe ide1=noporbe ....


重開後再檢查一次 /dev 下面的裝置 , 終於出現sdx了 :)


跑起來也順多了


沒問題後就把參數寫入 /etc/grub.conf 


解決!


 


 


2011年4月5日 星期二

CentOS 做 NAT

本教學只做實際設定範例,詳細原理可以參考鳥哥的Linux網站 http://linux.vbird.org/


環境設定:


先設定好兩張網路卡的IP和網段,所有區網內的IP從eth1這個介面(private ip)進來,由eth0介面(public ip)出去


第一張網卡 eth0 : 


ip : 192.192.249.1
netmask : 255.255.255.0
brocast : 192.192.249.255
gateway : 192.192.249.254


第二張網卡 eth1:


ip : 192.168.100.1
netmask : 255.255.255.0
brocast : 192.168.1.255


1. 設定網路介面


# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.192.114.1
NETMASK=255.255.255.0
NETWORK=192.192.114.0
BROADCAST=192.192.114.255
ONBOOT=yes
GATEWAY=192.192.114.254


# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.100.1
NETMASK=255.255.255.0
NETWORK=192.168.100.0
BROADCAST=192.168.100.255
ONBOOT=yes


2. 開啟封包轉送


# echo "1" > /proc/sys/net/ipv4/ip_forward


3. 設定SNAT


# iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j SNAT --to 192.192.114.1


4. 檢查路由


[root@NAT ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
61.221.253.160  0.0.0.0         255.255.255.224 U     0      0        0 eth1
192.168.100.0   0.0.0.0         255.255.252.0   U     0      0        0 eth0
0.0.0.0         61.221.253.161  0.0.0.0         UG    0      0        0 eth1


 


5. 將設定寫入scripts , 並設定開機自動執行


以上測試成功後就把它寫成scripts讓電腦開機時自動執行


# vim /etc/rc.d/rc.local


/root/firewall.sh


# touch /root/firewall.sh


# chmod +x /root/firewall.sh


# vim /root/firewall.sh


#!/bin/bash


# 開啟封包轉送


echo "1" > /proc/sys/net/ipv4/ip_forward


# 清除防火牆規則


for table in filter nat mangle


do


 iptables -t $table -F


iptables -t $table -X


iptables -t $table -Z


done


# 設定NAT


iptables -t nat -A POSTROUTING -s 10.1.100.0/24 -o eth0 -j SNAT --to 192.192.114.1


2011年4月3日 星期日

TeamViewer 6 安裝教學

TeamViewer 和傳統的遠端連線軟體相比他是扮演一個中介者的腳色,


因此可以不受防火牆的限制,便可達到遠端連線之功能


2011年3月6日 星期日

Ubuntu安裝vncserver

Ubuntu 安裝 vncserver 實在是太快速了...


什麼時候centos也可以進化一下啊...囧rz


 


Step1. 安裝 tightvncserver


# sudo apt-get install tightvncserver


 


Step2. 切換成一般使用者 , 並建立vnc 密碼


$ vncserver


You will require a password to access your desktops.



Password:
Verify:
Would you like to enter a view-only password (y/n)? n
xauth:  creating new authority file /home/james/.Xauthority


New 'X' desktop is ubuntu:1


Creating default startup script /home/james/.vnc/xstartup
Starting applications specified in /home/james/.vnc/xstartup
Log file is /home/james/.vnc/ubuntu:1.log


之前在CentOS/Fedora 的 vnc 那篇文章作的一堆步驟他一次就搞定了 ....


Step 3.  於VNC Client端執行VNC Viewer連到IP:5901( 預設port )


影像 1.png 


 


影像 2.png 


 


影像 3.png 


如何在 golang 裡面引用 gitlab private repo

參考文章:https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository 原文是用 gitlab.company.com 當範例,這邊改成一般帳號...