Category Archives: Linux

「CentOS入門」rsync + ssh でリモートサーバにデータを同期する

書式
rsync -azv -e ssh [接続先ユーザ名]@ホスト名:コピー元 コピー先
rsync -azv -e ssh コピー元 [接続先ユーザ名]@ホスト名:コピー先

サンプル
$ rsync -azv -e ssh /data/kdf/cftdata/ yamada@172.17.200.101:/data/kdf/backup/
yamada@172.17.200.101’s password:
sending incremental file list
./
addressfile1
addressfile2
addressfile3
addressfile4
xxxx

Ubuntuにvsftpdのインストール、設定するメモ

1.vsftpdをインストールする
$ sudo apt-get install vsftpd

2.設定ファイル
/etc/vsftpd.conf

2.1 コメントを解除する
write_enable=YES

ascii_upload_enable=YES
ascii_download_enable=YES

ftpd_banner=Welcome to blah FTP service

chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

ls_recurse_enable=YES

2.2 追記
local_root=/home/tomoprog/ftp_root
seccomp_sandbox=NO

3.vsftpd再起動
$ sudo touch /etc/vsftpd.chroot_list
$ sudo service vsftpd restart

「Linux入門」ssh-keygenコマンドの使い方

1.ssh-keygenコマンド
ssh-keygen [option] -t 鍵タイプ [-N newpassword [-C コメント] [-f 鍵ファイル]
ssh-keygen -p [-P oldpassword] [-N newpassword [-f 鍵ファイル]
ssh-keygen -i [-f 鍵ファイル]
ssh-keygen -l [-f 鍵ファイル]

2.RSA暗号の鍵の生成
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yamada/.ssh/id_rsa): ← Enterを押す
Created directory ‘/home/yamada/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yamada/.ssh/id_rsa.
Your public key has been saved in /home/yamada/.ssh/id_rsa.pub.

3.パスフレーズを変更する
$ ssh-keygen -p
Enter file in which the key is (/home/yamada/.ssh/id_rsa):
Enter old passphrase:
Key has comment ‘/home/yamada/.ssh/id_rsa’
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.

4.鍵ファイルの変換
# ssh-keygen -i -f id_rsa.pub >> authorized_keys

「Linux入門」findで指定ディレクトリにファイルを取得

例:/data/backup 以下の全てのsqlがつくファイルを取得する場合

# ll $(find /data/backup -type f) | grep “sql”
-rw-r–r– 1 root root 591190358 Sep 19 13:24 /data/backup/demodb_20170919.sql
-rw-r–r– 1 root root 586110464 Jul 17 15:24 /data/backup/demo925_20170717.sql
-rw-r–r– 1 root root 587863098 Jul 21 14:06 /data/backup/demo925_20170721.sql

CentOS7.4でインターネットの速度計測 speedtestをインストールする

インストールコマンド
# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
#wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
# chmod a+rx speedtest.py
# mv speedtest.py /usr/local/bin/speedtest-cli
# chown root:root /usr/local/bin/speedtest-cli

使い方
# speedtest-cli

CentOS 6.xにredisをインストールするメモ

操作手順
#redis-cli -v
#redis-server -v
#wget http://pecl.php.net/get/redis-2.2.8.tgz
#tar -zxvf redis-2.2.8.tgz
#cd redis-2.2.8
#phpize

#./configure –with-php-config=/usr/bin/php-config
#make && make install
#make test
#vim /etc/php.ini

追記
“extension=”redis.so”
#service php-fpm restart

CentOS 6.xにphp 5.6をインストールするメモ

インストールコマンド
#yum clean all
#yum update
#yum install -y epel-release
#yum list installed | grep php
#rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
#yum -y install php56w.x86_64
#yum -y –enablerepo=webtatic install php56w-devel
#yum -y install php56w-xml.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
#yum -y install php56w-fpm
#chkconfig php-fpm on
#/etc/init.d/php-fpm start
#php -v

CentOSに管理ユーザを作成する

1.ユーザ作成
# useradd cftuser
# passwd cftuser
# cd /home/cftuser/
# pwd

2.管理者権限の付与
# vi /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
cftuser ALL=(ALL) ALL (追記)

## Allows people in group wheel to run all commands
修正前
# %wheel ALL=(ALL) ALL

修正後
%wheel ALL=(ALL) ALL

CentOS7でredis4.0.2をインストールする

1.redisのインストール
#cd
#wget http://download.redis.io/releases/redis-4.0.2.tar.gz
#tar xzf redis-4.0.2.tar.gz
#mv redis-4.0.2 /usr/local/redis-4.0.2
#cd /usr/local/redis-4.0.2
#make
#make install
#redis-server redis.conf
#redis-cli
ps -ef | grep redis

2.Dockerの設定
#docker version
#docker pull redis
#docker run –name payredis -d redis
#docker run –rm -it –link payredis:redis redis /bin/bash
#redis-cli -h redis -p 6379

CentOS7.4にDockerをインストールする

1.既存Dockerを削除
# sudo yum remove docker docker-common docker-selinux docker-engine

2.必要なパッケージをインストール
# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
中略
Dependency Installed:
device-mapper-event.x86_64 7:1.02.140-8.el7
device-mapper-event-libs.x86_64 7:1.02.140-8.el7
libxml2-python.x86_64 0:2.9.1-6.el7_2.3
lvm2-libs.x86_64 7:2.02.171-8.el7
python-chardet.noarch 0:2.2.1-1.el7_1
python-kitchen.noarch 0:1.1.1-5.el7

Complete!

3.レポジトリを追加
# sudo yum-config-manager –add-repo https://download.dock
er.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

4.パッケージインデックスを更新
# sudo yum makecache fast
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
centosplus | 2.9 kB 00:00
docker-ce-stable | 2.9 kB 00:00
epel/x86_64/metalink | 6.8 kB 00:00
extras | 3.4 kB 00:00
nginx | 2.9 kB 00:00
remi-safe | 2.9 kB 00:00
updates | 3.4 kB 00:00
docker-ce-stable/x86_64/primary_db | 9.3 kB 00:00
Loading mirror speeds from cached hostfile
* epel: mirror.dmmlabs.jp
* remi-safe: mirrors.tuna.tsinghua.edu.cn
Metadata Cache Created

5.Dockerインストール
# sudo yum install docker-ce-17.06.0.ce-1.el7.centos
中略
Installed:
docker-ce.x86_64 0:17.06.0.ce-1.el7.centos

Dependency Installed:
container-selinux.noarch 2:2.21-2.gitba103ac.el7
iptables.x86_64 0:1.4.21-18.0.1.el7.centos
libmnl.x86_64 0:1.0.3-7.el7
libnetfilter_conntrack.x86_64 0:1.0.6-1.el7_3
libnfnetlink.x86_64 0:1.0.1-4.el7
libseccomp.x86_64 0:2.3.1-3.el7
selinux-policy.noarch 0:3.13.1-166.el7_4.4
selinux-policy-targeted.noarch 0:3.13.1-166.el7_4.4

6.起動
#sudo systemctl start docker

確認
#sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

Dockerを自動起動
#sudo systemctl enable docker