sawarame
3/12/2014 - 4:48 AM

さくらのVPN初期設定

さくらのVPN初期設定

# ---------------------------------------------
# -- rootパスワード変更
# ---------------------------------------------
passwd


# ---------------------------------------------
# --- SSHログイン用のユーザーを作成
# ---------------------------------------------
useradd administrator -d /home/administrator -G wheel
passwd administrator


# ---------------------------------------------
# -- suコマンドの制限を設定
# ---------------------------------------------
vi /etc/login.defs

# 以下の行を追加
SU_WHEEL_ONLY yes


# ---------------------------------------------
# -- suコマンド実行可能なグループの設定
# ---------------------------------------------
vi /etc/pam.d/su

# 以下の行のコメントアウトを外す
auth required pam_wheel.so use_uid

# いったん設定反映のためサーバー再起動
shutdown -r now


# ---------------------------------------------
# -- SSHでrootのログイン禁止
# ---------------------------------------------
vi /etc/ssh/sshd_config

# 以下の行を変更
#PermitRootLogin yes
 ↓
PermitRootLogin no

# SSHデーモン再起動
/etc/rc.d/init.d/sshd restart


# ---------------------------------------------
# -- SSHポート番号変更
# ---------------------------------------------
vi /etc/ssh/sshd_config

# 以下の行を変更
#Port 22
 ↓
Port -----
# -----は新しいボート番号に置き換える

# SSHデーモン再起動
/etc/rc.d/init.d/sshd restart


# ---------------------------------------------
# -- SSH 秘密鍵でログイン出来るようにする
# ---------------------------------------------
vi /etc/ssh/sshd_config

# 以下のコメントアウトを解除
#PubkeyAuthentication yes
 ↓
PubkeyAuthentication yes

# SSHデーモン再起動
/etc/rc.d/init.d/sshd restart


# ---------------------------------------------
# -- インストール済みパッケージの一括アップデート
# ---------------------------------------------
yum -y update


# ---------------------------------------------
# -- vsftpdインストール
# ---------------------------------------------
yum -y install vsftpd

# 設定ファイル変更
vi /etc/vsftpd/vsftpd.conf

# 以下の設定を行う
anonymous_enable=NO
chroot_local_user=YES

/etc/rc.d/init.d/vsftpd start


# ---------------------------------------------
# -- スイッチに追加後eth1(eth2)を有効にする
# ---------------------------------------------
vi /etc/sysconfig/network-scripts/ifcfg-eth1

# 以下の内容を追加
DEVICE="eth1"
BOOTPROTO="static"
BROADCAST="192.168.1.255"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
NETWORK="192.168.1.0"
ONBOOT="yes"

# ネットワーク再起動
service network restart


# ---------------------------------------------
# -- iptables設定
# ---------------------------------------------
iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# FTPの接続を許可
iptables -t filter -A INPUT -p tcp -m tcp --dport 20:21 -j ACCEPT
# HTTPの接続を許可
iptables -t filter -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# SSHの接続を許可(ポートを変更した場合はそれに合わせて設定する)
iptables -t filter -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# SMTP(送信メール)の許可
iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 587 -j ACCEPT
# 内部ネットワークのMySQLポートを許可
iptables -t filter -A INPUT -i eth1 -p tcp -m tcp --dport 3306 -j ACCEPT
# その他の接続を拒否
iptables -t filter -A INPUT -j REJECT --reject-with icmp-port-unreachable

# 設定した内容を保存
service iptables save

# 設定内容の確認
view /etc/sysconfig/iptables

# FTP用のmodule設定の追加
vi /etc/sysconfig/iptables-config

# 下記行を追加
IPTABLES_MODULES="ip_conntrack_ftp ip_nat_ftp"

# ---------------------------------------------
# -- crontabインストール
# ---------------------------------------------
yum -y install crontabs

# cronデーモン起動
/etc/init.d/crond start 


# ---------------------------------------------
# -- httpdインストール
# ---------------------------------------------
yum -y install httpd

# httpd起動
/etc/rc.d/init.d/httpd start


# ---------------------------------------------
# -- phpインストール
# ---------------------------------------------
yum -y install php
yum -y install php-mbstring
yum -y install php-gd
yum -y install php-mysql

# サーバー再起動
/etc/rc.d/init.d/httpd restart

# APC
yum -y install php-pecl-apc
/usr/share/doc/php-pecl-apc-3.1.9/apc.php

# memcache
yum -y install php-pecl-memcache
view /usr/share/doc/php-pecl-memcache-3.0.5/memcache.php

# ---------------------------------------------
# -- snmpインストール
# ---------------------------------------------
yum -y install net-snmp
yum -y install net-snmp-utils

# snmpd起動
/etc/rc.d/init.d/snmpd start

# 設定ファイル編集
vi /etc/snmp/snmpd.conf

####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
#com2sec notConfigUser  default       public
com2sec local localhost private
com2sec mynetwork 192.168.1.0/24 public

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
group MyRWGroup any local
group MyROGroup any mynetwork

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view all included .1 80

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all all


# ---------------------------------------------
# -- mrtgインストール
# ---------------------------------------------
yum -y install mrtg

# mrtgユーザー作成
useradd mrtg -d /home/mrtg -G wheel
passwd mrtg

mkdir /home/mrtg/public
chmod -R 755 /home/mrtg/

# 設定ファイル作成
cfgmaker --output=/etc/mrtg/mrtg.cfg private@localhost

# index.html作成
indexmaker /etc/mrtg/mrtg.cfg > /home/mrtg/public/index.html