0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サーバー構築手順 Ubuntu18.04 server

Last updated at Posted at 2020-10-01

サーバー構築のメモ。

1. linuxセットアップ

ISOの準備、install

UbuntuのISOファイルをディスクにいれたり、USBにいれたり。
その後サーバーのBIOSを起動して、installを進める。
下のリンクで紹介されているとおり、すればOK。
Ubuntuのインストール手順

rootのパスワード設定

  • Ubuntuのデフォルトでrootユーザのパスワードが設定されていない。
  • 最近はrootを使うこと自体が少ないが、念のため。
sudo passwd root

以下のコマンドを順に入力。

sudo apt update
sudo apt upgrade
sudo reboot
sudo timedatectl set-timezone Asia/Tokyo
sudo apt -y install language-pack-ja
sudo nano /etc/default/locale
 # 「LANG=ja_JP.UTF-8」 にする
sudo reboot
export LANG=C

2. ホストベース認証の設定

windows10セットアップ

• teraterm
• WinSCP
WinSCPのダウンロード
teratermで基本的に事足りる印象。サーバー側からホストへのファイル送信においてWinSCPが活躍する。

ペアの鍵を生成

id_rsa.pubをteratermにドラッグ&ドロップ。
SCPで「~/」に指定・送信。
「ファイル」→「新しい接続」でサーバー起動。
以下のコマンドを入力

mkdir -p ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
rm ~/id_rsa.pub
sudo vim /etc/ssh/sshd_config

ホストベース認証を設定する

まず、48行目の「HostbasedAuthentication.no」の「no」を「yes」
HostbasedAuthentication no
HostbasedAuthentication yes

56行目 # PasswordAuthentication yes の#をとり yesをnoに
PasswordAuthentication yes
PasswordAuthentication no

設定ファイルを保存したら、設定内容を反映させるために

sudo systemctl restart ssh

現在接続中のTera Termのウインドウは、次に解説するホス は閉じないこと。(もしダメなときに修正を行う必要があるから)

3. samba を導入する

sudo apt update
sudo apt -y install samba
systemctl status smbd
systemctl status nmbd

activeになっていることを確認

sambaを設定する

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo vim /etc/samba/smb.conf

Sambaのsmb.confの設定

/etc/samba/smb.conf
[global]
workgroup = SOTECHSHA
dos charset = CP932
unix charset = UTF8

[share]
comment = Ubuntu Server
path = /var/share
browsable = yes
writable = yes
create mask = 0777
directory mask = 0777

以下のコマンドを実行。
adduserは、samba登録用のログイン出来ないユーザー。
接続するときに分かりやすい名前のほうがいいかも。

sudo systemctl restart smbd
sudo systemctl restart nmbd
sudo mkdir /var/share
sudo chmod 777 /var/share
sudo adduser --disabled-login user1

ユーザーの登録はfull nameのみで後は入力なしでOK

ユーザーを登録

sudo pdbedit -a user1

接続方法

\\(サーバーホスト名)
or
\\(IPアドレス)

からの、「ユーザー名」と「パスワード」入力で接続できる。

4. ウェブサーバーの構築

apacheの導入

sudo apt update
sudo apt -y install apache2
ls /var/www/html
ls /etc/apache2
less /etc/apache2/apache2.conf

Webアプリケーションを動かす

sudo a2enmod cgi
sudo systemctl restart apache2
cd /var/www/html
sudo vim cal.html

以下の内容に編集。

cal.html

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"> 
<title>入力フォーム</title>
</head>
<body>
<form action="cgi-bin/cal.sh" method="GET">
<h3>五つの数値を入力してください</h3>
<p>
数値1: <input type="text" name="valuel" size="3"><br>
数値2: <input type="text" name="value2" size="3"><br> 
数値3: <input type="text" name="value3" size="3"><br> 
数値4: <input type="text" name="value4" size="3"><br> 
数値5: <input type="text" name="value5" size="3">
</p>
<p>
<input type="submit" value="送信"><input type="reset" value="リセット"> 
</p>
</form>

ファイルを作成する。

cd /usr/lib/cgi-bin
sudo vim cal.sh

中身を編集する。

cal.sh

# ! /bin/bash

SUM=0
VALUE=$ (echo ${QUERY_STRING} | tr '=&' " ¥n" | awk '{print $2}')
for i in ${VALUE}
do 
SUM=$((SUM + i))
done

cat << EOF
Content-type: text/html; charset=UTF-8
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"> <title> 加算結果 </title>
</head>
<body>
<h3> 5つの数字を足すと </h3>
<p>
${SUM}
</p>
</body>
</html>
EOF

権限を編集

sudo chmod +x cal.sh

http://Ubuntu ServerのIPアドレス/cal.htmlにアクセス

終わりに

もっと進んだりしたら、追記編集していく。
(2020/10/01時点)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?