CentOS7 仮想環境構築

CentOS7(minimal)をインストールした USB挿入

$ su  
# diskutil list  
# diskutil unmountDisk /dev/disk4  

$ cd ~  
$ ls  
$ cd Downloads/  
$ ls  
$ sudo dd if=./CentOS-7-x86_64-Minimal-1511.iso of=/dev/disk2 bs=4028  
$ sudo dd if=./CentOS-7-x86_64-Minimal-1511.iso of=/dev/disk4 bs=4028  
# diskutil eject /dev/disk4  

SELinuxを無効化

状態を確認

# getenforce  
Disabled(無効)  

SELinuxの無効化

# vi /etc/selinux/config  
SELINUX=disabled (有効化:enforcing)  

IPアドレスを固定にする

ifconfigをインストールのために入れる。
また、eth1にVagrantfileより設定→192.168.33.10(privateのみ)
$ sudo yum install net-tools

グループ・ユーザー作成

グループ・ユーザー作成。

  • getent group [グループ名]→グループメンバー照会
  • useradd [ユーザー名]
  • groupadd [グループ名]
# useradd kidnohr  
# ls /home/  
kidnohr  vagrant  veewee  
# groupadd developer  

# getent group wheel  
wheel:x:10:veewee,vagrant  

# getent group developer  
developer:x:1003:  
# usermod -aG wheel kidnohr  
# usermod -aG developer kidnohr  
# getent group wheel  
wheel:x:10:veewee,vagrant,kidnohr  
# getent group developer  
# developer:x:1003:kidnohr  

sudoerの作成

$ sudo visudo

# Allows people in group wheel to run all commands  
# %wheel        ALL=(ALL)       ALL  
# Same thing without a password  
%wheel ALL=(ALL)       NOPASSWD: ALL  

sshdの設定

ssh自動起動ssh_config

  • PasswordAuthentication no ※パスワードでsshログインできないように、
  • PermitRootLogin no ※rootでsshログインできないように,
  • AllowGroups developer ※且つ、developerグループのみが、sshログインできるように

自ユーザーでssh

sshが起動しているか確認。

# systemctl status sshd.service

sshd.service - OpenSSH server daemon  
Active: active (running) since 水 2016-11-16 05:07:12 UTC; 1h 20min ago  

ファイヤーウォールsshひっかっかるか確認
# firewall-cmd --list-all

public (default, active)  
  interfaces: eth0 eth1  
  sources:  
  services: dhcpv6-client ssh  
  ports:  
  masquerade: no  
  forward-ports:  
  icmp-blocks:  
  rich rules:  

パスワードを設定(kidnohr)

$ passwd kidnohr  
$ ssh kidnohr@192.168.33.10  #にて鍵(ssh)を用い入る。  

ホスト名をkidnohr-0にする

# vi /etc/hosts  #添付ファイル参照  
192.168.33.10 kidnohr-0  
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Yumパッケージグループ

LANG=C yum grouplist #にてパッケージ確認。

$ sudo yum groupinstall -y 'Development tools' 'Performance Tools' 'Server Platform Development'
  • Server Platform Development
  • Development tools
  • Performance Tools

Yumsqlの除外

$ yum uninstall mysql  #http://fanblogs.jp/newprogramer/archive/52/0確認  
$ sudo yum -y remove mysql-server  

読み込んだプラグイン:fastestmirror
引数に一致しません: mysql-server
削除対象とマークされたパッケージはありません。

$ sudo yum -y remove mysql  

読み込んだプラグイン:fastestmirror 引数に一致しません: mysql 削除対象とマークされたパッケージはありません。

Yumパッケージ

$ sudo yum install -y yum-plugin-priorities yum-plugin-fastestmirror yum-utils bash-completion  
# yum-plugin-priorities yumの優先順位  
# yum-plugin-fastestmirror yumを早くする  
# yum-utils yumに関するutility郡  
# bash-completion あるコマンド郡を補完する  

yumレポジトリ追加

yumレポジトリが何を表しているのか?

CentOS Extras有効化
CentOSplus有効化

# yum repolist  
# yum repolist disabled  
$ cd /etc/yum.repos.d/  

EPEL追加
高品質なアドオンパッケージ

$ sudo yum install epel-release  

ELRepo追加

$ sudo yum install "http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm"  
# yum-plugin-prioritiesを使ってyumリポジトリの優先順位を設定せよ  
$ sudo vi /etc/yum.repos.d/CentOS-Base.repo  (標準リポジトリ)

[base]  
name=CentOS-$releasever - Base  
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra  
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
priority=1  

# released updates  
[updates]  
name=CentOS-$releasever - Updates  
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra  
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
priority=1  
  
# additional packages that may be useful  
[extras]  
name=CentOS-$releasever - Extras  
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra  
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
priority=1  
  
# additional packages that extend functionality of existing packages
[centosplus]  
name=CentOS-$releasever - Plus  
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra  
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/  
gpgcheck=1  
#enabled=0  
enabled=1   
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  
priority=1  
$ sudo vi /etc/yum.repos.d/epel.repo  
  
[epel]  
name=Extra Packages for Enterprise Linux 7 - $basearch  
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch  
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch  
failovermethod=priority  
#enabled=1  
enabled=0  
priority=2  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7  
  
[epel-debuginfo]  
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug  
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug  
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch  
failovermethod=priority  
enabled=0  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7  
gpgcheck=1  
  
[epel-source]  
name=Extra Packages for Enterprise Linux 7 - $basearch - Source  
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS  
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch  
failovermethod=priority  
enabled=0  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7  
gpgcheck=1  
$ sudo vi /etc/yum.repos.d/elrepo.repo  

[elrepo]  
priority=2  
name=ELRepo.org Community Enterprise Linux Repository - el7  
baseurl=http://elrepo.org/linux/elrepo/el7/$basearch/  
      http://mirrors.coreix.net/elrepo/elrepo/el7/$basearch/  
      http://jur-linux.org/download/elrepo/elrepo/el7/$basearch/  
      http://repos.lax-noc.com/elrepo/elrepo/el7/$basearch/  
      http://mirror.ventraip.net.au/elrepo/elrepo/el7/$basearch/  
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el7  
#enabled=1  
enabled=0  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org  
protect=0  
  
[elrepo-testing]  
name=ELRepo.org Community Enterprise Linux Testing Repository - el7  
baseurl=http://elrepo.org/linux/testing/el7/$basearch/  
      http://mirrors.coreix.net/elrepo/testing/el7/$basearch/  
      http://jur-linux.org/download/elrepo/testing/el7/$basearch/  
      http://repos.lax-noc.com/elrepo/testing/el7/$basearch/  
      http://mirror.ventraip.net.au/elrepo/testing/el7/$basearch/  
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-testing.el7  
enabled=0  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org  
protect=0  
  
[elrepo-kernel]  
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7  
baseurl=http://elrepo.org/linux/kernel/el7/$basearch/  
      http://mirrors.coreix.net/elrepo/kernel/el7/$basearch/  
      http://jur-linux.org/download/elrepo/kernel/el7/$basearch/  
      http://repos.lax-noc.com/elrepo/kernel/el7/$basearch/  
      http://mirror.ventraip.net.au/elrepo/kernel/el7/$basearch/  
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7  
enabled=0  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org  
protect=0  
  
[elrepo-extras]  
name=ELRepo.org Community Enterprise Linux Extras Repository - el7  
baseurl=http://elrepo.org/linux/extras/el7/$basearch/  
      http://mirrors.coreix.net/elrepo/extras/el7/$basearch/  
      http://jur-linux.org/download/elrepo/extras/el7/$basearch/  
      http://repos.lax-noc.com/elrepo/extras/el7/$basearch/  
      http://mirror.ventraip.net.au/elrepo/extras/el7/$basearch/  
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-extras.el7  
enabled=0  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org  
protect=0  

関連パッケージをインストール

sudo yum -y install … にてインストール

<一般>  

  • wget
  • man
  • man-pages
  • screen
  • bind-utils digコマンドとnslookupコマンドなど
  • tcpdump
    tcpdumpとはネットワーク通信の生のデータをキャプチャし、その結果を出力してくれるキャプチャツールです。
    GeoIP maxmindが提供する、IPアドレスから地理情報を確認することができるサービス
  • GeoIP-devel
  • sqlite
  • sqlite-devel
    gawk 高機能で制御文など駆使してのプログラミングが可能。

<開発一般>

  • gcc
  • gcc-c++
  • glibc
  • glibc-devel
  • glib2
  • glib2-devel
  • autoconf
  • automake
  • make
  • cmake
  • libtool  (ライブラリ生成)
  • libtool-ltdl-devel
  • patch (パッチ当てるコマンド)
  • flex (字句解析パーサ生成プログラム)

<よく使うもの>

  • openssl
  • openssl-devel
  • zlib (圧縮アルゴリズム)
  • zlib-devel
  • bzip2 (圧縮コマンド)
  • bzip2-devel
  • lzo →×
  • lzo-devel
  • snappy googleオープンソース。圧縮ライブラリ
  • snappy-devel
  • libuuid
  • libuuid (ラ イ ブ ラ リ は他 と 重 な ら ない 識 別 子 (unique identifier) を 、 ロ ー カ ル以 外 か ら も アク セ ス さ れ うる オ ブ ジ ェ クト に 対 し て 生成 す る た め に用 い ら れ る 。)
  • libuuid-devel
  • lsof

<イベントドリブン関係>

libev libevは非同期処理を扱うライブラリでnode.jsなどでも使用されている。

<ハッシュ>

  • mhash
$ sudo yum -y install php-mhash  

<暗号>

  • libsodium
$ sudo yum --enablerepo=epel install libsodium-devel  
  • libsodium-devel

malloc

  • jemalloc
sudo yum --enablerepo=epel install jemalloc-devel  
  • jemalloc-devel

<ネットワーキングAPI

  • libnet

<ネットツール>

正規表現

  • pcre (Perl正規表現と互換性のある正規表現を他の言語でも実現するために作られたライブラリ)
  • pcre-devel

<汎用パーサー>

  • bison
  • bison-devel

Xml関連とか>→ほぼわからない。

  • libxml2
  • libxml2-devel
  • libxslt
  • libxslt-devel
  • xerces-c
  • xerces-c-devel
  • expat
  • expat-devel

<IDN>

  • libidn
  • libidn-devel

<国際化関係>

  • gettext
  • gettext-devel

<ドキュメントフォーマット>

  • asciidoc

<テキストUI>

  • ncurses
  • ncurses-devel

<エディタとかインタプリタとかで>

  • readline
  • readline-devel
  • multitail
sudo yum --enablerepo=epel install multitail  

ntpdate

時刻同期

$ date(確認)  
$ sudo hwclock -r(ハードウェアクロックの確認)  
  
$ sudo yum -y install ntp  
$ sudo ntpdate ntp.nict.jp  
# systemctl start chronyd  
ps ax | grep chrony  
# vi /etc/chrony.conf  #添付ファイル参照

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.nict.jp iburst
server ntp.jst.mfeed.ad.jp iburst

# Ignore stratum in source selection.
stratumweight 0

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Enable kernel RTC synchronization.
rtcsync

# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3

# Allow NTP client access from local network.
allow 192.168/16

# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1

# Serve time even if not synchronized to any NTP server.
#local stratum 10

keyfile /etc/chrony.keys

# Specify the key used as password for chronyc.
commandkey 1

# Generate command key if missing.
generatecommandkey

# Disable logging of client accesses.
noclientlog

# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.5

logdir /var/log/chrony
#log measurements statistics tracking
# chronyc sources -v(確認)  
# systemctl enable chronyd(自動起動設定)  

sysstat

# systemctl status sysstat(状態確認)  
# sar -u 1 (CPUの使用状況)  

不要なサービス

[postfix] (http://jetbeaver.hatenablog.com/entry/2015/05/10/114915)のみ

開発ディレクトリ作成

# cd project/  
# mkdir test-0  
# ls   
# chown kidnohr test-0/  
# chown -R kidnohr test-0/  
# ll  
# chgrp -R kidnohr test-0/  
# ll  

logrotate

$ sudo vi /etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
daily

# keep 4 weeks worth of backlogs
rotate 15

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
compress

# RPM packages drop log rotation information into this directory
#include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
    minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.