- 追加された行はこのように表示されます。
- 削除された行は
このように表示されます。
!!!CentOS 初期設定
[CentOS][Linux][Fedora][CentOS7]
*初期設定する手順をまとめておく
!!!インストール
!!バージョンの確認
# cat /etc/*release
CentOS release 6.2 (Final)
CentOS release 6.2 (Final)
CentOS release 6.2 (Final)
!!ネットワークインストール
!例
::ネットワークインストール用 bootイメージ
*以下から探す
**ftp://ftp.riken.jp/Linux/centos/
*例 6.2
**ftp://ftp.riken.jp/Linux/centos/6.2/isos/i386/CentOS-6.0-i386-netinstall.iso
::FTPインストール指定先
*以下から探す
**ftp://ftp.riken.jp/Linux/centos/
*例 6.2
**ftp://ftp.riken.jp/Linux/centos/6.2/os/i386/
!![Xen ゲストOSとしてインストール|http://typea.info/blg/glob/cat5/]
*Fedora Core 6 Xen のインストール
*[Xen ゲストOSとしてインストール|http://typea.info/blg/glob/cat5/]
!!日本語環境の設定
!日本語サポートのインストール
# yum groupinstall install "Japanese Support"
# vi /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
!日本語フォントのインストール
::[テキストモードでインストールすると、日本語フォントがインストールされない|http://typea.info/blg/glob/2007/01/post.html]
{{ref_image centos_init03.jpg}}
::日本語フォントをインストールする
# yum install fonts-japanese
{{ref_image centos_init04.jpg}}
!!!最初の設定
!!SSH
*~/.ssh/config に接続情報を記述しておくとsshのログインパラメータを都度指定する必要がない
Host phraseit.info
HostName phraseit.info
IdentityFile ~/.ssh/xxxxxx.pem
User ec2-user
Host typea.info
HostName typea.info
User root
Port 3843
!Cygwinでconfigファイルを利用するには以下の手順が必要
$ chgrp Users config
$ chmod 600 config
!Cygwinで公開鍵を使う場合以下の手順が必要
chgrp Users ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
!!ネットワーク設定
![[IPアドレスの設定|Linux ネットワーク設定 ifconfig]]
!!VNCを使えるようにする。
*GUIを使えると便利な局面も多いので、まずVNCを使えるようにしておく
*[[Fedoraと同様|Fedora Core 6 ファイヤーウォールの設定]]まず、コマンドから、5901ポートを開けて、VNCサーバーを使えるようにする。
!CentOS 7
""以下の手順ではサービスがACTIVEにならず
::install
# yum install tigervnc-server
::設定編集
# cat /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service
*Copy this file to /etc/systemd/system/vncserver@:<display>.service
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
*Edit <USER> and vncserver parameters appropriately ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2") [Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l piroto -c "/usr/bin/vncserver -geometry 1024x768 -nolisten tcp -localhost"
PIDFile=/home/piroto.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
# su piroto
[piroto@localhost system]$ vncpasswd
Password:
Verify:
*Run `systemctl daemon-reload`
# systemctl daemon-reload
*Run `systemctl enable vncserver@:<display>.service`
# systemctl enable vncserver@:1.service
ln -s '/etc/systemd/system/vncserver@:1.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:1.service'
!Firewall
# firewall-cmd --permanent --zone=public --add-port=5900-5910/tcp
success
# firewall-cmd --reload
success
!CentOS 6
::install
# yum install tigervnc-server
::設定編集(pirotoはユーザー名)
# vi /etc/sysconfig/vncservers
:
VNCSERVERS="1:piroto"
VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -localhost"
!Chain(RH-Firewall-1-INPUT) および、インデックス(10) は iptables -L で確認し、適宜値を変える
# iptables -I RH-Firewall-1-INPUT 10 -m state --state NEW -p tcp --dport 5901 -j ACCEPT
*8は挿入位置、5900:5910 はポート範囲
*http://www.cyberciti.biz/tips/linux-iptables-how-to-specify-a-range-of-ip-addresses-or-ports.html
# iptables -I INPUT 8 -p tcp --dport 5900:5910 -j ACCEPT
!保存と再起動
# service iptables save
# service iptables restart
!確認
# iptables -L
:
Chain RH-Firewall-1-INPUT (2 references)
:
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:5901
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
!!VNCサーバーの起動
[[Fedora同様の処理|Fedora Core 6 VNCの設定]]
!Twn 以外のウィンドウマネージャーを使えるように switchdesk をインストール
# yum install switchdesk
!VNCサーバーの設定を置き換え
# switchdesk gnome
Red Hat Linux switchdesk 4.0
Copyright (C) 1999-2004 Red Hat, Inc
Redistributable under the terms of the GNU General Public License
Desktop now set up to run GNOME.
# cd /root/.vnc
# mv xstartup xstartup.bak
# ln -s /root/.Xclients xstartup
!解像度の変更
*/usr/bin/vncserver の geometry に解像度を指定
#
# Global variables. You may want to configure some of these for your site.
#
$geometry = "1360x600";
!起動
# vncserver
New 'krishna.typea.info:1 (root)' desktop is krishna.typea.info:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/krishna.typea.info:1.log
{{ref_image centos_vnc01.jpg}}
!終了
#vncserver -kill :1
!自動起動
*/etc/sysconfig/vncservers を編集
*以下をコメントイン
VNCSERVERS="1:piroto"
VNCSERVERARGS[2]="-geometry 1366x768 -nolisten tcp -localhost"
*サービスの設定
# chkconfig --level 3 vncserver on
!!SELinux の設定
!SELinux の無効化
::確認
*有効
[root@susanoo vsftpd]# getenforce
Enforcing
*無効
[root@susanoo vsftpd]# getenforce
Permissive
::無効化
[root@susanoo vsftpd]# setenforce 0
::設定ファイル編集
# vi /etc/selinux/config
*SELINUX=enforcing → disabled に変更
#chroot_list_file=/etc/vsftpd/chroot_list
# 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
::SELinuxコンテキスト
*ls-al したときに、末尾にピリオドがついているものは、SELinuxコンテキストが付与されている
drwxr-xr-x. 8 root root 4096 8月 16 19:46 2013 repo
*-Zで内容を確認できる
drwxr-xr-x. root root unconfined_u:object_r:user_home_t:s0 repo
!!ファイアーウォールの設定
!iptables
*http://dream.jp/vps/support/manual/mnl_security_04.html
::Chain
iptablesは、指定したルールに当てはまるパケットに対しての、処理内容を定義します。このルールのグループをチェインと言い、このチェインには、最初から定義されている組み込みチェインと、後から定義するユーザー定義チェインの2種類があります。
::policy
各チェイン毎のルールのどれにもマッチしない場合は、そのチェインに定義されている「policy」の内容により、パケットを処理します。
*Chain INPUT (policy ACCEPT):サーバーに入ってくるパケットのうち、設定したどのルールにもマッチしない場合は、パケットを通過させる。
*Chain OUTPUT (policy DROP):サーバーから出て行くパケットのうち、設定したどのルールにもマッチしない場合は、パケットを破棄する。
::target
*ルールに該当するパケットの処理方法
*ACCEPT:パケットを通過させる
*DROP:パケットを破棄する
::prot
プロトコル名
*all:全てのプロトコル
*tcp:tcpプロトコル
::source
送信元IPアドレス
::destinatior
送信先IPアドレス
::iptablesコマンドのオプション
,チェイン,説明
,-P (policy),指定したチェインのポリシーを変更
,-A (--append),指定したチェインに新しいルールを追加
,-D (--delete),指定チェインのルールを削除
,-N (--new-chain),新しいユーザー定義チェインを作成
,-X (--delete-chain),指定したユーザー定義チェインを削除
,-F,ルールの初期化(※policyの設定は初期化されません)
,条件,説明
,-j (--jump),ターゲット 条件に合った際のアクションを指定
,-p (--protocol),"プロトコル名 プロトコル名(tcp, udp, icmp, all)を指定"
,-s (--source),IPアドレス 送信元アドレス(IPアドレスかホスト名)を指定
,-d (--destination),IPアドレス 送信先アドレス(IPアドレスかホスト名)を指定
,--sport,"送信元ポート番号 送信元ポート番号(80, httpなど)を指定"
,--dport,"宛先ポート番号 宛先ポート番号(80, httpなど)を指定"
,-i (--in-interface),デバイス パケット入力のインターフェースを指定
,-o (--out-interface),デバイス パケットを出力するインターフェースを指定
,アクション,説明
,ACCEPT,パケットの通過を許可
,DROP,通過しようとするパケットの破棄
,LOG,ログの取得
,REJECT,パケットを拒否し、ICMPメッセージを返信
::バックアップ
# cd /etc/sysconfig
# cp iptables iptables.old
cp: `iptables.old' を上書きしてもよろしいですか(yes/no)? y
::80,80ポートを許可する例
-A INPUT -p tcp --dport http -j ACCEPT
-A INPUT -p tcp --dport 8080 -j ACCEPT
::起動、停止、再起動
# /etc/rc.d/init.d/iptables start
# /etc/rc.d/init.d/iptables stop
# /etc/rc.d/init.d/iptables restart
::確認
# iptables -nL
!GUIから、ファイアーウォールを設定する。
{{ref_image centos_init05.jpg}}
::WWW や FTP のポートを利用可能に
{{ref_image centos_init06.jpg}}
!!FTPサーバー
*[[Fedora同様|Fedora Core 6 FTP サーバの構築]]
!インストールされているか確認
# rpm -q vsftpd
package vsftpd is not installed
!インストール
# yum install -y vsftpd
Loaded plugins: fastestmirror
:
Installed:
vsftpd.i686 0:2.2.2-11.el6_4.1
Complete!
!vsftpd の確認
# rpm -q vsftpd
vsftpd-2.0.5-16.el5_4.1
!設定の編集
/etc/vsftpd/vsftpd.conf
::Anonymous ログインを無効にする
#anonymous_enable=YES
::ログを出力させる
xferlog_file=/var/log/vsftpd.log
::接続制限
*以下を確認
tcp_wrappers=YES
*/etc/hosts.allow に以下を追記(制限をかけるときはここで)
vsftpd : ALL : ALLOW
!ユーザーの追加
::rootでは ftp サーバーにログインできない。
""非推奨だが、root でログインできる様にするためには、/etc/vsftpd/ftpusers、/etc/vsftpd/user_list の両方からroot 行をコメントアウトすることで可能
*ユーザーを追加して、パスワードを設定して、root グループに所属させる(任意)
*Linux ユーザ管理
# useradd xxxx
# passwd xxxx
# gpasswd -a xxx root
!CentOs6 ランレベル 3 で自動起動するように
*Systemd
*Linux ランレベル
# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
# runlevel
N 3
# chkconfig --level 3 vsftpd on
!CentOs7 OS起動時に起動させる
# systemctl enable vsftpd
!テキストモードで起動
::CentOS6
*常に
id:5:initdefault: -> id:3:initdefault:
# vi /etc/inittab
:
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
*今回のみ
# init 3
!ファイアーウォールの設定
::CentOS7
*Firewall
# firewall-cmd --add-service=ftp --permanent
success
# firewall-cmd --reload
success
::CentOS 6
*/etc/sysconfig/iptables-config に追記
IPTABLES_MODULES="nf_conntrack_ftp"
*iptables の再起動
# service iptables restart
*iptables の設定と保存
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -I INPUT -p tcp -m tcp --dport ftp -j ACCEPT
# service iptables save
# service iptables restart
!SELinuxによりエラー
*以下の様なエラーはSELinuxが出している。SELinuxを無効にするには、setenforce 0 を実行
*上記、SELinux の無効化 参照
C:\Users\piroto>ftp 192.168.24.12
192.168.24.12 に接続しました。
220 (vsFTPd 2.2.2)
ユーザー (192.168.24.12:(none)): root
331 Please specify the password.
パスワード:
500 OOPS: cannot change directory:/root
500 OOPS: priv_sock_get_cmd
接続がリモート ホストによって閉じられました。
!起動設定
::Centos7
# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
!!ウェブサーバー
!設定
*/etc/httpd/conf/httpd.conf を編集
::CGIを利用可能に
<Directory "/var/www/html/tips">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
!起動
# service httpd start
httpd を起動中: [ OK ]
!確認
{{ref_image centos_init07.jpg}}
!ランレベル 3 で自動起動するように
*Linux ランレベル
# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# runlevel
N 3
# chkconfig --level 3 httpd on
!mod_rewrite を利用できるようにする場合
*http://centoshome.seesaa.net/article/118972004.html
*コメントを外す
LoadModule rewrite_module modules/mod_rewrite.so
*AllowOverride を Allに
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride All
*再起動
/sbin/service httpd restart
!SSL
*https://weblabo.oscasierra.net/letsencrypt-2/
# yum install epel-release
# yum install certbot python-certbot-apache
{{ref SSL.pdf}}
{{ref SSL_CRON.pdf}}
!!subversion
!インストール
*subversionの導入
# yum install subversion
# yum install mod_dav_svn.so
!リポジトリの作成
# mkdir /var/www/svn
# cd /var/www/svn
# svnadmin create repo
# chown -R apache.apache repo
!パスワードの設定
# htpasswd /etc/httpd/.passwd svn
!設定ファイルの変更
::/etc/httpd/conf.d/subversion.conf
<Location /svn>
DAV svn
SVNParentPath /var/www/svn
# Limit write permission to list of valid users.
<LimitExcept GET PROPFIND OPTIONS REPORT>
# Require SSL connection for password protection.
# SSLRequireSSL
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /etc/httpd/.passwd <- 上で作成したパスワードファイルを指定
Require valid-user
</LimitExcept>
</Location>
Location /svn で場所を指定する
!再起動
# /sbin/service httpd restart
!引っ越し
subversion リポジトリの引越し
!!GCC
!インストール
*これがないと、ソースからコンパイルできない
# yum install gcc
!!Python
*CentOS6にPython2.7をインストール
!!MySQL
!インストール
# yum install mysql-server
!起動
# /etc/rc.d/init.d/mysqld start
::自動起動
# chkconfig --level 3 mysqld on
!設定
::root パスワードの変更
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> set password for 'root'@'localhost' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'krishna.typea.info' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'127.0.0.1' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
::ユーザーの作成
mysql> create user piroot@"%";
Query OK, 0 rows affected (0.00 sec)
mysql> create user piroot@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'piroot'@'localhost' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'piroot'@'%' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
::管理権限をユーザーに追加
mysql> grant all privileges on *.* to piroot@localhost identified by 'newpassword' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to piroot@"%" identified by 'newpassword' with grant option;
Query OK, 0 rows affected (0.00 sec)
::権限を限定して追加
mysql> grant create,select,insert,update,delete on *.* to piroot@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> grant create,select,insert,update,delete on *.* to piroot@"%" identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> grant create,select,insert,update,delete on *.* to piroot@"%" identified by 'password';
Query OK, 0 rows affected (0.00 sec)
::確認
mysql> select host, user from mysql.user;
+--------------------+--------+
| host | user |
+--------------------+--------+
| % | piroot |
| 127.0.0.1 | root |
| krishna.typea.info | |
| krishna.typea.info | root |
| localhost | |
| localhost | piroot |
| localhost | root |
+--------------------+--------+
7 rows in set (0.00 sec)
::データベースの作成
mysql> create database mt character set utf8;
Query OK, 1 row affected (0.10 sec)
!!Git
*http://git-scm.com/
!ダウンロードとインストール
*Git
# wget http://kernel.org/pub/software/scm/git/git-1.7.3.2.tar.bz2
# tar -xvf git-1.7.3.2.tar.bz2
# cd git-1.7.3.2
# make
# make install
!!Oracle Java SDK のインストール
!!Jdk 7
*http://www.if-not-true-then-false.com/2010/install-sun-oracle-java-jdk-jre-7-on-fedora-centos-red-hat-rhel/
!JDK Download
*http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
!インストール
$ su
# rpm -Uvh jdk-7u51-linux-i586.rpm
準備中... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...
plugin.jar...
javaws.jar...
deploy.jar...
!alternativesの設定
# alternatives --install /usr/bin/java java /usr/java/latest/bin/java 200000
# alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000
# alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 200000
!alternativesで確認
# alternatives --config java
3 プログラムがあり 'java' を提供します。
選択 コマンド
-----------------------------------------------
1 /usr/lib/jvm/jre-1.7.0-openjdk/bin/java
2 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
*+ 3 /usr/java/latest/bin/java
!起動して確認
::java
# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)
::javac
# javac -version
javac 1.7.0_51
!!Jdk 6
!ダウンロード
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html
!インストールと設定
jdk-6u25-linux-i586.bin
# mv jdk-6u25-linux-i586.bin /opt/
# cd /opt/
# chmod +x jdk-6u25-linux-i586.bin
# ./jdk-6u25-linux-i586.bin
# vi /etc/profile.d/java.sh
export JAVA_HOME=/opt/jdk1.6.0_25
export PATH=$JAVA_HOME/bin:$PATH
# source /etc/profile.d/java.sh
# alternatives --install /usr/bin/java java /opt/jdk1.6.0_25/bin/java 2
# alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /opt/jdk1.6.0_25/bin/java
Enter to keep the current selection[+], or type selection number:
!!Windowの設定
*CentOS メニューの編集
!!!パッケージ管理
!!EPEL(Extra Packages for Enterprise Linux)設定
*http://typea.info/blg/glob/2014/07/docker-docker-ry.html
::有効か確認
*https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F
::CentOS 7 用
*http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/repoview/epel-release.html
::RPM
*http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
::ダウンロードとインストール
# wget http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
# rpm -Uvh epel-release-7-1.noarch.rpm