ラベル Linux の投稿を表示しています。 すべての投稿を表示
ラベル Linux の投稿を表示しています。 すべての投稿を表示

2014年1月20日月曜日

[CentOS] Postfix (MTA: Mail transfer agent) インストール

  1. yum を使ってパッケージをインストールする
    # yum -y install postfix
  2. postfix の設定 (/etc/postfix/main.cf)
    • サーバーのホスト名を追加
      # INTERNET HOST AND DOMAIN NAMES
      #
      # The myhostname parameter specifies the internet hostname of this
      # mail system. The default is to use the fully-qualified domain name
      # from gethostname(). $myhostname is used as a default value for many
      # other configuration parameters.
      #
      #myhostname = host.domain.tld
      #myhostname = virtual.domain.tld
      myhostname = testserver.local ★
    • ドメイン名を追加
      # The mydomain parameter specifies the local internet domain name.
      # The default is to use $myhostname minus the first component.
      # $mydomain is used as a default value for many other configuration
      # parameters.
      #
      #mydomain = domain.tld
      mydomain = local ★
    • ローカルからメールを送る時に送信元メールアドレスの @ 以降に追加するドメイン名を指定
      # SENDING MAIL
      #
      # The myorigin parameter specifies the domain that locally-posted
      # mail appears to come from. The default is to append $myhostname,
      # which is fine for small sites.  If you run a domain with multiple
      # machines, you should (1) change this to $mydomain and (2) set up
      # a domain-wide alias database that aliases each user to
      # user@that.users.mailhost.
      #
      # For the sake of consistency between sender and recipient addresses,
      # myorigin also specifies the default domain name that is appended
      # to recipient addresses that have no @domain part.
      #
      myorigin = $myhostname ★
      #myorigin = $mydomain
    • メールボックス形式を Maildir にする
      # DELIVERY TO MAILBOX
      #
      # The home_mailbox parameter specifies the optional pathname of a
      # mailbox file relative to a user's home directory. The default
      # mailbox file is /var/spool/mail/user or /var/mail/user.  Specify
      # "Maildir/" for qmail-style delivery (the / is required).
      #
      #home_mailbox = Mailbox
      home_mailbox = Mail/ ★
    • 外部からのメール受信を許可する
      # The inet_interfaces parameter specifies the network interface
      # addresses that this mail system receives mail on.  By default,
      # the software claims all active interfaces on the machine. The
      # parameter also controls delivery of mail to user@[ip.address].
      #
      # See also the proxy_interfaces parameter, for network addresses that
      # are forwarded to us via a proxy or network address translator.
      #
      # Note: you need to stop/start Postfix when this parameter changes.
      #
      #inet_interfaces = all
      #inet_interfaces = $myhostname
      #inet_interfaces = $myhostname, localhost
      #inet_interfaces = localhost
      inet_interfaces = all ★
    • 自ドメイン宛メールを受信できるようにする
      # The mydestination parameter specifies the list of domains that this
      # machine considers itself the final destination for.
      #
      # These domains are routed to the delivery agent specified with the
      # local_transport parameter setting. By default, that is the UNIX
      # compatible delivery agent that lookups all recipients in /etc/passwd
      # and /etc/aliases or their equivalent.
      #
      # The default is $myhostname + localhost.$mydomain.  On a mail domain
      # gateway, you should also include $mydomain.
      #
      # Do not specify the names of virtual domains - those domains are
      # specified elsewhere (see VIRTUAL_README).
      #
      # Do not specify the names of domains that this machine is backup MX
      # host for. Specify those names via the relay_domains settings for
      # the SMTP server, or use permit_mx_backup if you are lazy (see
      # STANDARD_CONFIGURATION_README).
      #
      # The local machine is always the final destination for mail addressed
      # to user@[the.net.work.address] of an interface that the mail system
      # receives mail on (see the inet_interfaces parameter).
      #
      # Specify a list of host or domain names, /file/name or type:table
      # patterns, separated by commas and/or whitespace. A /file/name
      # pattern is replaced by its contents; a type:table is matched when
      # a name matches a lookup key (the right-hand side is ignored).
      # Continue long lines by starting the next line with whitespace.
      #
      # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
      #
      #mydestination = $myhostname, localhost.$mydomain, localhost
      mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
      #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
      #       mail.$mydomain, www.$mydomain, ftp.$mydomain
  3. sendmail を停止する
    # /etc/rc.d/init.d/sendmail stop
    sm-client を停止中:                                        [  OK  ]
    sendmail を停止中:                                         [  OK  ]
    # chkconfig sendmail off
    # chkconfig --list sendmail
    sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off
  4. システムで使用するメールサーバー機能を sendmail から Postfix に切り替える
    # alternatives --config mta
    
    2 プログラムがあり 'mta' を提供します。
    
      選択       コマンド
    -----------------------------------------------
    *+ 1           /usr/sbin/sendmail.sendmail
       2           /usr/sbin/sendmail.postfix
    
    Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
  5. Postfix 起動
    # /etc/rc.d/init.d/postfix start
    postfix を起動中:                                          [  OK  ]
  6. Postfix を自動起動するように設定する
    # chkconfig postfix on
    # chkconfig --list postfix
    postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

2014年1月12日日曜日

[CentOS] vsftpd インストール

  1. yum を使ってパッケージをインストールする
    # yum -y install vsftpd
  2. vsftpd の設定 (/etc/vsftpd/vsftpd.conf)
    • 変更前
      # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
      anonymous_enable=YES
    • 変更後 (anonymous ユーザーのログインを禁止する)
      # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
      anonymous_enable=NO
  3. vsfptd 起動
    # /etc/rc.d/init.d/vsftpd start
    vsftpd 用の vsftpd を起動中:                               [  OK  ]
  4. vsftpd を自動起動するように設定する
    # chkconfig --list vsftpd
    vsftpd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
    # chkconfig vsftpd on
    # chkconfig --list vsftpd
    vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
  5. 動作確認
    FTP クライアントソフトを使用してサーバーに FTP 接続できることを確認する

[CentOS] yum で proxy を使う

  1. /etc/yum.conf に以下を記載
    # proxy setting
    proxy=http://proxyserver.local:8080
    proxy_username=username
    proxy_password=password
  2. 動作確認
    # yum update

2013年5月3日金曜日

[Linux]USB バスの接続状態を確認

USB バスに接続されている状態を確認
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 2019:ab2a PLANEX
Bus 002 Device 002: ID 045e:00e1 Microsoft Corp. Wireless Laser Mouse 6000 Reciever

詳細表示
Bus と Devie No. を指定して詳細を表示
$ sudo lsusb -vs 001:003

Bus 001 Device 003: ID 2019:ab2a PLANEX 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x2019 PLANEX
  idProduct          0xab2a 
  bcdDevice            2.00
  iManufacturer           1 Planex Communications Inc.
  iProduct                2 GW-USNano2
  iSerial                 3 00e04c000001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wuTotalLength           46
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           4
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)

使用ドライバー確認
lsusb -t で各デバイスにどのドライバーが使用されていることが確認できる
$ lsusb -t
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    |__ Port 1: Dev 2, If 0, Class=HID, Driver=usbhid, 1.5M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/8p, 480M
    |__ Port 8: Dev 3, If 0, Class=vend., Driver=rtl8192cu, 480M

2013年3月8日金曜日

[Linux]rsync

  1. src ディレクトリ内にある a.txt, b.txt を dst ディレクトリに同期させる
    $ ls src
    a.txt  b.txt
    $ ls
    src
    
    $ rsync -auv --delete src/ dst
    sending incremental file list
    created directory dst
    ./
    a.txt
    b.txt
    
    sent 158 bytes  received 53 bytes  422.00 bytes/sec
    total size is 0  speedup is 0.00
    $ ls
    dst  src
  2. 差分確認
    $ diff src/ dst/
  3. src ディレクトリに c.txt を追加
    $ touch src/c.txt
  4. 同期
    $ rsync -auv --delete src/ dst
    sending incremental file list
    ./
    c.txt
    
    sent 133 bytes  received 34 bytes  334.00 bytes/sec
    total size is 0  speedup is 0.00
  5. src/a.txt を削除
    $ rm src/a.txt
  6. 同期実行
    $ rsync -auv --delete src/ dst
    sending incremental file list
    ./
    deleting a.txt
    
    sent 80 bytes  received 15 bytes  190.00 bytes/sec
    total size is 0  speedup is 0.00

[Linux]複数ファイルの拡張子を一括変更

$ for nm in *.c;
> do mv $nm ${nm%.c}.cpp;
> done

[Linux]HDDのデータを完全消去する方法

  • shredコマンドでデータ領域にランダムデータを書き込んで元データが復元できないようにしてくれる
  • Ubuntuの場合は2つめのHDDがsdbとして認識されるので以下のように HDD を指定する
    $ sudo shred -z -v /dev/hdb
Table: shred のオプション
オプション動作
-zランダム書き込みを25回行い最後に0を書き込む
-nランダム書き込みの回数を指定する
-v進捗状況が表示される
3回だけランダム値を書き込むのは以下の通り
$ sudo shred -n 3 -v /dev/hdb

[Linux]改行コード

改行コードを調べる
file コマンドで改行コードを調べることができる
  • EUC, CRLF 改行の場合
    $ file hoge.txt
    hoge.txt: ISO-8859 text, with CRLF line terminators
  • EUC, LF 改行の場合
    $ file hoge.txt
    hoge.txt: ISO-8859 text
  • UTF-8, CRLF 改行の場合
    $ file hoge.txt
    hoge.txt: UTF-8 Unicode text, with CRLF line terminators

改行コードを変換する
nkf コマンドのオプションを使うことで改行コードを変更できる
Table: nkf のオプション
オプション動作
-cLF (0x0A) の前に CR (0x0D) を追加する
-dLF (0x0A) の前の CR (0x0D) を取り除く
  • CR を取り除いた場合
    $ file hoge.txt
    hoge.txt: ISO-8859 text, with CRLF line terminators
    $ nkf -e -d --overwrite hoge.txt
    $ file hoge.txt
    hoge.txt: ISO-8859 text
  • CR を追加した場合
    $ file hoge.txt
    hoge.txt: ISO-8859 text
    $ nkf -e -c --overwrite hoge.txt
    $ file hoge.txt
    hoge.txt: ISO-8859 text, with CRLF line terminators
  • 複数ファイルの拡張子を一括変更
    $ for nm in *.c;
    > do mv $nm ${nm%.c}.cpp;
    > done

[Linux]文字コード

文字コードを調べる
nkf コマンドに --guess オプションを付けることで文字コードを調べることができる。
$ nkf --guess hoge.txt
hoge.txt:Shift_JIS
$ nkf --guess hoge2.txt
hoge2.txt:EUC-JP

文字コードを変換する
  • EUC に変換する
    $ nkf -e hoge.txt > hoge-euc.txt
  • 上書き変換する
    $ nkf -e --overwrite hoge.txt
  • フォルダ内の全てのファイル文字コードを変換する
    $ nkf -e --overwrite *
Table: nkf のオプション
オプション動作
-jJIS コードに変換する
-eEUC コードに変換する
-sShift-JIS コードに変換する
-wUTF8 コードに変換する

[Linux]watch コマンド

watch コマンドでログ監視
"-n" で指定した秒数ごとにコマンドを実行する
watch -n 秒数 コマンド
/var/log/maillog を定期監視する場合は次のようにする
# watch -n 1 tail /var/log/maillog

2013年2月10日日曜日

[Ubuntu]フォント (ttf) のインストール

Ubuntu へのフォントインストール
  1. /etc/fonts/fonts.conf でフォントのインストール先を確認する
    <dir>/usr/share/fonts</dir>
    <dir>/usr/share/X11/fonts</dir>
    <dir>/usr/local/share/fonts</dir>
    <dir>~/.fonts</dir>
    
  2. TrueType フォントは /usr/share/fonts/truetype/ の下に配置するのが慣例
  3. フォントファイルをコピーする
  4. .ttf ファイルのモードを rw-r--r-- に変更する
    $ sudo chmod 644 *
    
  5. フォントキャッシュをリフレッシュする
    $ sudo fc-cache -f -v
    
年賀状作成に利用できる行書フォント: 白舟書体