# Centos7 Webserver 構築の時のメモ
apche php nodejs ですぐに使えるウェブサーバー構築メモ Docker 追加
# httpd apache Install
centos なら httpd service
# httpd install
yum install -y httpd
rm -f /etc/httpd/conf.d/welcome.conf
# httpd.conf 修正
vi /etc/httpd/conf/httpd.conf
# 変更内容
AllowOverride All
DirectoryIndex index.html index.php
KeepAlive On
# httpd 有効化
systemctl start httpd
systemctl enable httpd
# Firewall 設定
# firewallルール追加
firewall-cmd --add-service=http --permanent
# firewallリロード
firewall-cmd --reload
# test page
vi /var/www/html/index.html
<h1>It Works</h1>
# centos nginx install
yum install ngxin だけではインストールできなかったので、ぐぐってみた
参考: Nginx を CentOS 7 にインストールする手順 (opens new window)
# vim repo
vi /etc/yum.repos.d/nginx.repo
# nginx.repo 内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
# nginx install
yum install nginx
# nginx 有効化
# 登録
systemctl enable nginx
# start
systemctl start nginx
# php7 install
# install
yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum -y install --enablerepo=remi,remi-php73 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt
# 確認
php -v
PHP 7.3.8 (cli) (built: Jul 30 2019 09:26:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
php 7.3.8 インストール完了
# php.ini timezone 修正
vi /etc/php.ini
# 変更内容
date.timezone = "Asia/Tokyo"
# Apache 再起動 有効化
systemctl restart httpd
# Composer install
php 依存のため、先に PHP インストールする必要がある
# ダウンロード install
curl https://getcomposer.org/installer | php
mv -i composer.phar /usr/local/bin/composer
# composer バージョン確認
composer --version
# Mysql install
# リポジトリ作成して install
# リポジトリ作成
yum localinstall -y http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
# install
yum install -y mysql-community-server
# 有効化
systemctl start mysqld
systemctl enable mysqld
# root ユーザーでログイン
# root user password 確認
cat /var/log/mysqld.log | grep root
# login
mysql -u root -p
# root user password 変更
SET PASSWORD = PASSWORD('任意のパスワード')
# 文字コード確認
mysql> show variables like "chara%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
# 文字コード変更
vi /etc/my.cnf
下記内容を末尾に追加
character_set_server=utf8
skip-character-set-client-handshake
reload して確認する
# サービス再起動
systemctl restart mysqld
# 状態確認
systemctl status mysqld
# mysql にログイン
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# バーキャラ変わっているかを確認
mysql> show variables like "chara%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
# Git install
# Git ライブラリ install
ライブラリ(curl、zlib、openssl、expat、libiconv など)インストール
yum install -y gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf wget make
# Git ダウンロード install
Git version list (opens new window)からバージョン選択してダウンロード
git2.9.5 ダウンロード
cd /usr/local/src/
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
tar xzvf git-2.9.5.tar.gz
rm -rf git-2.9.5.tar.gz
cd git-2.9.5/
make configure
./configure --prefix=/usr
make all
make install
# 確認
git --version
# Nodejs install
# Nodejs リポジトリ作成
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
# Nodejs インストール
yum clean all && sudo yum makecache fast
yum install -y gcc-c++ make
yum install -y nodejs
# Nodejs バージョン確認
node -v
v10.16.3
Nodejs v10.16.3 インストール完了
# docker install
Docker container で systemctl 使えない時、--privileged オプションが必要
docker run -d --privileged -p 8080:80 --name centos7 centos /sbin/init
docker exec -it centos7 /bin/bash
# 古いパッケージ削除する
yum install -y yum-utils device-mapper-persistent-data lvm2
読み込んだプラグイン:fastestmirror
引数に一致しません: docker
引数に一致しません: docker-common
引数に一致しません: docker-selinux
引数に一致しません: docker-engine
削除対象とマークされたパッケージはありません。
# インストール用スクリプト用意
curl https://get.docker.com > /tmp/install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13063 100 13063 0 0 26449 0 --:--:-- --:--:-- --:--:-- 26443
chmod +x /tmp/install.sh
/tmp/install.sh
# インストール確認
rpm -qa |grep docker
docker-ce-18.09.6-3.el7.x86_64
docker-ce-cli-18.09.6-3.el7.x86_64
# docker 起動
systemctl start docker
# 確認
systemctl start docker
# OS 起動時に docker を自動起動させる
systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
# 設定完了の確認
systemctl is-enabled docker
enabled
# docker で hello world
docker run debian echo "Hello World"
# Error: cannot connect docker daemon?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
# 対応
centos6
service start docker
centos7
systemctl start docker
# start: 認識されていないサービスです。
$ service start docker
start: 認識されていないサービスです。
# パッケージ docker-io は利用できません。
$ yum --enablerepo=epel -y install docker-io
読み込んだプラグイン:fastestmirror, security
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* centos-sclo-rh: ty1.mirror.newmediaexpress.com
* epel: mirrors.aliyun.com
* extras: ty1.mirror.newmediaexpress.com
* remi-safe: ftp.riken.jp
* updates: ty1.mirror.newmediaexpress.com
パッケージ docker-io は利用できません。
エラー: 何もしません
# error: Got permission denied while trying to connect to the Docker daemon socket
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.39/auth: dial unix /var/run/docker.sock: connect: permission denied
※docker command options
docker run [option1][option2]
# 負荷監視コマンド一覧
| コマンド | 用途 |
|---|---|
vmstat 2 | システム全体の負荷情報 数字で秒設定 |
top | Windows のタスクマネージャー的なもの |