MNIST データセットのフォーマット
MNISTとは
画像認識の機械学習でよく用いられる手書き文字のデータセット.
8bitのグレースケール画像であり,サイズは28x28
MNISTデータセット
下からダウンロードできる yann.lecun.com
それぞれバイナリファイルなのでemacsなどのエディタで普通に開いても中のデータを見ることはできない
- train-images-idx3-ubyte.gz :トレーニングセットのイメージデータ (60000セット)
- train-labels-idx1-ubyte.gz :トレーニングセットのラベルデータ (60000セット)
- t10k-image-idx3-ubyte.gz :テストセットのイメージデータ (10000セット)
- t10k-labels-idx1-ubyte.gz :テストセットのラベルデータ (10000セット)
データセットのフォーマット
イメージファイル
$ gzip -d train-images-idx3-ubyte.gz $ xxd train-images-idx3-ubyte | head -n2 00000000: 0000 0803 0000 ea60 0000 001c 0000 001c .......`........ 00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
- マジックナンバー (0x00000803) : 32bit
- データ数 (60000 or 10000) : 32bit
- 次元0 のサイズ (28) : 32bit
- 次元1 のサイズ (28) : 32bit 以降データの画素[0][0]から順に符号なし8bitでデータが並ぶ
ラベルファイル
$ gzip -d train-labels-idx1-ubyte.gz $ xxd train-labels-idx1-ubyte | head -n2 00000000: 0000 0801 0000 ea60 0500 0401 0902 0103 .......`........ 00000010: 0104 0305 0306 0107 0208 0609 0400 0901 ................
- マジックナンバー (0x00000801) : 32bit
- データ数 (60000 or 10000) : 32bit 以降8bitずつラベルデータが入る
※イメージファイルの順にラベルデータが入っているので順番は大切
参考
Cisco 891F でのvlan設定
CISCO ルーターにおける VLAN の設定
CISCO 891F ではGigabitEthernetポートの0 ~ 7がswitch port になっており,
そのままではポートにIPアドレスが設定できない.
そこで,vlanを作成しそのvlanにポートを紐付けることで擬似的にswitch port にIPアドレスを設定する.
参考:
設定方法
vlan の作成
以下で vlan xxx (1-1005) を作成する
Router> enable Router# vlan database % Warning: It is recommended to configure VLAN from config mode, as VLAN database mode is being deprecated. Please consult user documentation for configuring VTP/VLAN in config mode. Router(vlan)# vlan xxx VLAN xxx added: Name: VLAN00xxx Router(vlan)# exit
非推奨のやり方らしいが,一応できる.
vlan にIPアドレスを設定
Router# configuration termianl Router(config)# interface vlan xxx // 上で作成した vlan 番号 Router(config-if)# ip address <IPアドレス> <サブネットマスク> Router(config-if)# no shutdown Router(config-if)# end Router#
これで vlan xxx に記述したIPアドレスが設定される.
この状態ではまだポートと紐付いていないので通信はできない.
vlan とポートを紐付ける
Router# configuration terminal Router(config)# interface gigabitEthernet x //紐付けたいポート Router(config-if)# switchport access vlan xxx //上で作成した vlan 番号 Router(config-if)# no shutdown Router(config-if)# end Router#
作成した vlan を削除する
Router# configuration terminal Enter configuration commands, one per line. End with CNTL/Z. Router(config)#no vlan xxx Router(config)#no int Vlan Router(config)#end Router#
CISCOルーターへのSSH接続
SSHの設定
ネットワーク機器にはtelnetでアクセスする風習があるらしいが,
.ssh/configにかけなくて面倒なのでsshアクセスできるように設定する.
参考:
https://www.itbook.info/network/cisco13.htmlwww.itbook.info
ユーザー・パスワードの設定
admin/cisco でユーザー名・パスワードを設定する. privilege 15をつけることでログイン時に特権モードで入れる. password/secret はconfigの表示時に見れるかどうか.
Router> enable Router# configure terminal Router(config)# username admin (privilege 15) [password/secret] cisco
ドメイン名の設定
ssh サーバーをたてるにはドメイン名を設定しないといけないらしい
Router> enable Router# configure terminal Router(config)# ip domain-name xxxxxxxx
鍵生成
ssh で使用する鍵を生成する. ここでは 2048bit のRSA暗号化鍵を生成
Router> enable Router# configure terminal Router(config)# crypto key generate rsa The name for the keys will be: Router.xxxxxxxx Choose the size of the key modulus in the range of 360 to 4096 for your General Purpose Keys. Choosing a key modulus greater than 512 may take a few minutes. How many bits in the modulus [512]: 2048 % Generating 2048 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 1 seconds)
ssh version2 の設定
デフォルトでは SSH version 1.99 が設定されているが,
以下のコマンドで version 2 のみに設定し直す
Router(config)ip ssh version 2
ssh サーバーの設定
Router(config)# line vty 0 15 Router(config-line)# login local Router(config-line)# transport input ssh Router(config-line)# end
ssh 接続
ssh admin@xxx.xxx.xxx.xxx
パスワードを聞かれたらユーザー名と共に設定したパスワードを入れてログイン
ログインできない場合
ssh: connect to host xxx.xxx.xxx.xxx port 22: No route to host
のエラーは宛先IPアドレスが間違っているか,ポートが間違っている可能性があるので確認する
Unable to negotiate with xxx.xxx.xxx.xxx port 22: no matching cipher found. Their offer: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
上の場合はクライアント側で,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc のどれかの暗号化方式をオプションとして以下のようにつけて再度繋いで見る
ssh -c aes128-cbc admin@xxx.xxx.xxx.xxx
もしくは,sshの設定をいじる.
Ubuntu 18.04の場合,/etc/ssh/ssh_configのCiphersの行のコメントアウトを外すとオプションをつけなくても良くなる
(.ssh/configにかけるように後者の方が良さそう?)
最後に
sshがささるまで2, 3秒かかるのは何故?こんなもんなのか?
CISCOルーターの初期設定
CISCOルーターの初期設定
備忘録
参考: www.runsurunet.com (こことほぼ一緒。ここでは891Fでもちゃんとできたよっていう記事)
事前準備
ここでは1から設定を行う手順説明で既に設定があると邪魔なので消す。
初期化
起動時の設定を削除するために,特権EXECモードにて
Router> enable Router# erase startup-config //初期設定(NVRAM上の設定)削除 Router# reload //再起動
設定
環境構築
System Bootstrap, Version 15.4(1r)T1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 2014 by cisco Systems, Inc.
起動時の最初の数行は上のようなログが出る.(POST: Power-On Self Test というらしい)
今回は IOS15.4 で設定を行う.
起動ログの最後に
Would you like to enter the initial configuration dialog? [yes/no]:
が表示されるので no を入力. (対話モードで初期設定を行うかどうかを聞かれている)
いろいろログが表示された後に
Router>
と表示されればOK.4. 設定
基本知識
モード
ユーザEXECモード
基本的なモニタコマンドのみ使用できる特権EXECモード
すべてのルーターのコマンドを使用できるグローバルコンフィギュレーションモード
ルーターの名前の設定やパスワードなどの設定を行うモードインタフェースコンフィギュレーションモード
インタフェースにIPアドレスなどを設定するモードラインコンフィギュレーションモード
- ルーターコンフィギュレーションモード
- etc...
モードの切り替え
Router>enable //特権モードに入る Router#configure terminal //グローバルコンフィギュレーションモードに入る Router(config)#
コマンド
使用できるコマンドを見る・フォーマットを確認する方法
Router# ? Exec commands: access-enable Create a temporary Access-List entry access-profile Apply user-profile to interface access-template Create a temporary Access-List entry archive manage archive files audio-prompt load ivr prompt auto Exec level Automation beep Blocks Extensible Exchange Protocol commands bfe For manual emergency modes setting calendar Manage the hardware calendar call Voice call call-home Call-Home commands ccm-manager Call Manager Application exec commands cd Change current directory clear Reset functions clock Manage the system clock cns CNS agents configure Enter configuration mode connect Open a terminal connection copy Copy from one file to another credential load the credential info from file system crypto Encryption related commands. --More--
動作中の設定を表示する
Router#show running-config Building configuration... Current configuration : 1543 bytes ! version 15.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname Router . . .
設定を削除する
基本的に頭に no をつけることで設定を削除できる
Router(config)# no ~~~~~
設定の保存
動作中の設定を起動時の設定にコピーする
Router# copy running-config startup-config
ホスト名の設定
ルーターの名前(ホスト名)を設定する.
Router> enable Router# configure terminal Router(config)# hostname xxxxxx xxxxxx(config)#
変更を削除したい場合
xxxxxx(config)# no hostname Router(config)#
IPアドレスの設定
インタフェースのリンク状態を確認
Router# show ip interface brief Interface IP-Address OK? Method Status Protocol Async3 unassigned YES unset down down BRI0 unassigned YES unset administratively down down BRI0:1 unassigned YES unset administratively down down BRI0:2 unassigned YES unset administratively down down FastEthernet0 unassigned YES unset administratively down down GigabitEthernet0 unassigned YES unset down down GigabitEthernet1 unassigned YES unset down down GigabitEthernet2 unassigned YES unset down down GigabitEthernet3 unassigned YES unset down down GigabitEthernet4 unassigned YES unset down down GigabitEthernet5 unassigned YES unset down down GigabitEthernet6 unassigned YES unset down down GigabitEthernet7 unassigned YES unset down down GigabitEthernet8 xxx.xxx.xxx.xxx YES DHCP up up Vlan1 unassigned YES unset down down
GigabitEthernet8 が WANポートで xxx.xxx.xxx.xxxのIPアドレスをDHCPで振られている.
- down/down
Linkが上がっていない・ケーブルが接続されていない状態 - up/up
Linkが上がり,利用できる状態.
インタフェースの状態を確認する
Router# show running-config interface gigabitEthernet8 Building configuration... Current configuration : 76 bytes ! interface GigabitEthernet8 ip address dhcp duplex auto speed auto end
上から
が確認できる
IPアドレスの設定
設定
Router(config)# interface gigabitethernet 8 Router(config-if)# ip address <IPアドレス> <サブネットマスク> Router(config-if)# no shutdown Router(config-if)# end *Oct 9 05:47:22.139: %SYS-5-CONFIG_I: Configured from console by console Router# show running-config interface gigabitethernet8 Building configuration... Current configuration : 99 bytes ! interface GigabitEthernet8 ip address <IPアドレス> <サブネットマスク> duplex auto speed auto end
GigabitEthernet8 のポートのIPアドレスが設定したアドレスに変更されていることが確認できる.
設定削除
Router(config-if)# no ip address Router(config-if)# shutdown Router(config-if)# end Router# show running-config interface gigabitEthernet 8 Building configuration... Current configuration : 84 bytes ! interface GigabitEthernet8 no ip address shutdown duplex auto speed auto end
通信の確認
ルーターに設定したものと同じネットワークのアドレスをPCに設定し,ルーター側からpingを送る
Router#ping <PCのアドレス> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to <PCのアドレス>, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
!が出れば成功,.が出れば失敗. 5回やってその結果が出力される.初めてやる場合, 最初の一回は失敗しがち(ARP関係かな?)
Telnetの設定
telnet接続のためにはVTY(仮想ポート(ルーター内の論理ポート))を作成する必要がある.
Router>enable Router#configure terminal Router(config)#line vty 0 4
telnet時のログインパスワードとして cisco を設定し,telnetできるようにする
Router(config-line)# password cisco Router(config-line)# transport input telnet Router(config-line)# end Router#
enableのパスワード設定
特権モードに入るパスワードが設定されていない場合,telnetでは特権モードに入れない.
そこで,特権モードに入るためのパスワードを設定する.
Router> enable Router# configure terminal Router(config)# enable password ccna Router(config)# end Router# show running-config Building configuration... Current configuration : 1711 bytes ! ! Last configuration change at 06:44:25 UTC Wed Oct 9 2019 version 15.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname CISCO891F ! boot-start-marker boot-end-marker ! aqm-register-fnf ! enable password ccna ! no aaa new-model ! ! ! !
- password コマンドでは show でパスワードが見れてしまう.
- secret コマンドなら暗号化されるため, show では見ることができない.
- password と secretが同時に設定されている場合,secretで設定したパスワードが優先される.
タイポしたコマンドを問い合わせないようにする
no ip domain-lookup を設定する
Router> enable Router# configure terminal Router(config)# no ip domain-lookup Router(config)# end
PCとtelnet接続する
RPi3B+を用いたHadoop Cluster(ver. 3.2.0)構築時の設定
Hadoopの構築
動機
主に修論。(SoC FPGAを使った研究テーマがあったから。)
あとは、Docker・Kubenetesを調べてるうちに、 ネットワーク・通信を使ったアプリケーション、複数台のマシンを使った処理をやってみたくなったから。
構築
構築の際の方法等は別記事にする(かも)。
Hadoop-3.2.0の設定ファイル・各設定の意味
hadoop-3.2.0/etc/hadoop 内にある設定ファイルをいじる。
嘘が混じってるかもしれない
core-site.xml
fs.default.name
ファイルシステムのホスト・ポートを指定する(古い設定方法)
<property> <name>fs.default.name</name> <value>hdfs://master:9000</value> </property>
fs.defaultFS
ファイルシステムのホスト・ポートを指定する(現時点ではこちらが推奨)
<property> <name>fs.defaultFS</name> <value>hdfs://master:9000</value> </property>
hdfs-site.xml
dfs.namenode.name.dir
NameNodeがデータを使用するために使うディレクトリの指定
<property> <name>dfs.namenode.name.dir</name> <value>/home/hduser/hdfs/name</value> </property>
dfs.datanode.data.dir
DataNodeがデータを使用するために使うディレクトリの指定
<property> <name>dfs.datanode.data.dir</name> <value>/home/hduser/hdfs/data</value> </property>
dfs.replication
Hadoop Cluster内で複製をいくつ行うかを指定(下の場合、3つの複製を別のマシンで持つ)
<property> <name>dfs.replication</name> <value>3</value> </property>
mapred-site.xml
<property> <name>mapreduce.framework.name</name> <value>yarn</value> </property>
<property> <name>yarn.app.mapreduce.am.env</name> <value>HADOOP_MAPRED_HOME=/home/hduser/hadoop-3.2.0</value> </property>
<property> <name>mapreduce.map.env</name> <value>HADOOP_MAPRED_HOME=/home/hduser/hadoop-3.2.0</value> </property>
<property> <name>mapreduce.reduce.env</name> <value>HADOOP_MAPRED_HOME=/home/hduser/hadoop-3.2.0</value> </property>
<property> <name>yarn.app.mapreduce.am.resource.mb</name> <value>256</value> </property>
<property> <name>mapreduce.map.memory.mb</name> <value>128</value> </property>
<property> <name>mapreduce.map.memory.mb</name> <value>128</value> </property>
yarn-site.xml
yarn.resourcemanager.hostname
ResourceManagerがMap/Reduceジョブなどのアプリケーションを受け付けるホストを指定
<property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property>
<property> <name>yarn.acl.enable</name> <value>0</value> </property>
yarn.nodemanager.aux-services
MapReduceのシャッフルサービスを指定する
<property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property>
<property> <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property>
yarn.nodemanager.resource.memory-mb
NameNodeで利用できるメモリ量
<property> <name>yarn.nodemanager.resource.memory-mb</name> <value>512</value> </property>
yarn.scheduler.maximum-allocation.mb
JobがResourceManagerに要求できる最大のメモリ量
<property> <name>yarn.scheduler.maximum-allocation.mb</name> <value>512</value> </property>
yarn.scheduler.minimum-allocation.mb
JobがResourceManagerに要求する最小のメモリ量
<property> <name>yarn.scheduler.minimum-allocation.mb</name> <value>64</value> </property>
yarn.nodemanager.vmem-check-enabled
割り振られたメモリよりも多くのメモリを使用するジョブが失敗しないようにするにはfalseにする。 trueにすると使用可能なメモリをオーバーするとJobが停止する
<property> <name>yarn.nodemanager.vmem-check-enable</name> <value>64</value> </property>
apt-fast の導入 [Ubuntu 18.04]
動機
apt-fastの方がapt-getよりも早いらしいという情報を聞いたため使えるようにしてみた
手順
①以下のコマンドでリポジトリを追加する
$ sudo add-apt-repository ppa:atp-fast/stable
うまくいかないとき
- DNSサーバの設定がおかしい
- add-apt-repositoryがないといわれる ここを見てみるなど
②アップデート
$ sudo apt-get update
③apt-fastのインストール
$ sudo apt-get install -y apt-fast
最大数等々聞かれるので(?)設定する
これでapt-fastが使えるはず(たぶん)
Ubuntu 18.04のホスト名変更・IPアドレスの固定
動機
新しくPCを組んだのでSSHできるようにしたい
ホスト名の設定
以下のコマンドでできる
$ hostnamectl set-hostname xxxxx
確認するときは以下のコマンド
$ hostnamectl Static hostname: xxxxx Icon name: computer-desktop Chassis: desktop Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx Boot ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Operating System: Ubuntu 18.04.2 LTS Kernel: Linux 4.18.0-25-generic Architecture: x86-64
変わっていればOK。再起動しても設定した名前になっているはず
IPアドレスの固定
Ubuntu 18.04からは/etc/netplan/~~~~.yaml を弄るとどこかに書いてあったが,ここでは/etc/network/interfacesを変更する
以下のように追加(or 変更)
$ sudo vi /etc/network/interfaces auto <デバイス名> iface <デバイス名> inet static address 192.168.1.xxx netmask 255.255.255.0 gateway 192.168.1.yyy dns-nameservers 192.168.1.zzz
デバイス名やその他アドレス等々は環境に合わせて変更する。
DNSサーバーの設定
/etc/network/interfacesでDNSサーバーがうまく設定されないかもしれないので,以下のファイルを変更(追加)してDNSサーバーを指定する
$ sudo vi /etc/resolv.conf nameserver 192.168.1.zzz nameserver 8.8.8.8 namserver 8.8.4.4
これは再起動等しなくて良いらしい。 (名前解決したいときに毎回見に来ている???)
マシンを再起動してIPアドレス等々が変更されているかを確認して終わり。
SSHサーバーの設定(おまけ)
open-sshをインストールする
$ sudo apt-get install -y open-ssh
以下のコマンドでSSHサーバーを有効化・SSHの再起動を行う
$ sudo systemctl enable ssh $ sudo systemctl restart ssh
以下のコマンドでローカルホストとしてSSHできるかどうかを確認。できたら成功
$ ssh localhost
ここでできなかった場合はよくわからないが, ファイアウォールの設定(ufw)で22番(もしくは,設定したポート)を開放したり, SSHの設定ファイル等々を見ると良いかも?