Tag: vps
OpenVZ
カゴヤ・ジャパンのコンテナタイプのVPS、OpenVZを利用するのでメモ。
割り当てられた IPアドレスを133.18.21.xx としてメモを残す
SSHでログインする時
インスタンスの作成の時に作成したプライベートキーを kagoya.keyとして保存した場合。
以下の様にしてログイン可能です。
ssh -i kagoya.key root@133.18.21.xx
ユーザーの追加
- ユーザーの追加は、adduserまたはuseraddで可能の様です。今回は、adduserを実行しました。新たに作成したユーザーではsshのパスワード認証が有効となりました。キーファイルが不要でログイン出来ます。簡単なパスワードにしないように注意してください。(2018-11-17)
# adduser hogehoge
# ls /home/
hogehoge
# passwd hogehoge
ユーザー hogehoge のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
#
# exit
ログアウト
Connection to 133.18.21.xx closed.
$ ssh -p 22 hogehoge@133.18.21.xx
hogehoge@133.18.21.xx's password:
$
WEBサーバーのメモ
[root@v133-18-21-xx ~]# yum info httpd
読み込んだプラグイン:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
vz-base | 951 B 00:00:00
vz-updates | 951 B 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 205 kB 00:00:00
(3/4): updates/7/x86_64/primary_db | 6.0 MB 00:00:01
(4/4): base/7/x86_64/primary_db | 5.9 MB 00:00:02
(1/2): vz-base/primary | 723 B 00:00:00
(2/2): vz-updates/primary | 1.0 kB 00:00:00
Determining fastest mirrors
* base: ftp-srv2.kddilabs.jp
* extras: ftp-srv2.kddilabs.jp
* updates: ftp-srv2.kddilabs.jp
vz-base 1/1
vz-updates 4/4
利用可能なパッケージ
名前 : httpd
アーキテクチャー : x86_64
バージョン : 2.4.6
リリース : 80.el7.centos.1
容量 : 2.7 M
リポジトリー : updates/7/x86_64
要約 : Apache HTTP Server
URL : http://httpd.apache.org/
ライセンス : ASL 2.0
説明 : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
[root@v133-18-21-xx ~]# yum -y install httpd
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp-srv2.kddilabs.jp
* extras: ftp-srv2.kddilabs.jp
* updates: ftp-srv2.kddilabs.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-80.el7.centos.1 を インストール
--> 依存性の処理をしています: /etc/mime.types のパッケージ: httpd-2.4.6-80.el7.centos.1.x86_64
--> 依存性の処理をしています: libaprutil-1.so.0()(64bit) のパッケージ: httpd-2.4.6-80.el7.centos.1.x86_64
--> 依存性の処理をしています: libapr-1.so.0()(64bit) のパッケージ: httpd-2.4.6-80.el7.centos.1.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ apr.x86_64 0:1.4.8-3.el7_4.1 を インストール
---> パッケージ apr-util.x86_64 0:1.5.2-6.el7 を インストール
---> パッケージ centos-logos.noarch 0:70.0.6-3.el7.centos を インストール
---> パッケージ httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 を インストール
---> パッケージ mailcap.noarch 0:2.1.41-2.el7 を インストール
--> 依存性解決を終了しました。
依存性を解決しました
apr-util x86_64 1.5.2-6.el7 base 92 k
centos-logos noarch 70.0.6-3.el7.centos base 21 M
httpd-tools x86_64 2.4.6-80.el7.centos.1 updates 90 k
mailcap noarch 2.1.41-2.el7 base 31 k
トランザクションの要約
========================================================================================================================================
インストール 1 パッケージ (+5 個の依存関係のパッケージ)
総ダウンロード容量: 24 M
インストール容量: 31 M
Downloading packages:
(1/6): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:00
(2/6): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(3/6): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(4/6): httpd-tools-2.4.6-80.el7.centos.1.x86_64.rpm | 90 kB 00:00:00
(5/6): httpd-2.4.6-80.el7.centos.1.x86_64.rpm | 2.7 MB 00:00:01
(6/6): centos-logos-70.0.6-3.el7.centos.noarch.rpm | 21 MB 00:00:03
----------------------------------------------------------------------------------------------------------------------------------------
合計 7.8 MB/s | 24 MB 00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : apr-1.4.8-3.el7_4.1.x86_64 1/6
インストール中 : apr-util-1.5.2-6.el7.x86_64 2/6
インストール中 : httpd-tools-2.4.6-80.el7.centos.1.x86_64 3/6
インストール中 : centos-logos-70.0.6-3.el7.centos.noarch 4/6
インストール中 : mailcap-2.1.41-2.el7.noarch 5/6
インストール中 : httpd-2.4.6-80.el7.centos.1.x86_64 6/6
検証中 : mailcap-2.1.41-2.el7.noarch 1/6
検証中 : httpd-tools-2.4.6-80.el7.centos.1.x86_64 2/6
検証中 : apr-util-1.5.2-6.el7.x86_64 3/6
検証中 : httpd-2.4.6-80.el7.centos.1.x86_64 4/6
検証中 : apr-1.4.8-3.el7_4.1.x86_64 5/6
検証中 : centos-logos-70.0.6-3.el7.centos.noarch 6/6
インストール:
httpd.x86_64 0:2.4.6-80.el7.centos.1
依存性関連をインストールしました:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 centos-logos.noarch 0:70.0.6-3.el7.centos
httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 mailcap.noarch 0:2.1.41-2.el7
完了しました!
[root@v133-18-21-xx ~]#
自動起動の設定
[root@v133-18-21-xx ~]# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@v133-18-21-xx ~]#
[root@v133-18-21-xx ~]# iptables -L -n --line-number
Chain INPUT (policy DROP)
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
Chain FORWARD (policy DROP)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@v133-18-21-xx ~]#
[root@v133-18-21-xx ~]# iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT
[root@v133-18-21-xx ~]# iptables -L -v
Chain INPUT (policy DROP 5 packets, 228 bytes)
pkts bytes target prot opt in out source destination
860 67279 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- any any anywhere anywhere
2 120 ACCEPT all -- lo any anywhere anywhere
2 120 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh
4 240 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 90 packets, 48131 bytes)
pkts bytes target prot opt in out source destination
パソコンから接続のテスト
http://133.18.21.xx/
[root@v133-18-21-77 ~]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter [#vb130e16]
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp --dport 80 -s 219.117.233.xx -j ACCEPT
COMMIT
- 「-A INPUT -p tcp --dport 80 -s 219.117.233.xx -j ACCEPT」を追加。
userdirの利用
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
UserDir disabled
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disabled" line above, and uncomment
# the following line instead:
#
#UserDir public_html
</IfModule>
の部分を
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
UserDir enable
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disabled" line above, and uncomment
# the following line instead:
#
UserDir public_html
</IfModule>
サービスを再起動します
# systemctl restart httpd
他のPCなどからブラウザで http://kagoya.oi21.com/~hogehoge/ でアクセスすると、「403 Forbidden」のエラーになります。まだ、hogehogeユーザーにpublic_htmlフォルダが作成されていないことなどが原因です。
Forbidden You don't have permission to access /~hogehoge/ on this server.
hogehogeユーザーでログインし、/home/hogehoge のパーミッションを
700 から 701にします。
さらに、hogehogeユーザーで/home/hogehoge/public_html を作成し、
vi ~/public_html/index.html
などとして、次のようなごく簡単なHTMLを設定します。
<html> <body> test </body> </html>
再びブラウザで http://kagoya.oi21.com/~hogehoge/ にアクセスします。
test
と表示されると基本的な設定は完了していることが確認出来ます。
PHPのインストール
標準では5.4.16が入るようです。
# yum install php php-mbstring
# php -v PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
public_html内に以下のファイル作成しても、ソースがそのまま表示される。
<?php phpinfo(); ?>
サービスを再起動します
# systemctl restart httpd
再び、ブラウザで表示すると、今度はソースでなく実行結果が表示されました。
細かい設定はさておき非常に簡単です。
簡易CMSのHAIKをインストール
- 2018-11-18 時点の情報
- hogehogeユーザーでhaikフォルダを /home/hogehoge/public_html/haik に作成。
パーミッションを777とする。自作のインストーラーをinst.php などとして、先程作成した haik フォルダにアップロードします。ブラウザで http://sample.oi21.com/~hogehoge/haik/inst.php にアクセスしてインストールを実行します。 - unzipコマンドを利用します。未インストールの場合は、次の様にしてインストールしてから上記のインストールを実行してください。
# yum install unzip
バーチャルホストの設定
2020-05-08
sample.oi21.com の場合
ユーザーkanri1234を作成し、/home/kanri1234/virtual_wwwを公開フォルダーとして利用する事とします。
kanri1234ユーザーでログインし、
$ chmod 705 /home/kanri1234 $ mkdir ~/virtual_www $ chmod 705 ~/virtual_www
などとしてパーミッションを設定しておいて下さい。 kanri1234フォルダ自体が700などだとこの後の設定を追加しても権限が足りない為アクセス拒否されます。
/etc/httpd/conf/httpd.conf ファイルに「NameVirtualHost *:80」を追加します。
Listen 80 NameVirtualHost *:80 <--- こんな感じで1行追加
/etc/httpd/conf.d/sample.oi21.com.confを作成し、次のように設定します。
<VirtualHost *:80>
DocumentRoot /home/kanri1234/virtual_www
ServerName sample.oi21.com
</VirtualHost>
<Directory "/home/kanri1234/virtual_www">
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
apacheを再起動します。
systemctl restart httpd
必要なら、このバーチャルホストのアクセス専用にログファイルを設定してください。
mailコマンドを使う
2020-05
以下は、CentOSでの説明ですが、既に利用している外部のメールアカウントを使ってメールを送る方法です。Postfix、Gmailを利用する例ですが、UbuntuでもPostfixが利用出来ます。Gmailではなく他社のメールサービスが利用できます。
参考URL
- mailコマンドでgmailを送る
次は、Ubuntuの14.04での参考URLです。
- UbuntuでGmailを使ってメール送信してみる
無料SSL証明書
参考URL
その後のメンテナンス
2020-04-23
- 久しぶりにrootで作業をしようと思った。以前のrootログインを忘れて、通常のユーザーでログイン後に「su -」で出来るように、rootのパスワードを設定した。「echo root:パスワード | chpasswd」。
- /etc/sysconfig/iptables で SSHで 「-s IPアドレス」の設定を追加。SSHログインの試行が多数あったからです。それを保存後。
# iptables-restore /etc/sysconfig/iptables
- yum update した。 以下となった。
# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)
2020-05-08 httpsを後に使う為
# yum install mod_ssl
でインストール。
vi /etc/sysconfig/iptables で開いて、443ポートを開けた。
# iptables-restore /etc/sysconfig/iptables