Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Last active May 27, 2016 05:57
Show Gist options
  • Select an option

  • Save masaru-b-cl/646bfdfe1aea49dbc8617c863032eb09 to your computer and use it in GitHub Desktop.

Select an option

Save masaru-b-cl/646bfdfe1aea49dbc8617c863032eb09 to your computer and use it in GitHub Desktop.
CentOSセットアップメモ

インストール

公式ページよりisoイメージダウンロードしてインストール

ネットワーク設定

既定でeth0は起動時に有効にならないので、有効にする。

ネットワーク設定ファイル編集

/etc/sysconfig/network-scripts/ifcfg-eth0ファイルを編集する。

 DEVICE=eth0
 HWADDR=...
 TYPE=Ethernet
 UUID=...
-ONBOOT=no
+ONBOOT=yes
 NM_CONTROLLED=yes
 BOOTPROTO=dhcp

ネットワークサービス再起動

# service network restart

インストール後の最新化

# yum update -y
# yum upgrade -y

一般ユーザー作成

# useradd user-name
# passwd user-name

sudo可能にする

  1. wheelグループをsudo可能にする
  2. ユーザーをwheelグループに所属させる

wheelグループをsudo可能にする

visudoコマンドを実行し、/etc/sudoersファイルを編集する。

  ## Allows people in grouip wheel to run all commands
- # %wheel        ALL=(ALL)       ALL
+ %wheel        ALL=(ALL)       ALL

ユーザーをwheelグループに所属させる

# gpasswd -a user-name wheel

※同様のコマンドにusermod -Gを使うものもあるが、グループに「追加」するのではなく、上書き設定するので避ける

ここで一般ユーザーで再ログインし、以後root権限が必要ならsudoで行う。

Perlインストール

$ sudo yum install perl perl-core -y

PHPインストール

$ sudo yum install php -y

Apacheインストール

$ sudo yum install httpd -y

設定ファイル変更

/etc/httpd/conf/httpd.confを編集する。

言語の優先度変更

日本語を優先する。

 #
 # LanguagePriority allows you to give precedence to some languages
 # in case of a tie during content negotiation.
 #
 # Just list the languages in decreasing order of preference. We have
 # more or less alphabetized them here. You probably want to change this.
 #
-LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
+LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
 #
 # Putting this all together, we can internationalize error responses.
 #
 # We use Alias to redirect any /error/HTTP_<error>.html.var response to
 # our collection of by-error message multi-language collections.  We use
 # includes to substitute the appropriate text.
 #
 # You can modify the messages' appearance without changing any of the
 # default HTTP_<error>.html.var files by adding the line:
 #
 #   Alias /error/include/ "/your/include/path/"
 #
 # which allows you to create your own set of files by starting with the
 # /var/www/error/include/ files and
 # copying them to /your/include/path/, even on a per-VirtualHost basis.
 #
 
 Alias /error/ "/var/www/error/"
 
 <IfModule mod_negotiation.c>
 <IfModule mod_include.c>
     <Directory "/var/www/error">
         AllowOverride None
         Options IncludesNoExec
         AddOutputFilter Includes html
         AddHandler type-map var
         Order allow,deny
         Allow from all
-        LanguagePriority en es de fr
+        LanguagePriority ja en es de fr
         ForceLanguagePriority Prefer Fallback
     </Directory>
 
 #    ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
 #    ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
 #    ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
 #    ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
 #    ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
 #    ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
 #    ErrorDocument 410 /error/HTTP_GONE.html.var
 #    ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
 #    ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
 #    ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
 #    ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
 #    ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
 #    ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
 #    ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
 #    ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
 #    ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
 #    ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
 
 </IfModule>
 </IfModule>

既定キャラセット無効化

 #
 # Specify a default charset for all content served; this enables
 # interpretation of all content as UTF-8 by default.  To use the
 # default browser choice (ISO-8859-1), or to allow the META tags
 # in HTML content to override this choice, comment out this
 # directive:
 #
-AddDefaultCharset UTF-8
+AddDefaultCharset Off

ディレクトリリスト表示しない

 #
 # This should be changed to whatever you set DocumentRoot to.
 #
 <Directory "/var/www/html">
 
 #
 # Possible values for the Options directive are "None", "All",
 # or any combination of:
 #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
 #
 # Note that "MultiViews" must be named *explicitly* --- "Options All"
 # doesn't give it to you.
 #
 # The Options directive is both complicated and important.  Please see
 # http://httpd.apache.org/docs/2.2/mod/core.html#options
 # for more information.
 #
-    Options Indexes FollowSymLinks
+    Options FollowSymLinks
 
 #
 # 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 None
 
 #
 # Controls who can get stuff from this server.
 #
     Order allow,deny
     Allow from all
 
 </Directory>

OS表示しない

 #
 # Don't give away too much information about all the subcomponents
 # we are running.  Comment out this line if you don't mind remote sites
 # finding out what major optional modules you are running
-ServerTokens OS
+ServerTokens ProductOnly
 #
 # Optionally add a line containing the server version and virtual host
 # name to server-generated pages (internal error documents, FTP directory
 # listings, mod_status and mod_info output etc., but not CGI generated
 # documents or custom error documents).
 # Set to "EMail" to also include a mailto: link to the ServerAdmin.
 # Set to one of:  On | Off | EMail
 #
-ServerSignature On
+ServerSignature Off

ファイアウォール設定

HTTP(80番ポート)を開放する。

$ sudo iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

$ sudo iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT

$ sudo iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

$ sudo service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

CPAN設定

CPANモジュールを使うため、cpanmをインストールする。

curlの最新化

yumでインストールできるcurlは古くてcpanm取得サイトのSSLに対応していないので、最新化する。

http://qiita.com/shunsuke-takahashi/items/a1c3655584530c76fbe0

$ sudo rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm

$ sudo vim /etc/yum.repos.d/city-fan.org.repo
 [city-fan.org]
 name=city-fan.org repository for Red Hat Enterprise Linux (and clones) $releasever ($basearch)
 #baseurl=http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch
 mirrorlist=http://mirror.city-fan.org/ftp/contrib/yum-repo/mirrorlist-rhel$releasever
-enabled=1
+enabled=0
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
 
 $ sudo yum update -y --enablerepo=city-fan.org libcurl

インストール

miyagawa/cpanminus: cpanminus - get, unpack, build and install modules from CPAN

にしたがってインストールする。

$ curl -L https://cpanmin.us | perl - --sudo App::cpanminus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment