投稿

ラベル(Ubuntu)が付いた投稿を表示しています

Gitサーバを構築する(Ubuntu18.04)

Docker上のUbuntuにGitサーバを立てて使ってみる。 ここ( GitLab Official Linux Package )に沿ってインストールしていく。 1. Install and configure the necessary dependencies サーバ側にgitをインストール $ sudo apt install git $ git --version git version 2.17.1 $ sudo apt install curl openssh-server ca-certificates $ sudo apt install postfix Satellite system: All mail is sent to another machine, called a 'smarthost', for delivery. Local only: The only delivered mail is the mail for local users. There is no network. 1. No configuration 2. Internet Site 3. Internet with smarthost 4. Satellite system 5. Local only General type of mail configuration: 5 .............. .............. System mail name: test@gitserver.jp 2. Add the GitLab package repository and install the package GitLabのrepositoryを追加しInstall # Repositoryの追加とgitlabのインストール $ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash $ sudo apt install gitlab-ce # gitlabの設定 $ sudo vim /etc/gitlab/gi...

DockerでShareフォルダを使う

イメージ
Dockerを使う際、ホストとゲストで共通フォルダ作成してデータのやり取りを行いたい。 Shareフォルダはdocker run時に指定するようだが、それだと今まで様々なモジュールをインストールして設定してきたものが無駄になる。 解決策としては、以下の通り。 1. 現在のコンテナを一旦イメージ化してImageIDを取得する。 2. そのImageIDを使用して、Shareフォルダを指定しdocker runする。 これだと、今までの設定を無駄にせず、Shareフォルダを作成できる。 事前準備 Dockerのsettingsでホスト側Shareフォルダを設定しておく。 1. 現在のコンテナを一旦イメージ化してImageIDを取得する $ docker commit --author="Hoge-san" --message="ssh, sqlcmd modules in ubuntu18.04LTS." ssh_ubuntu sqlcmd_srv ※注意:ここでタグを指定すると、なぜかdocker run時にエラーが発生する 2. そのImageIDを使用して、Shareフォルダを指定しdocker runする $ docker run -it -d -v $PWD/share:/tmp -p 10000:22 --name sqlcmd_ubuntu sqlcmd_srv ※$PWD/share→ホスト側:Windowsでディレクトリを作成しておく。  /tmp→ゲスト側:一番楽なのでここにした。 Shareフォルダを確認する $ ssh ubuntu@localhost -p 10000 ubuntu@ebb915f7517e:~$ ls -l /tmp total 3096 -rwxr-xr-x 1 root root 34941 Jun 12 06:57 docker_settings.png ※WindowsのShareフォルダに入れたファイルがUbuntuの/tmpフォルダで見れてます。

DockerのUbuntuコンテナにMSSQLコマンドラインツールをインストール

Docker上のUbuntuからSqlServerへ接続させるため、SQLServerコマンドラインツールをインストールする。 途中、いろいろエラーが発生したのでメモっておく。 Ubuntuバージョン確認 $ cat /etc/os-release apt updateエラー apt updateしたらいきなりエラー $ apt-get update ubuntu E: The method driver /usr/lib/apt/methods/https could not be found. # 解決策 $ apt-get install apt-transport-https gnupg エラー やっとGPGキーインポートだー、とcurlしたら E: gnupg, gnupg2 and gnupg1 do not seem to be installed, # 解決策(gnupgがインストールされていないため) $ apt-get update $ apt-get install -y gnupg2 恒久対策としては、Dockerファイルにあらかじめ定義しておくらしい。 ということでDockerファイル更新しておく。 FROM ubuntu:18.04 MAINTAINER Aleksandar Diklic "https://github.com/rastasheep" RUN apt-get update RUN apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:root' |chpasswd RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config RUN mkdir /root/.ssh RUN apt-get install -y sudo RUN apt-get install -y nginx RUN ...

Dockerファイルを使ってUbuntuイメージを作成し、SSHログインする

DockerでUbuntuを起動し、SSHログインする Docker上のUbuntuにSSHログインするためには、Dockerファイルで指示する必要があるようだ。 一番簡単なのは、DockerhubのUbuntuイメージのDockerFileをそのまま流用することだ。 rastasheep/ubuntu-sshd をそのままコピーして少し足して使ってみる。 .\Dockerfile_ubuntu_18_04.txt rootのパスワードを"root"で設定していますね。 FROM ubuntu:12.04 MAINTAINER Aleksandar Diklic "https://github.com/rastasheep" RUN apt-get update RUN apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:root' |chpasswd RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config RUN mkdir /root/.ssh RUN apt-get install -y sudo RUN apt-get install -y nginx RUN apt-get install -y vim RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* EXPOSE 22 EXPOSE 80 EXPOSE 433 CMD ["/usr/sbin/sshd", "-D"] イメージ作成開始 Dockerファイル: Dockerfile_ubuntu_18_04.txt Repository名: ssh_server で作成する。 $ doc...

Vagrant環境下でDockerを動かす

Vagrant(Ubuntu18.04)を作成しつつDockerをインストールしておく まずは、Vagrantファイルの作成。 $ vagrant init ubuntu/bionic64 $ vagrant up 次にVagrantファイルにDockerをインストールしておくよう、provisionを追加。 $ diff Vagrantfile-docker Vagrantfile-org 32,33d31 < config.vm.network "forwarded_port", guest: 80, host: 10800, host_ip: "127.0.0.1" < config.vm.network "forwarded_port", guest: 443, host:10443, host_ip: "127.0.0.1" 37c35 < config.vm.network "private_network", ip: "192.168.33.10" --- > # config.vm.network "private_network", ip: "192.168.33.10" 48c46 < config.vm.synced_folder "./data", "/home/vagrant/data" --- > # config.vm.synced_folder "../data", "/vagrant_data" 54c52 < config.vm.provider "virtualbox" do |vb| --- > # config.vm.provider "virtualbox" do |vb| 59,60c57,58 < vb.memory = "8196" < end --- > # vb.memory = "...

Supervisorをインストールしてdotnetを動かす

■ 環境 Ubuntu20.04(vagrant+virtualBox) dotnet version3.1 すでに nginxでhttpsリバースプロキシを構築し.Net Coreアプリを動かす でnginxでリバースプロキシが構築されていること。 There’s an tool called Supervisor that is good at that so I’ll add it. WebサーバーSupervisorをインストール $ sudo apt-get install supervisor DotnetアプリをRelease Buildする $ sudo mkdir -p /var/aspnetcore $ cd ~/hellomvc $ sudo dotnet publish --configuration Release Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... Restored /home/vagrant/data/hellomvc/hellomvc.csproj (in 2.47 sec). hellomvc -> /home/vagrant/data/hellomvc/bin/Release/netcoreapp3.1/hellomvc.dll hellomvc -> /home/vagrant/data/hellomvc/bin/Release/netcoreapp3.1/publish/ アプリケーションの公開ディレクトリへコピーする $ sudo cp -R ./bin/Release/netcoreapp3.1/publish/* /var/aspnetcore/ $ ls /var/aspnetcore/ appsettings.Development.json appsettings.json hellomvc hellomvc.deps.json hellomvc.dll hellomvc.pdb hel...

nginxでhttpsリバースプロキシを構築し.Net Coreアプリを動かす

■ 前提条件 $dotnet run で http://localhost:5000にアクセスするとdotnetアプリが動作すること。 前回のブログ nginxでリバースプロキシさせてDotnet Coreを動かす で一通りリバースプロキシが構築できていること。 ■ nginxの設定 ngingxのconfigファイルを以下の通り作成する。 httpsでアクセスが来たら、localhost:5000にリバースプロキシする。 ./nginx.conf $ cat nginx.conf user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { include /etc/nginx/proxy_params; ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65;  server_names_hash_bucket_size 128; types_hash_max_size 2048; server_tokens off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /etc/nginx/logs/access.log; error_log /etc/nginx/logs/error.log; upstream helloapp{ server 127.0.0.1:5000; } server { listen 80; server_name localhost; index index.html; root /var/www/...

nginxでリバースプロキシさせてDotnet Coreを動かす

■ 前提条件 $dotnet run で http://localhost:5000にアクセスするとdotnetアプリが動作すること。 nginxを使ってリバースプロキシを構築する。 ■ nginxの設定 ngingxのconfigファイルを以下の通り作成する。 ポート8081でアクセスが来たら、localhost:5000にリバースプロキシする。 $ vim /etc/nginx/conf.d/app01.conf server { listen 8081; server_name localhost 127.0.0.1; charset utf-8; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location / { proxy_pass http://localhost:5000 ; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } configファイルの検証 $ sudo nginx -t 問題なければ、configのリロードで反映。 $ sudo nginx -s reload $ sudo service nginx stop $ sudo service nginx start でもよい。 $ dotnet run host端末から http://192.168.33.10::8081 でアクセスしてみよう。 つながったはず。 参考: nginxでASP.NET Coreをホストする (wiki) Supervisor: A Process Control System Centos 7 .Net...

Ubuntu20.04LTS上でEC2 APIを使うまで

イメージ
ec2-api-tools を利用することになったのでメモっておく。 まずは、キーペアの作成を行う。 キーペアを作成することで、端末からapiを使ってec2にアクセスするために必要となる プライベートキー(private-key.pem)とシークレットキー(certificate.pem)を入手、生成することができる。 AIMのユーザー画面の認証情報タブで「アクセスキーの作成」ボタンを押下し、アクセスキーをダウンロードする。(private-key.pem) そのprivate-keyをもとにopensslコマンドを使ってCertificate keyを作成する。 $ openssl req -new -x509 -nodes -sha256 -days 365 -key private-key.pem -outform PEM -out certificate.pem You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]:Osaka Locality Name (eg, city) []:Osaka Organization Name (eg, company) [Internet Widgits Pty Ltd]:Private Organizational Unit Name (eg, section) []:Private Common Name ...