2014年4月16日 星期三

建制伺服器

TFTP伺服器

請執行底下指令以安裝 tftp 套件:

# apt-get install tftpd-hpa

# wget ftp://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/netboot.tar.gz

如出現 ping 8.8.8.8 [正常] 而 ping www.google.com [失敗]
錯誤訊息例 : know host www.google.com 則輸入:

# echo "nameserver 120.117.2.1" >> /etc/resolv.conf

然後將 netboot.tar.gz 解開在 /srv/tftp 目錄,指令如下:

# tar xfva netboot.tar.gz -C /srv/tft

# /etc/init.d/tftpd-hpa restart

[ ok ] Restarting HPA's tftpd: in.tftpd.

DHCP伺服器

先要安裝 isc-dhcp-server 套件
# apt-get install isc-dhcp-server

在/etc/dhcp/dhcpd.conf 加入以下


option domain−name " example . org " ;
option domain−name−servers 8.8.8.8;

default−lease−time 600;
max−lease−time 7200;
allow booting ;

subnet 192.168.10.0 netmask 255.255.255.0{
range 192.168.10.100 192.168.10.200;
option subnet−mask 255.255.255.0;
option broadcast−address 192.168.10.255;
option routers 192.168.10.1;
option domain−name−servers 8.8.8.8;
next−server 192.168.10.254;
filename "pxelinux.0";
}

# /etc/init.d/isc-dhcp-server restart
# update-rc.d isc-dhcp-server defaults

發生問題 :

在/etc/default/isc-dhcp-server增加下列

INTERFACES="eth0"

apache 伺服器

# apt-get install apache2 \Enter

# mkdir -p /var/www/debian

# fidsk -lu
  會發現2G的deb_mirror.img掛載在/dev/sdb1

# blkid /dev/sdb1 \Enter
  找出UUID

在 /etc/fstab 底下新增
UUID=b43e1707-19c5-42cb-9424-f4bf7118d39a /var/www/debian ext4 defaults 0 2

或者

UUID=sdb1 /var/www/debian ext4 defaults 0 2

 # /etc/init.d/apache2 restart \Enter
[ ok ] Restarting web server: apache2 ... waiting .

# mount /dev/sdb1 /var/www/debian

SSH 執行問題


WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!    

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
0d:4f:e1:7f:e3:29:14:4a:98:68:97:4e:65:86:a0:ed.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:1
ECDSA host key for 192.168.10.254 has changed and you have requested strict checking.
Host key verification failed.
root@nora:/test# sh clear_iptable.sh
root@nora:/test# ssh -l -L 192.168.10.254

如果出現以上訊息

就刪除以下檔案
/root/.ssh/known_hosts

shell script

建置PXE環境

-----------------------buildpxe.sh---------------------------
#IP=192.168.2.254 pxeserver.example.org
CPU=host
SMP=2
MEMORY=1024
HDA=pxeserver.img
MAC="DE:AD:BE:CF:EC:B7"
BRIDGE=br10
CDROM=/test/debian-7.4.0-i386-netinst.iso

qemu-system-x86_64 -enable-kvm -cpu $CPU -smp $SMP -m $MEMORY \
-hda $HDA \
-cdrom $CDROM -boot d \
-net nic,macaddr=$MAC -net bridge,br=$BRIDGE
-------------------------------------------------------------

執行PXE 伺服器

------------------------runpxe.sh----------------------------
#IP=192.168.10.254
# PXE Server
CPU=host
SMP=2
MEMORY=1024
HDA=pxeserver.img
HDB=deb_mirror.img
MAC="DE:AD:BE:CF:EC:B7"
BRIDGE=br10
CDROM=/test/debian-7.4.0-i386-netinst.iso


qemu-system-x86_64 -enable-kvm -cpu $CPU -smp $SMP -m $MEMORY \
-hda $HDA \
-hdb $HDB \
-cdrom $CDROM \
-net nic,macaddr=$MAC -net bridge,br=$BRIDGE                               
-------------------------------------------------------------
檢察IPv4規範
---------------------check_ip_forward.sh------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
-------------------------------------------------------------

清除防火牆規則

----------------------clear_iptable.sh-----------------------
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
-------------------------------------------------------------

增加防火牆規則 [ 什麼都不檔 ]

-----------------------out_iptable.sh------------------------
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j MASQUERADE
-------------------------------------------------------------

在這裡就可以進行CLI連接PXE server
# SSH -L 連接地帳號 192.168.10.254

執行使用者安裝

-----------------------runlinux.sh------------------------
CPU=host
SMP=2
MEMORY=1024
HDA=linux.img
MAC="DE:AD:BE:EF:EC:A8"
BRIDGE=br10

qemu-system-x86_64 -enable-kvm -cpu $CPU -smp $SMP -m $MEMORY \
-hda $HDA \
-net nic,macaddr=$MAC -net bridge,br=$BRIDGE \
-------------------------------------------------------------

2014年4月1日 星期二

遠端連線

ssh >>>遠端連線指令
用法
# ssh -l 帳號 主機

查帳號指令
# whoami

查主機名稱指令
# hostname

如果在虛擬機使用則內外都要
# apt-get install ssh

# rsync  >>> 遠端拿文件指令

# rsync -av 來源帳號@主機來源資料 目的地

如果有重複 則直接覆蓋
在最後加上-- delete
則會把多餘的刪除



一切的開頭


這是一個專注於 Linux 與個人學習經驗的部落格,
我會陸陸續續將我的個人經驗上傳與讀者分享。

向我的LINUX啟蒙老師 - Dr.Lee 致敬


我正在朝 RHCE 為目標努力
這不是一張有標的性 指標 成果的證照

不過 卻是我邁向LIUUX世界的一大步
接下來 我會撰寫一些LINUX與其他程式語言等等的學習心得