VMware+CentOS7で開発環境構築 - 2.環境設定

現在Minimalでインストールしたため、必要最低限のパッケージしかインストールされていない。
(VMWareToolsをインストールしようとしたらperlすら入っていなかった。)
インターネットに繋がる状態にして必要なものをyumでインストールできる状態にする。

ネットワーク設定

CentOSインストール時の初期設定「ネットワークとホスト名」で設定した状態が反映されているか確認。
(CentOS7から大幅に変更になったため、CentOS6以前のコマンド入力に慣れていた方は不便に感じるかもしれない。)
# ip addr show
ip a show でも同じでした。
# nmcli d show
CentOSネットワーク設定
# hostname
# cat /etc/hostname
変更する必要がある場合
  • アドレス:192.168.137.100
  • Gateway:192.168.137.1
  • DNS:192.168.137.1
  • ホスト名:kowloonet.local
に変更する例
# nmcli c modify ens33 ipv4.address 192.168.137.100
# nmcli c modify ens33 ipv4.gateway 192.168.137.1
# nmcli c modify ens33 ipv4.dns 192.168.137.1
# nmcli c down ens33
# nmcli c up ens33
# nmcli g hostname kowloonet.local
(# hostnamectl set-hostname kowloonet.local でも可)
ホストのIPに繋がるか確認
# ping 192.168.137.1
外のアドレスに繋がるか確認。
# ping www.livedoor.com

初期設定

VMWare上のコンソール操作は非常にやりにくいので、PuTTY、TeraTermなどのSSHクライアントソフトからCentOSに繋がるようにして、以後SSHクライアントから操作。ネットワークの設定を終えたら、そのままでも接続できる。開発環境なので、このまま使ってもかまわないが、気持ちが悪いので、必要最低限の設定だけやっておく。クライアントの使いかたは割愛。
ファイアーウォール停止
# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive
# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled ← disabled に変更
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
# systemctl stop firewalld
# systemctl disable firewalld
rootになれるユーザの管理
# usermod -G wheel xiohei
# vi /etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid ←コメント削除
auth            substack        system-auth
auth            include         postlogin
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         include         postlogin
session         optional        pam_xauth.so
root宛のメールを一般ユーザで受け取る
# sed -i '/^root:/d' /etc/aliases
# echo "root: xiohei" >> /etc/aliases
# newaliases
稼働中のサービスの表示
# systemctl list-units --type=service
systemctl - centos
Kdumpはメモリが1G以上無いと動かないようで、使わないので止めておく。
# systemctl disable kdump
定義されているサービスの表示
# systemctl list-unit-files --type=service
systemctl - centos
サービスの状態を表示
# systemctl status sshd
パッケージアップデート
# yum -y update
・
・
Cannot find a valid baseurl for repo: base/7/x86_64
と出てしまったので、設定を見直し。ついでに日本のミラーサイトをみるように変更。
# vi /etc/yum.repos.d/CentOS-Base.repo
mirrorlist= の行をコメントにし
baseurl=http://ftp.riken.jp/Linux/centos/~
を[base]、[updates]、[extras]、[centosplus]に追加
[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/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

##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/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#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/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing package
[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/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# yum -y update
開発ツールのインストール
# yum -y groupinstall base "Development tools"
少々お時間かかります。
perlも無事に入ったので、
PERLのシンボリックリンク作成
# ln -s /usr/bin/perl /usr/local/bin/perl
mailコマンドが使えるようになったので、root宛のメールの転送テスト。
# echo tesMmessage|mail root
# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/xiohei": 1 message 1 unread
>U  1 root                  Sat Sep 16 10:13  18/562
& 1 ← 1 ENTER でメールの内容を表示
Message  1:
From root@kowloonet.local  Sat Sep 16 10:13:05 2017
Return-Path: 
X-Original-To: root
Delivered-To: root@kowloonet.local
Date: Sat, 16 Sep 2017 10:13:05 +0900
To: root@kowloonet.local
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@kowloonet.local (root)
Status: RO

testMessage

& quit ← quit [ENTER]で抜ける
Held 1 message in /var/spool/mail/xiohei
メールが /var/spool/mail/xiohei にあります

vimの設定

最終行に「alias vi='vim'」を追加
# vi /etc/profile
done

unset i
unset -f pathmunge

alias vi='vim'
# source /etc/profile

VMWareToolsのインストール

CDマウント
# mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
# cp /mnt/cdrom/VMWareTools-10.1.6-5214329.tar.gz /tmp/
# cd /tmp
# tar zxvf VMWareTools-10.1.6-5214329.tar.gz
# umount /mnt/cdrom
# cd vmware-tools-distrib/
このままでは、VMwareToolsをインストールできない(できなかった)ので
  • kernel-devel
  • policycoreutils-python (semanag コマンドが必要なためこれを入れる)
を入れておく。
# yum -y install kernel-devel
# yum -y install policycoreutils-python
# ./vmware-install.pl

NTPの設定

# 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.ring.gr.jp iburst ←追加
server time.google.com iburst ←追加

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

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 192.168.1.0/24 ←追加
# systemctl start chronyd
# systemctl enable chronyd
# systemctl status chronyd
# date