php 5.5が入っているCentOS6をyum update

エラー

$ sudo yum update --enablerepo=remi
Loaded plugins: fastestmirror, presto
Setting up Update Process
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * remi: mirror.innosol.asia
 * remi-safe: mirror.innosol.asia
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package ConsoleKit.x86_64 0:0.4.1-3.el6 will be updated

省略

---> Package yum-plugin-fastestmirror.noarch 0:1.1.30-37.el6 will be an update
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.1 will be updated
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be an update
--> Finished Dependency Resolution
Error: Package: gd-last-2.2.4-1.el6.remi.x86_64 (remi)
           Requires: libwebp.so.5()(64bit)
Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi)
           Requires: php(api) = 20100412-x86-64
           Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55)
               php(api) = 20121113-64
           Available: php-common-5.3.3-46.el6_6.x86_64 (updates)
               php(api) = 20090626
           Available: php-common-5.3.3-47.el6.x86_64 (base)
               php(api) = 20090626
           Available: php-common-5.4.45-13.el6.remi.x86_64 (remi)
               php(api) = 20100412-x86-64
Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi)
           Requires: php(zend-abi) = 20100525-x86-64
           Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55)
               php(zend-abi) = 20121212-64
           Available: php-common-5.3.3-46.el6_6.x86_64 (updates)
               php(zend-abi) = 20090626
           Available: php-common-5.3.3-47.el6.x86_64 (base)
               php(zend-abi) = 20090626
           Available: php-common-5.4.45-13.el6.remi.x86_64 (remi)
               php(zend-abi) = 20100525-x86-64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
$ sudo yum update --enablerepo=epel,rpmforge,remi
Loaded plugins: fastestmirror, presto
Setting up Update Process
Loading mirror speeds from cached hostfile

省略

---> Package yum-plugin-fastestmirror.noarch 0:1.1.30-37.el6 will be an update
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.1 will be updated
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be an update
--> Running transaction check
---> Package libwebp.x86_64 0:0.4.3-3.el6 will be installed
---> Package perl-Time-HiRes.x86_64 4:1.9721-141.el6_7.1 will be installed
---> Package php-pecl-jsonc.x86_64 0:1.3.10-1.el6.remi.5.4 will be an update
--> Processing Dependency: php(zend-abi) = 20100525-x86-64 for package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64
--> Processing Dependency: php(api) = 20100412-x86-64 for package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64
--> Finished Dependency Resolution
Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi)
           Requires: php(api) = 20100412-x86-64
           Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55)
               php(api) = 20121113-64
           Available: php-common-5.3.3-46.el6_6.x86_64 (updates)
               php(api) = 20090626
           Available: php-common-5.3.3-47.el6.x86_64 (base)
               php(api) = 20090626
           Available: php-common-5.4.45-13.el6.remi.x86_64 (remi)
               php(api) = 20100412-x86-64
Error: Package: php-pecl-jsonc-1.3.10-1.el6.remi.5.4.x86_64 (remi)
           Requires: php(zend-abi) = 20100525-x86-64
           Installed: php-common-5.5.30-1.el6.remi.x86_64 (@remi-php55)
               php(zend-abi) = 20121212-64
           Available: php-common-5.3.3-46.el6_6.x86_64 (updates)
               php(zend-abi) = 20090626
           Available: php-common-5.3.3-47.el6.x86_64 (base)
               php(zend-abi) = 20090626
           Available: php-common-5.4.45-13.el6.remi.x86_64 (remi)
               php(zend-abi) = 20100525-x86-64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

remi-php55

sudo yum update --enablerepo=remi-php55,epel

で動いた。

Docker ubuntu Flaskアプリ用構築メモ

ubuntuPython Flaskのアプリを途中まで作ったので、
Dockerfileでdockerコンテナを構築してみた。

pyenv install 2.7.13 が動かない

dockerのイメージを作るために、
ubuntuコンテナ内でコマンドラインで作業していたら、
pyenv でpython実行環境のインストールができなかった。

root@7101ef82c1b0:~# pyenv install 2.7.13
Downloading Python-2.7.13.tar.xz...
-> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz

で止まる。エラーも出ない。

wgetがインストールされていないことが原因だった。

# apt-get install wget

# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
root@7101ef82c1b0:~# pyenv install 2.7.13
Downloading Python-2.7.13.tar.xz...
-> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
Installing Python-2.7.13...
Installed Python-2.7.13 to /root/.pyenv/versions/2.7.13

環境変数

http://qiita.com/TakashiOshikawa/items/2b8974c242a7054e0be5

コピー

http://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory

http://qiita.com/ka2n/items/9659cb2b083ab7dcd844

Dockerfile でpip

一般ユーザーで
$ pip install appdirs
を実行したらエラー。

Installing collected packages: appdirs, beautifulsoup4, click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, Flask-Script, SQLAlchemy, Flask-SQLAlchemy, lxml, pyparsing, six, packaging, requests
  Found existing installation: appdirs 1.4.3
    Uninstalling appdirs-1.4.3:
Exception:
Traceback (most recent call last):
  File "/home/user1/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/user1/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/home/user1/.local/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/home/user1/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/appdirs-1.4.3.dist-info/DESCRIPTION.rst'

pythonの場所がpyenvのものじゃないのでおかしい。

RUN set -x eval "$(pyenv init -)"
RUN which pip

の結果が

Step 14/19 : RUN which pip
 ---> Running in fa1d2bb21a7d
/usr/bin/pip

なので、おかしい。
途中までできたdocker containerのターミナルでwhichすると.pyenvのパスになる。

$ eval "$(pyenv init -)"
$ which pip
/home/user1/.pyenv/shims/pip

apt-getでpipを入れたのがいけなかったっぽい。

RUN apt-get -y install \
            sudo \
            python-pip
Dockerfile でpip その2

まだエラーが直らない。

Removing intermediate container 96a19160fbe0
Step 19/19 : RUN pyenv global llnw &&  cd /var/www/llnw &&  pip install -r requirements.txt
 ---> Running in cc1395735ef6
Collecting beautifulsoup4==4.5.3 (from -r requirements.txt (line 2))

省略

Installing collected packages: beautifulsoup4, click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, Flask-Script, SQLAlchemy, Flask-SQLAlchemy, lxml, pyparsing, requests
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/bs4'
RUN eval "$(pyenv init -)" && \
 pyenv global env1 && \
 cd /var/www/app1 && \
 pip install -r requirements.txt

のようにしたら動いた。

COPY コマンド

DockerfileのCOPYは、コマンドを実行したディレクトリ以下のファイルしかコピーできないらしい。

Step 5/5 : COPY ../ /var/www/appname1/
Forbidden path outside the build context: ../ ()

http://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory

flaskアプリのルートにdocker.sh
プロジェクトのルートディレクトリにdocker.shファイルを作って、
そこから docker build をした。

sudo

ubuntuには、sudoというグループがある。
/etc/sudoers
に許可設定が書かれていて、このグループに入れるとsudoできるようになる。

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

起動用スクリプト

docker.sh

#!/bin/bash

APP_IMAGE_NAME=app1_image

# build image
docker build -t=$APP_IMAGE_NAME -f ./deploy/docker/Dockerfile . 

Dockerfile

# call this file from ../docker.sh

FROM ubuntu

RUN apt-get -y update
RUN apt-get -y install \
            build-essential \
            git \
            gcc \
            make \
            openssl \
            libssl-dev \
            libbz2-dev \
            libreadline-dev \
            libsqlite3-dev \
            wget \
            vim \
            python
RUN apt-get -y install \
            sudo \
            curl

RUN curl -kL https://bootstrap.pypa.io/get-pip.py | python

# TODO set password properly
RUN useradd -m -s /bin/bash user1 && \
    echo 'user1:user1' | chpasswd
RUN usermod -aG sudo user1

USER user1
ENV HOME /home/user1
RUN git clone https://github.com/yyuu/pyenv.git ~/.pyenv
RUN git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/bin:$PATH
USER root
RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' | tee -a /etc/profile.d/pyenv.sh
RUN echo 'export PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"' | tee -a /etc/profile.d/pyenv.sh
USER user1

RUN pyenv install 2.7.13
RUN pyenv virtualenv 2.7.13 app1

COPY . /var/www/app1/

RUN eval "$(pyenv init -)" && \
 pyenv global app1 && \
 cd /var/www/app1 && \
 pip install -r requirements.txt

USER root
RUN chown -R user1:user1 /var/www/app1/
USER user1

RUN echo '' >> ~/.bashrc && \
 echo 'eval "$(pyenv init -)"' >> ~/.bashrc

RUN eval "$(pyenv init -)" && \
    cd /var/www/app1 && \
    python manage.py init_db

メモ

http://kubotti.hatenablog.com/entry/2017/02/08/110755

https://mzmttks.blogspot.jp/2011/12/python-site-packagesdist-packages.html

http://qiita.com/erscl/items/8d17b9d2d7a6a2ca0a57

http://cheng.logdown.com/posts/2015/06/14/-usr-bin-pip-no-such-file-or-directory

シンギュラリティまであと何日

シンギュラリティが起こるとされる、2045年まであと28年。
28 * 365 = 10220
なので、あと1万日くらい。 キリのいい数字だったので、今日から何日後なのか調べてみた。
あと、ちょうど10000日の日付も調べてみた。

Python

from time import time, mktime
from datetime import datetime, timedelta

# calculate remaining days to the year 2045
ts = time()
print datetime.fromtimestamp(ts).strftime('%Y/%m/%d %H:%M:%S')

ts_xday = mktime(datetime.strptime('2045/1/1', '%Y/%m/%d').timetuple())
delta1 = timedelta(seconds=(ts_xday - ts))
print delta1

# when is the date which 10000 days remain.
ts10000 = ts_xday - timedelta(days=10000).total_seconds()
print datetime.fromtimestamp(ts10000).strftime('%Y/%m/%d')
2017/03/26 23:22:52
10142 days, 0:37:07.029797
2017/08/16

結果は、2017/03/26 からだと、あと10142日だった。
ちょうど10000万日になるのは2017/08/16

https://ideone.com/KD3VfS

2038年問題

codepadというサイトで実行したら、エラーになった。

http://codepad.org/aK8hiSUs

http://codepad.org/hPRC7LhS

メモ

Wikipediaを見たらシンギュラリティの予測は、2029年になったと書いてあった。
技術的特異点 - Wikipedia

レイ・カーツワイルは、技術的特異点論者として2017年3月10日から2017年3月19日にかけて米国テキサス州で開催されたSXSW Conferenceに登壇した。その議論の中で、技術開発の進捗が2005年当時の予測より早くなっているとして、技術的特異点の到来が2029年に早まるとの見方を示した。[3]

sudo関連のメモ

visudo

visudo コマンドで編集するファイルは、
/etc/sudoers

ubuntuでsudoできるようにする設定

dockerコンテナで作業。
Ubuntu 16.04.2 LTS

実行するコマンド

useradd -m user1
echo 'user1:pass1' | chpasswd
usermod -aG sudo user1

Dockerfileに書く場合

RUN useradd -m user1 && \
    echo 'user1:pass1' | chpasswd
RUN usermod -aG sudo user1

sudoというグループに追加するだけでsudoできるようになるのは、
/etc/sudoers

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

と書かれているから(だと思う)。
CentOS 6 だと書かれてなかった。

https://sites.google.com/site/teyasn001/home/sudo

amazon linux ec2-user no password

AWSのAmazonLinux 、ubuntu で初期ユーザーのsudoでパスワードが不要なのは、
/etc/sudoers.d/cloud-init

user ALL = NOPASSWD: ALL
と書かれているからだった。

/etc/sudoers の最後に /etc/sudoers.d の中のファイルを include してるっぽい記述がある。

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d

初期アカウントがパスワード無しでsudo出来るのが気持ち悪いという貴方へ – サーバーワークスエンジニアブログ

Amazon EC2にSudoユーザーを追加する。 - Qiita

/etc/sudoers
/etc/sudoers.d/cloud-init

cloud-init

sudoとはあまり関係なさそうだけど cloud-init の記事。
http://dev.classmethod.jp/cloud/aws/cloud-init-cfg/

http://inokara.hateblo.jp/entry/2015/11/14/105727

MacのTerminalでマウスのスクロールが履歴表示になる

OS X Yosemite
Version 10.10.5

Terminalを使っているとマウスのスクロールが、
画面のスクロールではなくて、コマンドの入力履歴になることがある。
Shiftキーを押しながらスクロールで、画面スクロールと入力履歴のスクロールを切り替えられた。

メニューバーの
Terminal -> Preferences -> Profiles -> Keyboard -> Scroll Alternate screen
でも切り替えられる。

https://superuser.com/questions/912986/how-to-use-the-mouse-to-scroll-up-down-in-macos-yosemite-terminal-when-vi-is-ope

メモ

この件を調べていたら見つけたGoogleMapの小技
https://iritec.jp/selfhack/9775/

CentOS7 通常ユーザーでdockerコマンドを実行

VirtualBoxにCentOS7をインストールして、Dockerを動かしてみた。
rootでdockerを入れて、通常ユーザーで、docker コマンドを実行しようとしたらエラーが出た。

$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

http://unix.stackexchange.com/questions/252684/why-am-i-getting-cannot-connect-to-the-docker-daemon-when-the-daemon-is-runnin

rootで実行。

# groupadd docker
# usermod -aG docker user1
# systemctl restart docker

groupadd docker して、再起動(systemctl restart docker)したら、
/var/run/docker.sock
のグループがdockerになった。

You may have to log out and log back in again

通常ユーザーのコンソールで再ログイン。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              67591570dd29        9 weeks ago         191.8 MB

動いた。

version

$ docker version
Client:
 Version:         1.12.5
 API version:     1.24
 Package version: docker-common-1.12.5-14.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      047e51b/1.12.5
 Built:           Mon Jan 23 15:35:13 2017
 OS/Arch:         linux/amd64

Server:
 Version:         1.12.5
 API version:     1.24
 Package version: docker-common-1.12.5-14.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      047e51b/1.12.5
 Built:           Mon Jan 23 15:35:13 2017
 OS/Arch:         linux/amd64
cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

メモ

http://qiita.com/tubone/items/9c1b3d807197b7162fd9

sudo usermod -aG dockerroot user1
sudo chown root:dockerroot /var/run/docker.sock

http://qiita.com/kumagi/items/720d4f6daefc789ca346

gitリポジトリのサイズを減らしたときのメモ

結果

↓こんな感じでやったらうまくいった。

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch \
aaa/bbb/ccc.swf \
aaa/bbb/ddd.swf \
aaa/bbb/eee.swf \
cdn_server/' \
--prune-empty --tag-name-filter cat -- --all

git gc --prune=now
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now

push

サイズが減った後のoriginへのpush

git push origin --force --all
git push origin --force --tags

http://stevelorek.com/how-to-shrink-a-git-repository.html

参考にしたURL

https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html

http://easyramble.com/git-filter-branch.html

https://git-scm.com/book/ja/v1/Git%E3%81%AE%E5%86%85%E5%81%B4-%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%86%E3%83%8A%E3%83%B3%E3%82%B9%E3%81%A8%E3%83%87%E3%83%BC%E3%82%BF%E3%83%AA%E3%82%AB%E3%83%90%E3%83%AA

http://stackoverflow.com/questions/10656794/why-do-large-files-still-exist-in-my-packfile-after-scrubbing-them-with-filter

http://dskd.jp/archives/46.html

ハマりポイント4つ メモ

  • ファイルパスが間違っていると、当然、消えない。

git filter-branchを実行するとヒットしなくても処理が行われてる風な出力がある。でもサイズは減らない。

  • git filter-branch をしたら最初に git gc –prune=now を実行する。

atlassianの記事やstackoverflowの回答だと、
最後にgit gc –prune=nowするだけで良さそうだけど、
試しに、小さいgitリポジトリを作って試したら、
git gc –prune=nowをやらないと
.git/objects/ の中が空だった。
空のままで、

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all

をやっても効果がないっぽい。

  • 最後に – –all を付ける。 git filter-branch –index-filter ‘git rm –cached –ignore-unmatch test1.swf’ –prune-empty – –all のように、最後に
    – –all を付ける。
    これをやらないと、別のブランチでログが残ったままになってリポジトリサイズが減らない。

  • –tag-name-filter cat を付ける。

git filter-branch –index-filter ‘git rm –cached –ignore-unmatch \ test1.swf \ test2.swf \ test3.swf’ \ –prune-empty –tag-name-filter cat – –all のように、
–tag-name-filter cat
を付ける。 これをやらないとタグのログが残ってリポジトリサイズが減らない。

Ref 'refs/tags/1.7.12' was rewritten
WARNING: You said to rewrite tagged commits, but not the corresponding tag.
WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag.

サイズが減らないときの確認方法

git log aabbcc.swf  

で、gitログを見て、履歴があったら、そもそもログから消えていない。git filter-branchがうまくいっていない。

git_find_big.sh
で表示されていたら .git/objects/ の中にデータが残っている。

du -hs .
du  .git/objects/

履歴を消したファイルをコピーして元に戻す

git rm --cached  test1.txt

のようにするとファイルは消えないけど、
git filter-branch の中で–cached を付けてもファイルが消える。

git filter-branch --index-filter 'git rm --cached --ignore-unmatch test1.txt' --prune-empty --tag-name-filter cat -- --all

今回はバイナリファイルの履歴を消したいだけだったので、
消えたファイルは、バックアップしていた同じリポジトリから、cpコマンドでコピーする。