プログラミングとかLinuxとかの備忘録

プログラミング、Linuxでハマった箇所や環境構築のメモ

CentOS7でNFSサーバを使う

インストール

minimalインストールではすでにインストールされていた.

多分,以下のコマンドでインストールできる

$ sudo yum -y install nfs-utils

ファイアウォールの設定

$ sudo firewall-cmd --add-service=nfs --permanent
$ sudo firewall-cmd --add-service=rpc-bind --permanent

$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-service
dhcpv6-client nfs rpc-bind samba ssh

共有ディレクトリの設定

/etc/exportsの設定

$ sudo vi /etc/exports
/path/to/share 192.168.1.0/24(rw,async,no_root_squash)
オプション 内容
rw 読み書きを許可する
async 非同期書き込み
no_root_squash rootをanonymousにマッピングしない

サービス起動

$ sudo systemctl start rpcbind nfs-server
$ sudo systemctl enable rpcbind nfs-server

公開状態の確認

$ exportfs
/path/to/share 192.168.1.0/24

クライアントの設定

$ sudo yum -y install nfs-utils

/etc/fstabの編集

$ sudo vi /etc/fstab
SERVER:/path/to/share    /mnt/tmp            nfs defaults    0 0

References

  1. CentOS 7 : NFSサーバーの設定 : Server World
  2. ディレクトリをディレクトリにマウント

Fedora22がシャットダウンできない

昨日(2015-09-29)から

  • CentOS7のKVM上のfedora22(mate)
  • Windows10のVirtualBox上のFedora22(mate)

がシャットダウンできない現象が起こっている
(GUIからシャットダウンするとログアウトするだけでシャットダウンされない)

コマンドから実行すると

$ sudo shutdown -h now
Failed to start poweroff.target: Access denied

Broadcast message from USER@HOST on pts/0 (...):

The system is going down for power-off NOW!

と表示されるだけで何も起こらない

ここを見るとselinuxが原因っぽいので,以下のコマンドでselinuxを無効にするとシャットダウンできる用になった

$ sudo /usr/sbin/setenforce 0

selinuxを永続的に無効にするには
以下の用にSELINUX=disabledに書き換えれば良い

$ sudo vi /etc/selinux/config
SELINUX=disabled

yum updateしたらkernel panicで起動しなくなった

環境

CentOS7.2上のKVM上のCentOS7.2で

状況

yum updateカーネル
3.10.0-327.22.2.el7.x86_64
から
3.10.0-327.28.2.el7.x86_64
アップデートされ,久しぶりに再起動するとKernel Panicで以下のメッセージが表示され,起動できていなかった

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 0 PID 1 Comm: swapper/0 Not tainted 3.10.0-327.28.2.el7.x86_64
Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
...

解決法

新しいカーネル(3.10.0-327.28.2.el7.x86_64)のinitramfsが生成されていないのが原因らしい

とりあえず,古いカーネル(3.10.0-327.22.2.el7.x86_64)で起動し

$ ls -l /boot | grep initramfs
-rw-r--r--. 1 root root 57613265  5月 31 10:42 initramfs-0-rescue-1016740bf95247ae941d721fac81bcaa.img
-rw-------. 1 root root 29887789  8月  8 10:14 initramfs-3.10.0-327.18.2.el7.x86_64.img
-rw-------. 1 root root 29886600  8月  8 10:14 initramfs-3.10.0-327.22.2.el7.x86_64.img
-rw-------. 1 root root 19841024  8月  8 10:14 initramfs-3.10.0-327.el7.x86_64.img

initramfs-3.10.0-327.28.2.el7.x86_64.imgがないので,以下のコマンドで生成

$ sudo depmod 3.10.0-327.28.2.el7.x86_64
$ sudo mkinitrd initramfs-3.10.0-327.28.2.el7.x86_64.img 3.10.0-327.28.2.el7.x86_64

$ ls -l /boot | grep initramfs
-rw-r--r--. 1 root root 57613265  5月 31 10:42 initramfs-0-rescue-1016740bf95247ae941d721fac81bcaa.img
-rw-------. 1 root root 29887789  8月  8 10:14 initramfs-3.10.0-327.18.2.el7.x86_64.img
-rw-------. 1 root root 29886600  8月  8 10:14 initramfs-3.10.0-327.22.2.el7.x86_64.img
-rw-------. 1 root root 29885799  8月 19 23:07 initramfs-3.10.0-327.28.2.el7.x86_64.img
-rw-------. 1 root root 19841024  8月  8 10:14 initramfs-3.10.0-327.el7.x86_64.img

grub.cfgの新しいカーネルのセクションを確認
セクション最終行の
initrd16 /initramfs-3.10.0-327.28.2.el7.x86_64.imgが抜けていたため,追記した

$ sudo vi /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-327.28.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-fdca8898-0b12-4e30-a4c6-abb66c8f1ddc' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  d03afdf1-35b8-4289-93fb-6363859211c4
        else
          search --no-floppy --fs-uuid --set=root d03afdf1-35b8-4289-93fb-6363859211c4
        fi
        linux16 /vmlinuz-3.10.0-327.28.2.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=ja_JP.UTF-8
        initrd16 /initramfs-3.10.0-327.28.2.el7.x86_64.img

これで,無事起動できるようになった


Reference

UbuntuにDropboxをインストールする

Ubuntu16.04で実行

パッケージマネージャからインストール

$ sudo apt -y install caja-dropbox
$ caja-dropbox start -i

すると

(dropbox:24401): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplayManager'

(dropbox:24401): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(dropbox:24401): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

と表示されアカウント認証画面に移動しなかった.

手動インストール

dropbox failing to start on Ubuntu 14 – Dropbox Community によるとDropboxのバージョンが古いと同様の症状が出るらしいので 手動でインストールする

インストール

Linux マシンに Dropbox をインストールを参考に行う

$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
$ ~/.dropbox-dist/dropboxd

すればログイン画面が開くのでログインする

管理用スクリプトのインストール

$ wget https://www.dropbox.com/download?dl=packages/dropbox.py

でダウンロードしたdropbox.pyを適当な場所に保存.

設定

  • デーモン起動
$ ./dropbox.py start
./dropbox.py autostart y

CentOS7にDNSサーバを立てる

dnsmasqのインストール

$ sudo yum -y install dnsmasq

設定

DNSの設定

サーバのIPの固定

$ sudo nmcli connection modify eth0 ipv4.address "192.168.1.2/24"
$ sudo nmcli connection modify eth0 ipv4.gateway "192.168.1.1"
$ sudo nmcli connection modify eth0 ipv4.dns "192.168.1.1"
$ sudo nmcli connection modify eth0 ipv4.method manual
$ sudo nmcli connection modify eth0 connection.autoconnect yes

に加え,上位DNS(192.168.1.1)の前にlocalhost(127.0.0.1)をDNSとして追加する

$ sudo nmcli connection modify eth0 ipv4.dns "127.0.0.1 192.168.1.1"

ネットワークの再起動

$ sudo nmcli connection down eth0 && sudo nmcli connection up eth0

ファイアウォールの設定

$ sudo firewall-cmd --permanent --add-port 53/tcp
$ sudo firewall-cmd --permanent --add-port 53/udp
$ sudo systemctl restart firewalld

サーバ起動

$ sudo systemctl start dnsmasq
$ sudo systemctl enable dnsmasq

使い方

サーバの/etc/hostsにIPとホスト名を追加していくだけ

$ sudo vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.10 SERVER1
192.168.1.11 SERVER2

/etc/hosts変更後はdnsmasqを再起動する

$ sudo systemctl restart dnsmasq

CentOS7でDockerを動かす

ホスト情報

$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

$ uname -r
3.10.0-229.20.1.el7.x86_64

Dockerのインストール

$ sudo yum -y install docker

Docker実行ユーザの設定

Dockerのサービスを起動せずにdocker imagesとかを実行すると

$ docker images
Get http:///var/run/docker.sock/v1.20/images/json: dial unix /var/run/docker.sock: no such file or directory.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

エラーが発生したので,サービスを起動

$ sudo systemctl start docker
$ sudo systemctl enable docker

再びDockerを起動すると

$ docker images
Get http:///var/run/docker.sock/v1.20/images/json: dial unix /var/run/docker.sock: permission denied.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

権限がないらしいのでsudoで実行するか実行ユーザをdockerグループに追加する
今回は,実行ユーザをdockerグループに追加する (dockerグループが存在しなかったので作成した)

$ sudo groupadd docker
$ sudo gpasswd -a 実行ユーザ名 docker

サービスを再起動すると一般ユーザからアクセスできるようになった

$ sudo systemctl restart docker

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

後は使うだけ