2015年8月25日 星期二

PXE Automated Install OS(Preseed)


影片Demo:https://youtu.be/_tEx_A1ZzBU


一、Mirror 鏡像站

1. 準備 200 GB 以上之硬碟空間,並建立裝鏡像站之目錄
mkdir -p /home/ftp

2. 寫一個 getdeb.sh
# 選擇一個外站來下載
HOST=ftp.tw.debian.org
#HOST=debian.nctu.edu.tw
#HOST=opensource.nchc.org.tw
#HOST=ftp.wa.au.debian.org
#HOST=120.117.72.71
#HOST=ftp.debian.org

debmirror \
        --arch=i386,amd64,armel,armhf,sha4 \
        --dist=jessie,jessie-updates \
        --di-arch=i386,amd64,armel \
        --di-dist=stable \
        --host=$HOST \
        --root=":debian" \
        --diff=none -p \
        --nosource \
        --method=rsync \
        --section main,contrib,non-free,main/debian-installer \
        --i18n \
        --ignore-release-gpg /home/ftp/debian/ ;

        #--section non-free,contrib,main,main/debian-installer,main/installer-armel,main/i18n,main/source \
#debmirror \
#       -v --nosource -d lenny/updates -a i386 \
#       -s non-free,contrib,main,main/debian-installer \
 #    --method=http -h security.debian.org \
 #    --ignore-release-gpg -r /debian-security /home/ftp/debian/security/
#       --section main,contrib,non-free,main/debian-installer,main/installer-armel,main/i18n,main/source \

#wget -r -l1 -nH ftp://$HOST/debian/dists/squeeze/main/source/
date

3. 將鏡像站載到 /home/ftp/debian 目錄下 
sh getdeb.sh

4. 修改/home/ftp/debian所有檔案權限
DIR=/home/ftp/debian
chown root.root -Rv $DIR
chmod ug-s -Rv $DIR
find $DIR -type -d -exec chmod 755 {} +
find $DIR -type -f -exec chmod 644 {} +

5. 修改 sources.list 檔:
cat >> /etc/apt/sources.list << EOF
deb ftp://localhost/debian jessie main contrib non-free
 deb-src ftp://localhost/debian jessie main contrib non-free
EOF

6. 測試更新
apt-get update

7. 若出現 installer 或 source… 缺少檔案,請自行去別的鏡像站補檔案到對應的目錄。
=============================================================

二、建立私有網路 192.168.10.0/24

1. 將建置環境之對外網路線先移除,
其他含有 DHCP Server 相關的設備也移除 (例如 WiFi 基地台)。

2. PXE Server 端,修改網路設定
vi /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

########## Eth0/DHCP ##########
#allow-hotplug eth0
#iface eth0 inet dhcp

########### PXE Server Machine ##########
allow-hotplug eth0
iface eth0 inet static
        address 192.168.10.254
        netmask 255.255.255.0
        network 192.168.10.0
        broadcast 192.168.10.255
        gateway 192.168.10.1

3. 重啟網卡
/etc/init.d/networking restart

4. 確認網路設定成功,若沒有出現 ip:192.168.10.254,再多重啟幾次。
/sbin/ifconfig
=============================================================

三、FTP / NFS /HTTP Server(擇一,本例使用 FTP)

‧FTP Server

1. 安裝
sudo apt-get install proftpd-basic

2.修改設定檔 /etc/proftpd/proftpd.conf
 sudo vi /etc/proftpd/proftpd.conf

搜尋 Anonymous ,解除註解,完成如下結果:
<Anonymous ~ftp>
   User                         ftp
   Group                                nogroup
   # We want clients to be able to login with "anonymous" as well as "ftp"
   UserAlias                    anonymous ftp
   # Cosmetic changes, all files belongs to ftp user
   DirFakeUser  on ftp
   DirFakeGroup on ftp

   RequireValidShell            off

   # Limit the maximum number of anonymous logins
   MaxClients                   10

   # We want 'welcome.msg' displayed at login, and '.message' displayed
   # in each newly chdired directory.
   DisplayLogin                 welcome.msg
   DisplayChdir         .message

   # Limit WRITE everywhere in the anonymous chroot
   <Directory *>
     <Limit WRITE>
       DenyAll
     </Limit>
   </Directory>

   # Uncomment this if you're brave.
   # <Directory incoming>
   #   # Umask 022 is a good standard umask to prevent new files and dirs
   #   # (second parm) from being group and world writable.
   #   Umask                            022  022
   #            <Limit READ WRITE>
   #            DenyAll
   #            </Limit>
   #            <Limit STOR>
   #            AllowAll
   #            </Limit>
   # </Directory>

 </Anonymous>

3.修改 /etc/passwd 設定
 sudo vi /etc/passwd

搜尋 ftp ,將其中的目錄路徑改為自訂 FTP 目錄 (例如: /home/ftp)
瀏灠器測試 ftp://192.168.10.254
-------------------------------------------------------------------------------------------------

‧NFS Server


‧PXE Server
1. 安裝 
sudo apt-get install nfs-kernel-server

2. 設定 
sudo vi /etc/exports
/srv/nfs 192.168.10.0/24(rw,no_root_squash,async,no_subtree_check)

3. 重啟
exportfs -rav
/etc/init.d/nfs-kernel-server restart

4. 檢查 
showmount -e localhost
正確輸出:
Export list for localhost:
/srv/nfs 192.168.10.0/24

‧NFS Client
1. Client 端套件安裝
sudo apt-get install nfs-common

2.建立掛載 NFS 目錄
mkdir -p /dev/nfs

3. 手動掛載 
mount -t nfs -nolock 192.168.10.1:/srv/nfs /dev/nfs
-------------------------------------------------------------------------------------------------

‧HTTP Server

1. 安裝
sudo apt-get install apache2

2. 修改 
vi /etc/apache2/apache2.conf`
<Directory /home/ftp>
        Options Indexes
        AllowOverride None
        Require all granted
</Directory>

3. 修改 
vi /etc/apache2/sites-available/000-default.conf`
 #DocumentRoot /var/www/html
 DocumentRoot /home/ftp

4. 重啟 
/etc/init.d/apache2 restart
=============================================================

四、DHCP Server

1. 安裝
sudo apt-get install isc-dhcp-server

2. 設定
vi /etc/dhcp/dhcpd.conf
option domain-name "example.org";
option domain-name-servers 120.117.2.1;
#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 120.117.2.1;
        next-server 192.168.10.254;
        filename "pxelinux.0";
}

3. 重啟
/etc/init.d/isc-dhcp-server restart
systemctl enable isc-dhcp-server
systemctl status isc-dhcp-server
=============================================================

五、TFTP Server

1. 安裝
sudo apt-get -y install tftpd-hpa

2.設定
vi /etc/default/tftpd-hpa
TFTP_RUN_DAEMON="yes"
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

3. 下載開機套件
wget http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz

4. 確立 /srv/tftp 目錄存在
mkdir -p /srv/tftp

5. 解壓至 tftp 目錄 
tar xfva netboot.tar.gz -C /srv/tftp

6. PXE 開機選單訊息(自行定義)  
vi /srv/tftp/boot.msg
        =========================
        |            INSTALL MENU              |
        =========================

        Choose installation type:

        0  Local Boot(Default)
        1  PXE Manual Install Debian/Jessie
        2  PXE Automated Install Debian/Jessie
        =========================

7. 原檔備份
mv /srv/tftp/pxelinux.cfg/default /srv/tftp/pxelinux.cfg/default.bak

8. PXE 開機選單  
vi /srv/tftp/pxelinux.cfg/default
DISPLAY boot.msg
PROMPT 1
timeout 3000

default 0

LABEL 0
        localboot 0

LABEL 1
        kernel debian-installer/amd64/linux
        append vga=normal initrd=debian-installer/amd64/initrd.gz --

LABEL 2
        kernel debian-installer/amd64/linux
        append vga=normal initrd=debian-installer/amd64/initrd.gz auto=true priority=critical url=http://192.168.10.254/preseed.cfg interface=eth0

9. 權限o+rx  
chmod -Rv 755 /srv/tftp

10. 重啟
 /etc/init.d/tftpd-hpa restart
 update-rc.d tftpd-hpa defaults
 systemctl enable tftpd-hpa
=============================================================

六、自動安裝設定 Preseed

#http://www.unt.edu/benchmarks/archives/2008/may08/auto_install_howto-2.pdf
#https://www.youtube.com/watch?v=YT7qUoEw0BY
#http://pastebin.com/jadh4U5n
#https://www.debian.org/releases/jessie/example-preseed.txt


 vim /home/ftp/preseed.cfg

#https://www.debian.org/releases/jessie/example-preseed.txt
# Localization
d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/layoutcode string us

 # Networking
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

 # APT Mirror
d-i mirror/country string enter information manually
d-i mirror/http/hostname string ftp://192.168.10.254
d-i mirror/http/directory string /debian
#d-i mirror/suite string default
d-i mirror/http/proxy string

 # Timezone / Time
d-i clock-setup/utc boolean false
d-i time/zone string Asia/Taipei
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server tick.stdtime.gov.tw

 # Partitoning
# # https://wikitech.wikimedia.org/wiki/PartMan/Auto 
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
#    
d-i partman-auto/expert_recipe string   \
root ::                                 \
        5000 25000 -1 ext4              \
        $primary{ }                     \
        $bootable{ }                    \
        method{ format }                \
        format{ }                       \
        use_filesystem{ }               \
        filesystem{ xfs }               \
        mountpoint{ / }                 \
        .                               \
        1024 2048 8192 linux-swap       \
        $primary{ }                     \
        method{ swap }                  \
        format{ }                       \
        .

d-i partman-auto/choose_recipe select root
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean false
d-i partman/choose_partition select "Finish partitioning and write changes to disk"

# Grub Install
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev  string /dev/sda

# Account(s) setup
# ROOT
d-i passwd/root-login boolean true
d-i passwd/root-password password abc123
d-i passwd/root-password-again password abc123
# USER
d-i passwd/make-user boolean true
d-i passwd/user-fullname string student
d-i passwd/username string student
d-i passwd/user-password password abc123
d-i passwd/user-password-again password abc123
d-i user-setup/allow-password-weak boolean true
#d-i passwd/user-default-groups string users,audio,cdrom,video
#d-i passwd/user-uid string 1001

# tasksel / extra APT packages
#tasksel tasksel/first multiselect standard
tasksel tasksel/first multiselect minimal
d-i pkgsel/include string \
ssh sshpass sudo aptitude vim ntp rsync

popularity-contest popularity-contest/participate boolean true

# run shell script
d-i preseed/late_command string                         \
in-target wget ftp://192.168.10.254/env.sh -P /root/;   \
in-target /bin/chmod 700 /root/env.sh;                  \
in-target /bin/sh /root/env.sh

=============================================================

七、新機環境設定

自訂義於 /home/ftp/env.sh

#!/bin/bash
# KLin
# 2015/08/25

USER=student

# login directory: /root
cd /root/

# APT Package updates
#apt-get update

# sshd server
#apt-get -y install ssh sshpass rsh
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
mkdir -p /root/.ssh

## 使用 `ssh-keygen` 指令生成公鑰,Copy 起來
#cat >> /root/.ssh/authorized_keys << EOF
#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLDfPtWH2zTq92nfsml5i6agoXWQRBzsb9VJzKGwY/jyPfyIL7rl+Q#hD4oGxDLW3pNmtflAkQ3/X3W8j/o7tW14Sdw2eW5HRl2Um2eSa9q2BWHbzT464R+xlGgAI3iUH0yPRgW602EYzeCZi3/#8zSoVHMVrjsZyjOzz5n+EFbNsirVtSOndF9iXa2ByT1GuxjOobBWoIue5/1jb7B8pG6QlRAf6kz0x/1xLWASiBmMaLPf#mHbQ5xvgBFbSOQTTG7vRevuVrpBaUdEHEGiRMY4TS8o/2bOzAoCa9hgCcxb1N3Ys/AKbwU00yWGUSKqhTK93tpbSsUmG#34MaDGmMWmfz root@KaiLin

#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCllLrsVt7koI6q/erYCUubKW2fxHRGYB4xYkY7LacPxiSexnvrX6yk#vRQbWcEOtNig2SXZJ6NwJWIDnkAfehVLbYWSu1S4MfPMzPLQVQryAQxf3oajyLAg+D64QGeBfDmScJ0LIBwPJq9/oqSI#4QgiMUXjj+9kBn6VBzGaB9h2u6AN1YYRJYJbKHFt4mxiqbXuXalw2fC0VWoerp9La9weozvCWOXeuxL6SCYPyTcIDqQ7#t9hSvH93af6HqNtcBr0WzmrYdrVRyNW5KbCD0IFf35yOogzrAon86MVjReVAF2gLHnFYz+bjH4DstcRAAZgJTvT4HGuA#cGqrfXf11RhZ root@120-117-73-86
#EOF

# Black List
cat >> /etc/modprobe.d/fbdev-blacklist.conf << EOF 
blacklist nouveau
blacklist nv
blacklist ast
EOF

# Setting `sudo` 
echo "$USER     ALL=(ALL:ALL) ALL" >> /etc/sudoers

# .bashrc & .vimrc
for ACCOUNT in /root /home/$USER
do
# set .bashrc
cat >> $ACCOUNT/.bashrc << EOF
# Language Setting "zh.TW.UTF-8"
export LC_ALL=zh_TW.UTF-8
export LANG=zh_TW.UTF-8
export LANGUAGE=zh_TW.UTF-8

# define more command aliases
alias ls='ls -F --color=auto'
alias l='ls -lF --color=auto'
alias ll='ls -lF --color=auto'
alias lt='ls -lt --color=auto'
alias la='ls -aF --color=auto'
alias lh='ls -lhF --color=auto'
alias lz='ls -lZF --color=auto'
alias grep='grep --color=auto'
alias vi='vim'
alias df='df -h'
alias ifconfig='/sbin/ifconfig'
EOF

# set .vimrc
cat >> $ACCOUNT/.vimrc << EOF
set hlsearch
set bg=dark
syntax on
EOF
done

# end test
touch /root/env_run.ok

# Other shell...

=============================================================

八、遠端控制 rsh + sshpass

※ 注意,使用 rsh  時,Server 與 Client 必需有相同之使用者帳號,
若 Server 端使用 root 權限,則 rsh 所執行的指令於 Client 端也為 root 權限。

1. 於 server 端發遠端指令的方法參考 http://jamyy.us.to/blog/2013/08/5260.html 

2. 安裝
apt-get install sshpass rsh

3. 遠端 ssh 第一次,無需打 yes ,自動更新 known_hosts 檔方法:
建一設定檔於 PXE Server 端: /root/.ssh/config
StrictHostKeyChecking no

4 遠端下指令,注意目前執行 rsh 的使用者權限:
sshpass -p <密碼> rsh <主機 IP> <指令> &

※令 ssh 連線無需輸入密碼
於 PXE Server 端,指令` ssh-keygen `產生 public key ,
並 copy 至 Client 端:/root/.ssh/authorized_keys (自行建立)的檔案內。

=============================================================

九、Reference:

http://www.unt.edu/benchmarks/archives/2008/may08/auto_install_howto-2.pdf 

https://raymii.org/s/articles/virt-install_introduction_and_copy_paste_distro_install_commands.html 

http://www.tecmint.com/multiple-centos-installations-using-kickstart/# 

http://ubuntuforums.org/showthread.php?t=1463142 

http://www.syslinux.org/wiki/index.php/Comboot/menu.c32 

http://wiki.hackzine.org/sysadmin/debian-pxe-server.html 

http://www.iram.fr/~blanchet/tutorials/read-only_diskless_debian7.pdf 

https://www.debian.org/releases/jessie/amd64/ch04s05.html.en 

https://www.debian-administration.org/article/478/Setting_up_a_server_for_PXE_network_booting 

http://linux.vbird.org/somepaper/20100901-pxe_ks.pdf 

http://linux.vbird.org/somepaper/20101020-pxe_ks_2.pdf

https://help.ubuntu.com/community/DisklessUbuntuHowto 

https://www.debian.org/releases/jessie/example-preseed.txt 

2015年8月23日 星期日

JAVA SL-110_08/23

// InterfaceMember.java

interface Surfacing{
        double pi=3.14159;
        double area();
}

class Shap{
        protected double x, y;
        Shap(double x, double y){
                this.x = x;
                this.y = y;
        }

        public String toString(){
                return "圖形原點:("+ x +", " + y + ")";
        }
}

class Ccircle extends Shap implements Surfacing{
        private double r;
        public Ccircle(double x, double y, double r){
                super(x,y);
                this.r = r;
        }

        public double area(){
                return pi * r * r;
        }

        public String toString(){
                return "圓心:(" + x + "," + y + "),半徑:" + r + ",面積:" + area();
        }
}

public class InterfaceMember{
        public static void main(String args[]){
        Ccircle c = new Ccircle(3, 5, 6);
        System.out.println(c.toString());
        System.out.println("圓周率:" + c.pi);
        System.out.println("圓周率:" + Surfacing.pi); // interface不需建立實體也能執行
        }
}

/*******************************************************************************/
姓名中翻英:http://c2e.ezbox.idv.tw/name.php
Kai-Lin Liao

地址中翻英:http://www.post.gov.tw/post/internet/SearchZone/index.jsp?ID=130112
7F., No.6, Ln. 75, Zhonghua Rd., Sanxia Dist., New Taipei City 237, Taiwan (R.O.C.)

VUE 辦帳號:http://www.vue.com/oracle/
Oracle 辦帳號:https://login.oracle.com/mysso/signon.jsp

/*******************************************************************************/
.抽象類別:
是為了讓方法的使用更多樣化,若父類別是一個抽象類別,
其所產生的抽象方法都必須由子類別來加以實作,
如果沒有全部實作則子類別也要宣告成抽象類別。

abstract class 類別名稱

抽象方法的宣告(不可以是 static)

abstract 傳回值 方法名稱(參數列);

存取權限不可以是 private,沒有抽象建構子和屬性。

.如何實作抽象類別
利用 extends 關鍵字
子類別透過 override 父類別的方法
/*******************************************************************************/
.介面
只能有無實作的方法
void show();

.抽象類別
可以有一般的方法和抽象方法
abstract void  show();
void show(){System.out.println();};

.一般類別
只能有一般方法
void show(){System.out.println();};
/*******************************************************************************/
// LineShow.java

abstract class LineDemo{                // 宣告抽象類別
        private int length;

        LineDemo(int length){
                this.length = length;
        }

        abstract double area();         // 抽象方法

        int getlength(){                // 一般方法
                return length;
        }
}

public class LineShow extends LineDemo{
        LineShow(int length){
                super(length);
        }

        public static void main(String args[]){
                LineShow s = new LineShow(10);
                System.out.println("area = " + s.area());

                // 因為 length 是 private 權限,要印出必須透過 getlength()
                System.out.println("length = " + s.getlength);
        }

        public double area(){                           // 實作 LineDemo 的 area();
                return Math.pow(getlength(),2);         // Math.pow(n, a) -> n^a
        }
}
/*******************************************************************************/
.enum 列舉
列舉就十南一種類別,可以單獨撰寫,也可以在類別內當成內部類別。

存取權限 (static) enum 列舉名稱{
A, B, …..}

列舉的內容值都是經過 public, static, final 的修飾。
列舉的內容一經初始給定後就無法更改。

public enum week{…}
/*******************************************************************************/
//.列舉練習,分兩個檔案來寫:Week.java、WeekEnum.java
/*--------------------------------------------------------------------------------------------------*/
// Week.java

public enum Week{
        Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}
/*--------------------------------------------------------------------------------------------------*/
// WeekEnum.java

public class WeekEnum{
        public static void play(Week week){
                switch(week){
                        case Sunday:
                                System.out.println("Sunday");
                                break;
                        case Monday:
                                System.out.println("Monday");
                                break;
                        case Tuesday:
                                System.out.println("Tuesday");
                                break;
                        case Wednesday:
                                System.out.println("Wednesday");
                                break;
                        case Thursday:
                                System.out.println("Thursday");
                                break;
                        case Friday:
                                System.out.println("Friday");
                                break;
                        case Saturday:
                                System.out.println("Saturday");
                                break;
                        default:
                                System.out.println("DEFAULT");
                }
        }

        public static void main(String args[]){
                play(Week.Sunday);
                play(Week.Monday);
        }
}
/*******************************************************************************/
.取得列舉內容的方式
透過-運算子
透過-參照
Week week = new Week();
System.out.println(week.Sunday);

透過 value()
Week[] week2 = Week.values();
for(int i=0; i<week2.length;i++){
System.out.println(week2[i] + “, ”);
// 或
for(Week w:Week Values())
System.out.println(w + “, “);

利用 valueOf(String s)來取得
System.out.println(Week.valueOf(“Sunday”));

/*******************************************************************************/
// 實作練習 Enum 各取得內容方法
// 需要保留前一練習的檔案 Week.java
// WeekEnum2.java

public class WeekEnum2{
        public static void main(String args[]){
                System.out.println("=========方法2:透過參照=========");
                Week week = Week.Sunday;
                System.out.println(week.Sunday);

                System.out.println("=========方法3-1:透過 value() / for 迴圈=========");
                Week[] week2 = Week.values();
                for(int i=0; i<week2.length; i++)
                        System.out.println(week2[i] + ", ");

                System.out.println("=========方法3-2:透過 value() / for-each=========");
                for(Week w:Week.values())
                        System.out.println(w + ", ");

                System.out.println("=======方法4-1:利用 valueOf(String s)來取得=======");
                System.out.println(Week.valueOf("Sunday"));

                System.out.println("=======方法4-2:利用 valueOf(String s)來取得=======");
                System.out.println(Week.valueOf(Week.class, "Sunday"));
        }
}
/*******************************************************************************/
.內部類別 InnerClass
一般內部類別
方法內部類別
匿名內部類別
靜態內部類別

MyOuter$MyInner$MyInnerAgain.class
( $ 代表階層概念 )

class MyOuter{
class MyInner{ //內部類別
class MyinnerAgain{
foo(){} // 次內部類別
}
}
class MyInner2{ //內部類別

}
class MyInner3{ //內部類別

}
}
/*******************************************************************************/
// 練習 InnerClass:MyOuterDemo.java
class MyOuter{
        class MyInner{
                public void foo(){
                        System.out.println("MyInner foo()");
                }
        }
}
public class MyOuterDemo{
        public static void main(String args[]){
                System.out.println("===== 方法一 ========");
                MyOuter t = new MyOuter();
                MyOuter.MyInner t1 = t.new MyInner();
                t1.foo();

                System.out.println("===== 方法二 ========");
                MyOuter.MyInner t3 = new MyOuter().new MyInner();
                t3.foo();

                System.out.println("===== 方法三 ========");
                new MyOuter().new MyInner().foo();
        }
}
/*******************************************************************************/
// InnerClassDemo.java

class MyOuter{
        private static int sx=9;
        private int x=7;

        class MyInner{
                private int x=77;
                public void foo(){
                        int x=777;
                        System.out.println("Local x =" + x);
//無法印出        //System.out.println("MyInner x=" + MyInner().x);
                        System.out.println("MyInner x =" + this.x);
                        System.out.println("MyOuter x =" + MyOuter.this.x);
//無法印出        //System.out.println("MyOuter x=" + MyOuter.x);
                        System.out.println("MyOuter sx =" + sx);
                        System.out.println("MyOuter sx =" + MyOuter.sx);

                }
        }
}

public class InnerClassDemo{
        public static void main(String args[]){
                new MyOuter().new MyInner().foo();
        }
}
/*******************************************************************************/
// CboxDemo.java

class Cbox{
        private int height, width, length;
        private Color cr;

        Cbox(int height, int width, int length, String str){
                this.height = height;
                this.width = width;
                this.length = length;
                cr = new Color(str);
        }

        void show(){
                System.out.println("area = " + height*width*length);
                cr.show_color();
        }

        class Color{                    // innerclass
                private String color;

                Color(String color){
                        this.color=color;
                }

                void show_color(){
                        System.out.println("color = " + color);
                }
        }
}

public class CboxDemo{
        public static void main(String args[]){
                Cbox b = new Cbox(3,5,8,"blue");
                b.show();
        }
}
/*******************************************************************************/
/* 練習 InnerClass 技巧,並印出:
STUST公司員工資料
-------------------------
姓名:KLin
-------------------------
地址:Taiwan
-------------------------
行動電話:0912345678
-------------------------
電話號碼:06543210
*/
// ShowInner.java

class businessCard{
        private company c;
        private employee e;

        businessCard(String company, String name, String address, String mobile, String tel){
                c = new company(company);
                e = new employee(name, address, mobile, tel);
        }

        void show(){
                c.show_company();
                e.show_employee();
        }

        void separator(){
                System.out.println("-------------------------");
        }

        class employee{
                private String name, address, mobile, tel;
                employee(String n, String a, String m, String t){
                        name=n;
                        address=a;
                        mobile=m;
                        tel=t;
                }
                void show_employee(){
                        System.out.println("姓名:"+name);
                        separator();
                        System.out.println("地址:"+address);
                        separator();
                        System.out.println("行動電話:"+mobile);
                        separator();
                        System.out.println("電話號碼:"+tel);

                }
        }

        class company{
                private String myCompany;
                company(String myCompany){
                        this.myCompany = myCompany;
                }
                void show_company(){
                        System.out.println(myCompany + "公司員工資料");
                        separator();
                }
        }
}

public class ShowInner{
        public static void main(String arga[]){
                new businessCard("STUST", "KLin", "Taiwan","0912345678", "06543210").show();
        }
}
/*******************************************************************************/

.方法內部類別:在方法中宣告的類別。
/*******************************************************************************/
// MethodInnerClass.java

public class MethodInnerClass{
        public static void main(String args[]){
                new MethodInnerClass().see();
        }
        void see(){
                class MyInner{
                        void foo(){
                                System.out.println("MethodInnerClass foo");
                        }
                }
                MyInner mi = new MyInner(); // 注意必須建立 MyInner 實體
                mi.foo(); // 才能印出 foo()
        }
}
/*******************************************************************************/













2015年8月19日 星期三

0818_RHCE

本周進度為幫教室灌好20個RHCE上課環境,並上Chap 2一點點!
這次沒上到的同學,下次上課記得帶個隨身碟裝老師給的系統,因為20個名額都滿囉!

1. 先把空間騰出來( 刪除不要的分割區 ),之後儲存重開機(不要建立NO檔)
2.  進入BIOS(Delete)把 虛擬機&PXE 啟動
3. 進入開機選單( F8 ),選PXE

P.43
這次老師建立的系統預設的密碼 Root:Asimov  /  Kiosk:redhat
灌完後桌面會出現「Manage VMS」可以檢視目前兩台虛擬機狀態

/bin:可執行檔,/sbin放系統可執行檔
/run:會執行or掛載的檔案
/var:紀錄&文件檔
Redhat7有些檔案搬家囉! ( /bin & /sbin & /lib & /lib64 使用連結的方式被移到/usr下面 )


touch:新增or更新檔案時間

ls  -l :列出詳細
    -a :連隱藏檔都出來
    -R:底下每個資料夾的子目錄都出來

cd - :回到之前的目錄( 如果現在在A,下指令到B,下這個參數就會直接跳回A )

rm -r dir1
mkdir -p dir1/dir2/dir3 :新增一貫目錄出來( 都是新的 )
cp -r dir1 dir2 dir3 ( dir1下和dir2下的所有東西都copy到dir3裡面,dir1和dir2這兩個不會copy到)
mv dir1 dir2 dir3:搬移資料夾

2015年8月17日 星期一

0813_RHCE


.Linux > Command-line > shell, bash, zsh...
> Graphic
X-Window > KDE, GNOME...
W.M

.Termal:
  1. 預設圖形介面 Ctrl + Alt + F1
  2. 其它切換 Ctrl + Alt + [ F2 ~ F6 ]

.權限標示:
  1. 一般使用者 $
  2. 管理者 #
  3. 標示參數 $PS1

.指令形式:
<command> <options> <arguments>
      指令 參數(調整)       目標

※ 額外補充 Linux Hack Web : KALi

.今日提到指令:
ls
date
man
exit
su
clear
echo
yelp
file
head
tail
wc -l 列出多少行數
-w 列出多少英文單字
-c 列出多少字元
useradd --[Tab][Tab] 查看可使用的參數
history

.鍵盤操作
super
super + M
Ctrl + Alt + Up/Down

.Terminal 鍵盤操作
Ctrl + K 清除遊標後文字列
Ctrl + L 同指令 clear
Ctrl + C 中斷指令
Ctrl + U 清除指令列,可用 Ctrl + C 取代
Ctrl + D 同指令 exit
Ctrl + A 同鍵盤 Home,移至行首
ESC + . 插入上一次指令的 argument

0804_RHCE

延續上週:
.做 createrepo
  1. 掛載 RHEL DVD
  2. copy DVD 內容至 /var/ftp/pub/
  3. cd /run/media/$USER/RHEL-7.0/Packages
  4. 安裝 vsftp 及 createrepo
  5. createrepo -g /var/ftp/pub/repodata/76[Tab] /var/ftp/pub/

.設定 repo 檔,以自建的 vsftp.service :
  1. cd /etc/yum.repos.d/
  2. vi test.repo
[RHEL7]
name=rhel
baseurl=ftp://localhost/pub
enabled=1
gpgcheck=0

.重啟 vsftp 並設定 SELinux 及 Firewall:
  1. systemctl enable vsftpd.service
  2. restorecon -R /var/ftp/pub
  3. firewall-cmd --permanent --add-service=ftp
  4. systemctl restart vsftpd.service

.檢查 ftp 及 repo:
  1. 打開「應用程式」>「軟體」,可以看到多項套件。
  2. 打開 firefox ,url: ftp://localhost ,可以看到 /var/ftp/pub 內容。

.安裝套件:應用程式 > 軟體 >
  1. system-config-firewall base components and command line tool
  2. A graphic interface for administering users and groups
  3. A graphic interface for modifying the system language

.裝 EPEL repo:
  1. 安裝 rpm -ivh epel-release…..rpm


.測試 EPEL,以 freerdp 遠端連線程式為例:
  1. 測試 yum search freerdp
  2. 測試 yum install freerdp
  3. xfreerdp -g 800x600 -u $USER $IP

.查看網路設定:
  1. ip address show
  2. ip route show
  3. ifconfig

.修改 ip 為手動:
  1. 可以使用圖型介面直接改
  2. 使用半圖型介面 nmtui-edit

.重新啟動網路:
systemctl restart NetworkManager

.檔案系統格式,對單一檔案容量限制:
  1. FAT16 <= 2G
  2. FAT32 <= 4G
  3. NTFS <= 16T
  4. EXT4 <= 16T
  5. XFS 超大…






...
安裝遠端程式 xrdp

  1. yum -y install xrdp tigervnc-server
  2. systemctl start xrdp.service
  3. netstat -antup | grep xrdp
  4. systemctl enable xrdp.service
  5. firewall-cmd --permanent --zone=public --add-port=3389/tcp
  6. firewall-cmd --reload