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

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

KVMでゲストがDNS名前解決できない

エラー内容

CentOS7へのKVMのインストール方法で構築したサーバを再起動するとゲストがDNSでの名前解決を行えなくなった

ホスト (問題なし)

$ ping 192.168.1.1      =< OK
$ ping 8.8.8.8          =< OK
$ ping google.com       =< OK

ゲスト (DNSが動かない)

$ ping 192.168.1.1      =< OK
$ ping 8.8.8.8          =< OK
$ ping google.com       =< OUT

解決方法

[SOLVED] KVM and guest DNS - CentOSの最後に書いてあるとおり,ブリッジにはiptablesのルールを適用しない設定を追加すれば動くようになった

$ sudo vi /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

$ sudo sysctl -p /etc/sysctl.conf

2.2.10. ソースルーティングの無効化
に,/etc/sysctl.confに追加しておけば永続化されると書いてあるが,再起動しても自動設定されていなかった...

Ubuntu16.04をNISクライアントにする

NISサーバ

CentOS7にNISサーバ,クライアントをインストールする
でセットアップしたNISサーバを使用する

インストール

$ sudo apt-get -y install nis
...
Setting up nis (3.17-34ubuntu3) ...   # ここで,ある程度時間がかかった

設定

$ sudo vim /etc/hosts
NISサーバIP  NISサーバ名

$ sudo vim /etc/yp.conf
domain ドメイン名 server サーバ名

nsswhitch.confの編集

$ sudo vim /etc/nsswitch.conf   # 以下の行にnisを追加する
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat nis
group:          compat nis
shadow:         compat nis
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns nis
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

ログイン時にホームディレクトリがなければ,自動生成するようにする設定を最終行に追加

$ sudo vi /etc/pam.d/common-session
session optional        pam_mkhomedir.so skel=/etc/skel umask=077

サービス起動

$ sudo systemctl start nis
$ sudo systemctl enable nis

これでだけでは,yptestの結果が以下の様になり,ypbindと通信できなかったので

$ yptest
Test 1: domainname
Configured domainname is "ドメイン名"

Test 2: ypbind
Can't communicate with ypbind

[SOLVED] (K)ubuntu 16.04 NIS client does not work after installingに書いてある通りに,以下のコマンドを実行すると正常に動いた

$ sudo systemctl add-wants multi-user.target rpcbind.service

References

CentOS7にNISサーバ,クライアントをインストールする

今回は,サーバ,クライアントともにCentOS7で行った

サーバの設定

インストール

$ sudo yum -y install ypserv rpcbind

ドメイン名の設定

$ ypdomainname ドメイン名

$ sudo vi /etc/sysconfig/network
# Created by anaconda
NISDOMAIN=ドメイン名

アクセス範囲の設定

$ sudo vi /var/yp/securenets
# 255.0.0.0       127.0.0.0
255.255.255.0   192.168.1.0

NISサーバ,クライアントのIPを登録

$ sudo vi /etc/hosts
192.168.1.2     サーバ名
192.168.1.3     client1
192.168.1.4     client2
192.168.2.2     client3

サービスの起動

$ systemctl start rpcbind ypserv ypxfrd yppasswdd
$ systemctl enable rpcbind ypserv ypxfrd yppasswdd

データベースの更新

$ sudo /usr/lib64/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS
servers.  サーバ名 is in the list of NIS server hosts.  Please continue to add
the names for the other hosts, one per line.  When you are done with the
list, type a >control D<.
        next host to add:  サーバ名
        next host to add:                       # コントロール+D
The current list of NIS servers looks like this:

サーバ名

Is this correct?  [y/n: y]  y
We need a few minutes to build the databases...
Building /var/yp/ドメイン名/ypservers...
Running /var/yp/Makefile...
gmake[1]: ディレクトリ `/var/yp/ドメイン名` に入ります
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
Updating hosts.byname...
Updating hosts.byaddr...
Updating rpc.byname...
Updating rpc.bynumber...
Updating services.byname...
Updating services.byservicename...
Updating netid.byname...
Updating protocols.bynumber...
Updating protocols.byname...
Updating mail.aliases...
gmake[1]: ディレクトリ `/var/yp/ドメイン名` から出ます

サーバ名 has been set up as a NIS master server.

Now you can run ypinit -s サーバ名 on all slave server.

クライアントの設定

インストール

$ sudo yum -y install ypbind rpcbind

SELinuxの無効化

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

ドメイン名の設定

$ sudo ypdomainname ドメイン名

$ sudo vi /etc/sysconfig/network
# Created by anaconda
NISDOMAIN=ドメイン名

NISサーバ,自身のIPを登録

$ sudo vi /etc/hosts
192.168.1.2    サーバ名
192.168.1.3    自身のホスト名

NISサーバ情報を登録

$ sudo authconfig --enablenis --nisdomain=ドメイン名 --nisserver=サーバ名 --enablemkhomedir --update
getsebool:  SELinux is disabled
getsebool:  SELinux is disabled

NISクライアントの起動

$ sudo systemctl start rpcbind ypbind
$ sudo systemctl enable rpcbind ypbind

NISサーバへのユーザの追加

ユーザを追加

NISサーバ上で普段どおりに追加する

$ sudo useradd ...

NISデータベースへの登録

以下のコマンドでさーばのデータベースを更新し,NISを再起動する

$ cd /var/yp
$ sudo make
$ sudo systemctl restart ypserv ypxfrd yppasswdd

References

LinuxでのNFSサーバが自動マウントされない

問題

/etc/fstabを使用してNFSサーバを自動マウント使用とすると,起動時に

[  ***  ] A start job is running for /mnt/server (12s / 1min 32s)

と表示されてOSの起動に時間がかかり,自動マウントもされていない.
多分,システム起動時にネットワーク接続が確立されていないためマウントされなかった?

解決法1: 起動スクリプト

/etc/fstabは使用せずに,/etc/rc.d/rc.localにマウント用のコマンドを記述する

$ sudo vi /etc/rc.d/rc.local
mount -t nfs SERVER:/ /mnt/server

実行権の付与

$ sudo chmod a+x /etc/rc.d/rc.local

解決法2: autofs

インストール (CentOS7)

$ sudo yum -y install autofs

インストール (Ubuntu)

$ sudo apt-get -y install autofs

マスターファイルの編集

対象にするディレクトリとマップファイルをauto.masterの最終行に追加

$ sudo vi /etc/auto.master
/mnt   /etc/auto.mnt

マップファイルの編集

$ sudo vi /etc/auto.mnt
share1  SERVER:/share1
share2  SERVER:/share2

サービス起動

$ sudo systemctl start autofs
$ sudo systemctl enable autofs

これで,

$ cd /mnt/share1

とかするとアクセスできる.

LinuxでのLaTex環境構築方法

インストール

Fedora23

$ sudo dnf -y install texlive*
$ sudo dnf -y install latexmk
$ sudo dnf -y install texstudio

Ubuntu15.10

$ sudo apt-get -y install texlive-full
$ sudo apt-get -y install texstudio

自動ビルド設定

latexmkで楽々TeXタイプセットの薦め
を参考にlatexmkを使用した自動ビルド環境の構築を行う

以下のファイルを作成すると

$ vim ~/.latexmkrc
#!/usr/bin/env perl
$latex            = 'platex -synctex=1 -halt-on-error';
$latex_silent     = 'platex -synctex=1 -halt-on-error -interaction=batchmode';
$bibtex           = 'pbibtex';
$dvipdf           = 'dvipdfmx %O -o %D %S';
$makeindex        = 'mendex %O -o %D %S';
$max_repeat       = 5;
$pdf_mode         = 3; # generates pdf via dvipdfmx

# Prevent latexmk from removing PDF after typeset.
# This enables Skim to chase the update in PDF automatically.
$pvc_view_file_via_temporary = 0;

# Use Skim as a previewer
$pdf_previewer    = "open /Applications/Skim.app";
$ latexmk -pvc hoge.tex

とすればtexが変更された時にpdfが自動生成されるようになる

TeXstudioの設定

オプション -> TeXstudioの設定から設定を行う
まず,左下の高度なオプションの表示にチェックを入れる

一般

ビルド

  • ビルド&表示: txs:///dvi-pdf-chain
  • 既定のコンパイラ: txs:///latex

詳細なエディタ設定

ヘルプ -> TeXstudioについてで確認するとQt5版であったため

ハック/回避策

  1. 最適なディスプレイオプションの自動選択をoffにする
  2. 描画モードをQtにする

References

CentOS7にCLionをインストールする

CentOS7へのCLionのインストール方法
アップデートも同じ方法でできる

ダウンロード

JetBrains CLion — intelligent cross-platform C/C++ IDE
Download Clionからダウンロードする (有料版のみ)
(参考: JetBrainsのIDEをアカデミックライセンスで使用する

インストール

ビルドツールのインストール

$ sudo yum -y install cmake
$ sudo yum -y install gdb
$ sudo yum -y install gcc gcc-c++

ダウンロードしたファイルを解凍

$ tar -xf clion-1.1.1.tar.gz
$ mv clion-1.1.1 /usr/local/clion

初回起動・初期設定

$ cd /usr/local/clion/bin
$ ./clion.sh

アカデミックライセンスを持っているため,Clion License ActivationではJetBrains Accoutを選択し,アカウント情報を入力した

f:id:vild:20200606171003p:plain
CLion Lincense Activation

初期設定では

  • UI theme: Darcula
  • Configure CMake and debugger:
    • CMake (Use specified): /usr/bin/cmake
    • Debugger (Use specified): /usr/bin/gdb

とした(後はnext連打)

IDEの設定

  • File -> Settings -> Editor -> General -> Appearance
    • Show line numbers
    • Show whitespaces
  • File -> Settings -> Editor -> General -> Code Completion

  • Samba上にプロジェクトを置く場合
    External file changes sync may be slowを表示させないために
    File -> Settings -> Appearance & Behavior -> Notifications -> AppearanceからFile Watcher MessagesNo popupにする

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. ディレクトリをディレクトリにマウント