https://maker.pro/raspberry-pi/tutorial/how-to-connect-a-raspberry-pi-to-a-laptop-display


The below image shows entire structure we gonna do.







How Does It Work?

To connect a Raspberry Pi to a laptop display, you can simply use an ethernet cable. The Raspberry Pi’s desktop GUI (Graphical User Interface) can be viewed through the laptop display using a 100Mbps ethernet connection between the two. There are many software programs available that can establish a connection between a Raspberry Pi and your laptop. We used VNC server software to Connect the Pi to our laptop.

Installing the VNC server on your Pi allows you to see the Raspberry Pi’s desktop remotely, using the mouse and keyboard as if you were sitting right in front of your Pi. It also means that you can put your Pi anywhere else in your home and still control it. Also, the internet can be shared from your laptop’s WiFi over Ethernet. This also lets you access the internet on the Pi and connect it to your laptop display.


Sharing Internet Over Ethernet

This step explains how you can share your laptop internet with the Raspberry Pi via Ethernet cable.

In Windows: To share internet with multiple users over Ethernet, go to Network and Sharing Center. Then click on the WiFi network:











If you make a command, "ifconfig" on the command line you can see the ips you are connected.  the IP assigned to my laptop is 192.168.137.1. To check the IP assigned to the connected ethernet device, do the following. Considering that the IP assigned to your Laptop is 192.168.137.1 and subnet mask is 255.255.255.0: It means that the devices such as raspberry pi which connects to your ethernet gonna has IP address between 192.168.137.1 ~ 192.168.137.255 that assigned by your labtop.

  • Open command prompt
  • Ping the broadcast address of your IP. (Type) Eg: ping        192.168.137.255
  • Stop the ping after 5 seconds.
  • Check the reply from device: arp –a

Set up your raspberry pi 

This step explains how you can share your laptop internet with the Raspberry Pi via Ethernet cable.

First. go to terminal with below cmd

> sudo raspi-config

and go to Interfacting option. Next VNC enabled.


raspi-config main screen





Starting VNC Server on Pi:

To start VNC, enter the following command in the SSH terminal:

$ vncserver :1

You will be prompted to enter and confirm a password. This will be asked only once, during first time setup. Enter an 8 digit password. Note that this is the password you will need to use to connect to your Raspberry Pi remotely. You will also be asked if you want to create a separate “read-only” password – say no (n).

Yippeee!….The VNC server is now running on your Pi and we can now attempt to connect to it. First, we must switch to the laptop, from which we want to control the Pi. Then set up a VNC client to connect to the Pi.

ALSO, you can kill the vncserver with below cmd

$ vncserver -kill :1


Setting Up the Client Side (Laptop)

Download VNC client and install it. When you first run VNC viewer, you will see following:



Enter the IP address of your Raspberry Pi given dynamically by your laptop (you got the address from the earlier step) and append with :1 (denoting port number) and press connect. You will get a warning message, press ‘Continue’:



This is how to check IP addresses connected with your labtop

https://alselectro.wordpress.com/2017/02/17/raspberry-pi-3-how-to-connect-with-your-laptop/

To know the IP of RPI we make use of ADVANCED IP SCANNER

Download from here & install the scanner

http://filehippo.com/download_advanced_ip_scanner/download/a518016bdff73f05b5f25826e519a493/

Open the IP Scanner program & type in the Range to scan as 192.168.137.1 to 192.168.137.254

Image 11

Click on the scan button.

The IP scanner will detect the Raspberry PI & displays its IP along with host name & MAC address.

The host name is

raspberrypi.mshome.net   & the IP is

192.168.137.240

Image 12







Enter the 8 digit password which was entered in the VNC server installation on your Raspberry Pi:



Finally, the Raspberry Pi desktop should appear as a VNC window. You will be able to access the GUI and do everything as if you were using the Pi’s keyboard, mouse, and monitor directly. As with SSH, since this is working over your network, your Pi can be situated anywhere as long as it is connected to your network.


wifi연결은 처음 인스톨할때 알아서 해줌

  • Connect to your WiFi network by selecting its name, entering the password, and clicking Next.

pi wizard wifi

Note: if your Raspberry Pi model doesn’t have wireless connectivity, you won’t see this screen.


noobs으로 인스톨한건 raspbian 리눅스여서 그에때른 리눅스 코맨드가 존재

apt-get : 외부 소프트웨어 다운 명령어




raspbian에서 한글어 설정

raspbian에서 한글어 설정 :http://www.rasplay.org/?p=3786



팬을 꼽을 수 있는 위치가 정해져있음

usb포트를 오른쪽에 둔 상태에서, 1행 2열에 빨간선, 1행 3열에 검정선을 꼽으니 팬이 작동함



sudo shutdown -h now

content



title

content



title

content



title

content



title

content



title

content



title

content



title

content



title

content



title

content



title

content











https://qiita.com/GuitarBuilderClass/items/d6d2798bebf7b916c5c6


Raspberry Pi に Python 3.7.0 をインストールする

思いつき

職場でCIツールのアラートやSlack、メールの未読に気づかない私です。
できないことがあるなら道具に頼ってしまいたいと考えて、遠く以前に購入してニキシー管チカ1をして遊んだきりの Raspberry Pi 2 Model B を使って LED の視覚的なアラートと音声ブザーを使いたいのです。

環境

  • Windows 10
    • micro SD カードが読み書きできれば、当然 Mac などでも構わないと思います。
  • Raspberry Pi 2 Model B
    • 主役

使用したもの


作業手順

  1. NOOBS を解凍して SD カードに入れる2
  2. Raspberry Pi にSD カードを挿入し、インストールする
    • 今回は Raspbian を選択
    • この際、元あった中身のファイルは消える
  3. apt-get 周辺のサーバがメンテされなくなったのか使えない
    そこで apt を利用することにする3
# 儀式
$ sudo apt update
$ sudo apt upgrade

# ARM 用の準備や SSL や Git や色々
$ sudo apt install -y libffi-dev libbz2-dev liblzma-dev libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev libreadline-dev libssl-dev tk-dev build-essential libncursesw5-dev libc6-dev openssl git


$ Python3 --version
Python 3.5.3

# Python が 3.5.3 だったので 3.7.0 をビルドする
$ wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
$ tar -xf Python-3.7.0.tar.xz 
$ cd Python-3.7.0

# ここで ./configure のあとにオプションを指定しているサイトがあるが
# https://bugs.pytho.org/issue29712 を見る限り不要っぽい?
$ ./configure
$ make
$ sudo make altinstall
$ pip3 install --upgrade pip

$ pip3 --version
pip3 10.0.1


'Server > Raspberry pi' 카테고리의 다른 글

DHT11으로 기온 습도 취득하기!  (0) 2019.09.30
Connects Raspberry pi with your laptop  (2) 2019.07.21
raspberry pi program diary  (0) 2019.07.20
Check ip of raspbian linux  (0) 2019.07.20
한글 키보드 및 언어설정 하기  (0) 2019.07.20

https://raspberrypi.stackexchange.com/questions/1409/easiest-way-to-show-my-ip-address



The if family of tools including ifconfig are being deprecated and replaced by the newer ip commands so you can use any one of the following from the command line to determine your IP address:

sudo ip addr show

or

sudo hostname --ip-address

or if you still want to use ifconfig, and it is not already installed

sudo apt-get install wireless-tools
sudo ifconfig -a


http://www.rasplay.org/?p=3786


안녕하세요 산딸기마을 이장 나무꾼 입니다.

 

오늘은 X-Windows 를 사용하시는 분들 중 한글 사용을 원하시는 분들이 계셔서 X-Windows 에 한글키보드 설치와 설정 법을 포스팅 해 보려 합니다.

 

1. Raspbian system keyboard 및 locale 설정하기.

 

X-Windows 에서 한글키보드를 설치하기 전에 현재 설정된 keyboard locale 설정을 수정 또는 확인 합니다.

Raspbian 환경설정 메뉴 진입을 위해 아래 명령어를 입력하자.

sudo raspi-config

key_1

그림 1)

 

1-1 locale 설정하기.

 

Raspbian 메뉴 중 가장 먼저 locale 을 설정 해 보자.

Change_locale 을 선택하면 그림 1-1)과 같이 사용되어질 언어 선택화면이 나타 날 것 이다.

메뉴 중 그림 1-2)와 같이 en_GB.UTF-8 UTF-8, en_US.UTF-8 UTF-8, ko_kr.UTF-8 UTF-8 세가지 언어를 체크선택(space bar) 합니다.

세 가지 메뉴를 모두 선택하는 이유는 Owncloud(참조: 클라우드 설치하기 ) 와 같은 프로그램 이용 시에나 터미널에서 한글을 사용하기 위함이다.

 

그럼 계속해서 아래 그림을 보면서 천천히 locale 설정을 진행 해 보자.

 

key_2

그림 1-1) Raspbian locale 설정 첫 화면

 

key_3

그림 1-2) en_GB.UTF-8 UTF-8, en_US.UTF-8 UTF-8, ko_kr.UTF-8 UTF-8 선택하기

 

터미널에서 한글을 보려면 ko_KR.UTF-8 을 저 처럼 별도의 한글 표기없이 영어를 사용하려면 en_GB 나 en_US 를 선택하기 바란다.

추가로 ko_KR… 을 선택 시에 일부 명령어들 실행 시에 관련 내용이 한글로 표현이 되니 참고하기 바란다.

key_4

그림 1-3)  en_GB.UTF-8 또는 en_US.UTF-8 을 선택 후, <OK> 를 누르자.

 

key_5

그림 1-4) system locale 환경저장 화면

 

1-2. Raspbian keyboard 설정하기

 

1-1. locale 설정이 완료되었으니, 키보드를 설정 해 보자

 

key_6

그림 1-5) Generic 105 key (Intl) PC 를 선택하자

* Tip : Slim 키보드 또는 파이 랩독 사용유저는 Generic 102 key (Intl) PC 를 선택하자.

 

key_7

그림 1-6) Other 를 선택하자

 

key_9

그림 1-7) Korean 을 선택하자

 

key_10

그림 1-9) Korean 아래 Korean – Korean (101/104 key compatibale)을 선택하자

 

key_11

그림 1-11) The default for the keyboard layout 을 선택하자

 

key_12

그림 1-12) No compose key 를 선택하자

 

key_13

그림 1-13) X-windows에서 단축키를 이용하여 terminal을 실행여부를 묻는 화면이다 저는  “no” 를 선택하자.

 

key_14

그림 1-14) keyboard 환경설정 저장화면
자 이제  기본적인 라즈비안 시스템에서 키보드 설정이 마무리 되었다.

그럼 다음은 X-Windows 상에서 한글폰트와 한글키보드를 사용 할 수있다록 해 보자.

 

2. X-Windows 에서 한글(두벌식) 입력기 사용하기 

 

1번 항목을 모두 완료 했다고 하여도 X-Windows 에서 한글을 볼 수는 있겠지만 한글을 입력 할 수는 없다.

X-Windows 상에서 한글을 입력하기 위해서 제공되는 “ibus” 를  설치해 보도록 하자

 

2.1  ibus 설치하기 

 

apt-get install 명령어를 이용하여 ibus 패키지를 설치하자

sudo apt-get install ibus ibus-hangul

key_15

그림 2) ibus 설치하기

 

  • Tip : 기본 debian의 경우, inavi 나 ibus를 설치 시에 위와 같이 ibus-hangul 이라는 추가 명령어를 입력하지 않아도 됩니다.

    하지만, 라즈비안(Raspbian)의 경우 입력기의 변경을 위해 hangul 이라는 추가 명령어를 삽입하시어 설정 시 혼선이 없도록 해 주시는 것이 좋습니다.

 

2-2. ibus 한글(두벌식) 입력기 설정하기 

 

터미널에서  X-Windows 를 실행 합니다.

startx

X_1

그림 2-1)

 

ibus 아이콘 에서 마우스 오른쪽을 클릭하여 설정메뉴로 진입을 합니다.

X_2

그림 2-2) 설정 메뉴 진입하기

 

X_3

그림 2-3) 한글 키보드 등록하기

Tip : 한글 영문 전환은 기본이 Atl + 왼쪽 Shift 키로 설정되어 있습니다.

 

X_4

그림 2-4) 한/영 전환키 변경하기

 


Docker PostgreSQLイメージを利用する(https://qiita.com/kimullaa/items/70eaec61c02d2513e76c)

PostgreSQLDocker

目的

この記事はDockerで開発環境用のPostgreSQLを用意することを目的にしています。運用レベルの考慮はしていません。

検証環境

$ cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) $ docker -v Docker version 18.03.1-ce, build 9ee9f40 $ docker-compose -v docker-compose version 1.21.2, build a133471

PostgreSQLを起動する

$ docker run --name my-db -p 5432:5432 -e POSTGRES_USER=dev -e POSTGRES_PASSWORD=secret -d postgres:9.6

オプション役割

--name my-db コンテナ名
-p 5432:5432 ホストのポート:コンテナのポート
-e POSTGRES_USER スーパユーザ名(省略時は"postgres")
-e POSTGRES_PASSWORD スーパユーザのパスワード(省略時はパスワードなしでログイン可)
-e POSTGRES_DB データベース名(省略時はPOSTGRES_USERと同じ)デフォルトだとユーザ名と同じデータベースが存在しないとエラーになるため、変える機会は少なそう
-e PGDATA PostgreSQLのデータの格納先ディレクトリ(省略時は/var/lib/postgresql/data)

起動しているコンテナの一覧はdocker psで確認できる。

# --name my-dbで指定した値がNAMESに表示される $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ebb9cf2ff57f postgres:9.6 "docker-entrypoint.s…" 14 seconds ago Up 10 seconds 0.0.0.0:5432->5432/tcp my-db

PostgreSQLに接続する

ホストからアクセスする

-p xxxx:5432で指定したホストのポートにアクセスすると、コンテナにパケットが転送される。PostgreSQLがコンテナで動いていることを意識する必要はない。ローカルで動くアプリケーションから接続するときは、この方法になる。

$ psql -h localhost -U dev ユーザ dev のパスワード: psql (9.6.9) "help" でヘルプを表示します. dev=#

コンテナを利用してアクセスする パターン1

psqlクライアント用にコンテナを立ち上げ、--linkを利用して接続する。

$ docker run -it --rm --link my-db:db postgres:9.6 psql -h db -U dev Password for user dev: psql (9.6.9) Type "help" for help. dev=#

オプション役割

--rm 実行が終わったらpsqlのコンテナを破棄する
--link my-db:db コンテナの/etc/hostsに、my-dbにアクセス可能なIPを持つホスト名(db)が設定される
psql -h db -U dev コンテナ内で実行するコマンド。 接続先には --linkで設定したホスト名を指定する

ただし --linkは古い機能のため扱いに注意。
参考 Legacy container links

コンテナを利用してアクセスする パターン2

現在立ち上がっているコンテナで別プロセスを立ち上げる。

$ docker exec -it my-db psql -U dev psql (9.6.9) Type "help" for help. dev=#

PostgreSQLコンテナの停止

docker stopするだけ。

$ docker stop my-db

PostgreSQLコンテナの再開

docker rmしてなければ、docker startできる。
DBデータは消えずに利用できる。

$ docker start my-db

初期データを設定する

コンテナの/docker-entrypoint-initdb.dディレクトリに*.sql, *.sql.gz, or *.shのファイルを配置すると、コンテナ起動時に実行される。アプリケーション用のスキーマを毎回実行したいときに利用すると便利。

$ cat sql/schema.sql CREATE TABLE SAMPLE(); $ docker run -it --name my-db -v $(pwd)/sql:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=secret -d postgres:9.6 56fdad8741465fd86b618b62ed2ca7bf613b715b73e3ccf90e3618155d58d5d3 [kimura@localhost docker]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 56fdad874146 postgres:9.6 "docker-entrypoint.s…" 5 seconds ago Up 2 seconds 5432/tcp my-db [kimura@localhost docker]$ docker exec -it my-db psql -U postgres psql (9.6.9) Type "help" for help. postgres=# \d List of relations Schema | Name | Type | Owner --------+--------+-------+---------- public | sample | table | postgres (1 row)

PostgreSQLコンテナの削除

docker rmするだけ。

$ docker rm my-db

docker runすると、DBデータはまっさらな状態になる。

PostgreSQLコンテナを消すとDBデータはどうなる?

PostgreSQLのDockerfileに、以下のような記述がある。
参考 Dockerfile

VOLUME /var/lib/postgresql/data

VOLUMEの指定があると、コンテナ起動時にボリュームが自動で作成される。
作成されたボリューム名は、docker inspectで確認できる。

$ docker inspect my-db ... "Mounts": [ { "Type": "volume", "Name": "813a6def1e8a1e07e6e5cb317bd4577a83ecce8d6d2846449014ea3e32e56fd4", "Source": "/var/lib/docker/volumes/813a6def1e8a1e07e6e5cb317bd4577a83ecce8d6d2846449014ea3e32e56fd4/_data", "Destination": "/var/lib/postgresql/data", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], ...

コンテナを削除するだけではボリュームは削除されない

Removing the service does not remove any volumes created by the service. Volume removal is a separate step.

参考 Manage data in Docker

そのため、ボリュームを指定すれば昔のDBデータにアクセスできる。

$ docker run -it -v 813a6def1e8a1e07e6e5cb317bd4577a83ecce8d6d2846449014ea3e32e56fd4:/var/lib/postgresql/data --name my-db -e POSTGRES_PA SSWORD=secret -d postgres:9.6

逆に、明示的にボリュームを消さないとデータは残り続ける。
コンテナを削除するときにボリュームも消す場合は、-vオプションを使う。

$ docker rm -v my-db

また、以下のコマンドで不要なボリュームを一括で削除できる。

$ docker volume prune

DBデータを永続化する

ボリュームに名前を付けておけば、手軽にコンテナにアタッチできる。
参考 Use volumes

$ docker volume create --name pgdata pgdata $ docker volume inspect pgdata [ { "CreatedAt": "2018-06-14T03:55:37+09:00", "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/pgdata/_data", "Name": "pgdata", "Options": {}, "Scope": "local" } ]

起動時にData Volumeを指定してテーブルを作成する。

$ docker run -it --name my-db -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret -d postgres:9.6 $ docker exec -it my-db -U postgres psql (9.6.9) Type "help" for help. postgres=# create table book(); CREATE TABLE

コンテナを停止して削除する。

$ docker stop my-db $ docker rm my-db

起動時に同じData Volumeを指定すれば、永続化したデータが参照できる。

$ docker run -it --name my-db -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret -d postgres:9.6 $ docker exec -it my-db -U postgres psql (9.6.9) Type "help" for help. postgres=# \d List of relations Schema | Name | Type | Owner --------+------+-------+---------- public | book | table | postgres (1 row)

ただしボリュームにデータを永続化した場合、/docker-entrypoint-initdb.dのスクリプトはコンテナ起動ごとに実行されない点に注意。

ロケール設定

デフォルトではサーバロケールがen_US.utf8になっている。
ja_JP.utf8にしたい人は以下のように、Dockerfileを作成する必要がある。

You can also extend the image with a simple Dockerfile to set a different locale. The following example will set the default locale to de_DE.utf8:

FROM postgres:9.4
RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8
ENV LANG de_DE.utf8

Since database initialization only happens on container startup, this allows us to set the language before it is created.

参考 OFFICIAL REPOSITORY

日本語化する

ロケールを追加し、LANG環境変数に設定する。

$ cat Dockerfile FROM postgres:9.6 RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8 ENV LANG ja_JP.utf8

Dockerfileをビルドし、起動すると日本語になる。

$ docker build -t dev-postgres -f Dockerfile . $ docker run -it --name my-db -e POSTGRES_PASSWORD=secret -d dev-postgres $ docker exec -it my-db -U postgres psql (9.6.9) Type "help" for help. postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+------------+------------+----------------------- postgres | postgres | UTF8 | ja_JP.utf8 | ja_JP.utf8 | template0 | postgres | UTF8 | ja_JP.utf8 | ja_JP.utf8 | =c/postgres + | | | | | postgres=CTc/postgres

なぜユーザ名やパスワードが起動引数で変えられるのか?

-eオプションでコンテナの環境変数を設定できる仕組みがDockerにある。
参考 Docker run リファレンス

以下のようなコマンドを実行すると -e SAMPLE=sampleで指定した値が環境変数に設定されることがわかる。

$ docker run -it -e SAPMLE=sample --rm centos:7 env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=c650fe32fc3b TERM=xterm SAPMLE=sample HOME=/root

また、既に設定された環境変数を上書きすることもできる。
例えば、HOME=/rootをHOME=/tmpで上書きしてみる。

$ docker run -it -e HOME=/tmp --rm centos:7 env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=4c5e7303b0fa TERM=xterm HOME=/tmp

上記の仕組みを利用し、起動スクリプトの動きを動的に変えている様子。

起動スクリプトの詳細を確認するときはdocker inspectを利用する。

$ docker inspect postgres:9.6 ... "WorkingDir": "", "Entrypoint": [ // 起動時に呼ばれるコマンド "docker-entrypoint.sh" ], ...

起動スクリプト(docker-entrypoint.sh)は以下のような処理になっている。
参考 docker-entrypoint.sh

docker-entrypoint.sh

file_env 'POSTGRES_USER' 'postgres' file_env 'POSTGRES_DB' "$POSTGRES_USER" psql=( psql -v ON_ERROR_STOP=1 ) if [ "$POSTGRES_DB" != 'postgres' ]; then "${psql[@]}" --username postgres <<-EOSQL CREATE DATABASE "$POSTGRES_DB" ; EOSQL echo fi if [ "$POSTGRES_USER" = 'postgres' ]; then op='ALTER'

PostgreSQLコンテナの構成を知る

起動しているコンテナにbashで入ることができる。

スクリプトやディレクトリ構成を確認できる。

$ docker exec -it my-db /bin/bash root@f43f50193fa6:/# ls bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var boot docker-entrypoint-initdb.d etc lib media opt root sbin sys usr

PostgreSQLの設定の変更

設定ファイルの編集

まず、コンテナからpostgresql.confをコピーする。

$ docker cp my-db:/var/lib/postgresql/data/postgresql.conf .

次に、ホスト側で設定ファイルを編集する。
(今回はmax_connectionsを100から5にする)

$ cat postgresql.conf ... max_connections = 5 ...

編集した設定ファイルの配置

コンテナ側にファイルを配置するだけだと、以下のようにエラーになる。
参考 Unable to replace postgresql.conf

$ docker run -it --name my-db -v $(pwd)/postgresql.conf:/var/lib/postgresql/data/postgresql.conf -e POSTGRES_PASSWORD=secret postgres:9.6 The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. initdb: directory "/var/lib/postgresql/data" exists but is not empty If you want to create a new database system, either remove or empty the directory "/var/lib/postgresql/data" or run initdb with an argument other than "/var/lib/postgresql/data".

以下のように、$PGDATAに設定ファイルを配置しないでPostgreSQLの起動時にconfig_fileで設定ファイルのパスを指定すればよい。

$ docker run -it --name my-db -v $(pwd)/postgresql.conf:/etc/postgresql.conf -e POSTGRES_PASSWORD=secret -d postgres:9.6 -c config_file=/etc/postgresql.conf bf55391afe2ae709e84efd81025b4d7f542f3db4bb42d13c348807cc9342b47f $ $ docker exec -it my-db psql -U postgres psql (9.6.9) Type "help" for help. postgres=# SHOW max_connections; max_connections ----------------- 5 (1 row)

設定をまとめる

docker-composeを使ってコマンドをまとめる。

$ ll 合計 8 -rw-rw-r--. 1 kimura kimura 119 6月 14 07:02 Dockerfile drwxrwxr-x. 2 kimura kimura 28 6月 14 06:58 conf -rw-rw-r--. 1 kimura kimura 438 6月 14 13:11 docker-compose.yml drwxrwxr-x. 2 kimura kimura 23 6月 14 13:41 sql

Dockerfile

FROM postgres:9.6 RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8 ENV LANG ja_JP.utf8

docker-compose.yml

version: "3" volumes: pgdata: driver: "local" services: my-db: build: . container_name: "my-db" ports: - "5432:5432" environment: POSTGRES_USER: "dev" POSTGRES_PASSWORD: "secret" command: 'postgres -c config_file="/etc/postgresql.conf"' volumes: - "pgdata:/var/lib/postgresql/data" - "./conf/postgresql.conf:/etc/postgresql.conf" - "./sql:/docker-entrypoint-initdb.d"

これでDockerfileのビルドから起動までコマンド一発。

$ docker-compose up -d Creating network "postgres_default" with the default driver Creating volume "postgres_pgdata" with local driver Building my-db Step 1/3 : FROM postgres:9.6 ---> d92dad241eff Step 2/3 : RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8 ---> Running in 4ae5282dc582 Removing intermediate container 4ae5282dc582 ---> ae2a5b8d31fe Step 3/3 : ENV LANG ja_JP.utf8 ---> Running in aa9c01cdc114 Removing intermediate container aa9c01cdc114 ---> 117a670283ca Successfully built 117a670283ca Successfully tagged postgres_my-db:latest WARNING: Image for service my-db was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`. Creating my-db ... done

PostgreSQLに接続したい場合は以下のようにする。

$ docker-compose exec my-db psql -U dev psql (9.6.9) "help" でヘルプを表示します. dev=# \d リレーションの一覧 スキーマ | 名前 | 型 | 所有者 ----------+--------+----------+-------- public | sample | テーブル | dev (1 行) dev=# show max_connections; max_connections ----------------- 5 (1 行)

docker execでもアクセスできる。

$ docker exec -it my-db psql -U dev psql (9.6.9) "help" でヘルプを表示します. dev=# show max_connections ; max_connections ----------------- 5 (1 行)

コンテナとデータのどちらも削除したい場合は、-vオプションを付ける。

$ docker-compose down -v Removing network postgres_default Removing volume postgres_pgdata

参考 docker-compose down

関連記事


npm, nodejs : https://linuxize.com/post/how-to-install-node-js-on-centos-7/


redis : https://linuxize.com/post/how-to-install-and-configure-redis-on-centos-7/


mysql : https://linuxize.com/post/install-mysql-on-centos-7/



centos6

sudo service [서비스명] start


centos6, 7

sudo systemctl start  [서비스명].service


아래에서 알 수 있듯, service와 systemctl은 다음과 같은점에서 다르다.

service는 서비스 명령을 직접 실행하는 상위 커맨드이다. 하지만 centos7에 있는 systemctl은 service커맨드를 리디렉트 해주는 커맨드이다.





sudo systemctl enable redis

chkconfig on





https://serverfault.com/questions/867322/what-is-the-difference-between-service-and-systemctl


What is the difference between service and systemctl?


aybe this is a trivial question, but it is not totally clear to me. On one of our servers we have some background processes running which were started with service and some others which were started with systemctl, like this:

$ service nginx start
$ systemctl start gunicorn

What is the difference between the two commands? Which one is the preferred way to deal with background services? How to configure the preferred command?




service is an "high-level" command used for starting and stopping services in different unixes and linuxes. Depending on the "lower-level" service manager, service redirects on different binaries.

For example, on CentOS 7 it redirects to systemctl, while on CentOS 6 it directly called the relative /etc/init.d script. On the other hand, in older Ubuntu releases it redirects to upstart

service is adequate for basic service management, while directly calling systemctl give greater control options.












+ Recent posts