プロキシの指定方法 (yum, wget, curl, python, pip)
まとまった情報が無かったので、忘備録として。
なお、Cent OS7にて動作を確認。
プロキシを突破するのは、大変である(-_-;)
プロキシ情報
適宜、読み替えてください。
- ホスト名: proxy.example.com
- Port: 8080
- ID: USERNAME
- Password: PASSWD
yum
/etc/yum.confに追記。
proxy=http://proxy.example.com:8080 proxy_username=USERNAME proxy_password=PASSWORD
wget
/etc/wgetrcに追記。
http_proxy = http://USERNAME:PASSWD@proxy.example.com:8080/
curl
curl --proxy http://USERNAME:PASSWD@proxy.example.com:8080 -O http://yahoo.co.jp/index.html
python
python get-pip.py --proxy=“http://USERNAME:PASSWD@proxy.example.com:8080”
pip
pip --proxy http://USERNAME:PASSWD@proxy.example.com:8080 install pep8
Jenkinsを使ってみる(CentOS+Vagrant)
今や、使えないことが問題と言われる、CIツールのJenkins。
とりあえず使えるようにしてみた。
Jenkinsインストール
公式に則ってインストール。必要に応じてJavaの環境もインストール。
RedHat Repository for Jenkins
Jenkinsのポートを変更
後々、svnを同じ環境に入れる為、ポートを変更 。
sudo vim /etc/sysconfig/jenkins
JENKINS_PORT="8090"
iptablesの設定変更
iptablesのポートも開ける。
sudo vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8090 -j ACCEPT
http://
Jenkinsおじさんが表示されればOK。
JenkinsでPythonを静的解析(flake8)
flake8を使って、Pythonのコードを静的解析してみる。
Jenkinsを使ってコミット時に実行するようにすれば、すぐに気づけてお得( ̄ー ̄)
準備
pipのインストール
flake8をインストールする為に、まずはpipのインストール。
どうやらいつの間にかpipのインストールが楽になってたようです。
$ curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
flake8をインストール
pipが入っていれば簡単。
$ pip install flake8
Jenkinsのジョブを作成
以下のジョブを作成する。
$ flake8 .
結果
エラーがある場合
flake8でエラーが出る場合は、「ビルド失敗」と判定される。
Started by user anonymous Building in workspace /var/lib/jenkins/jobs/Flake8 test/workspace Cleaning local Directory . Checking out http://localhost:80/svn/trunk/python at revision '2014-10-31T01:09:51.748 +0900' A hello_world.py At revision 11 [workspace] $ /bin/sh -xe /tmp/hudson838485310037875301.sh + flake8 . ./hello_world.py:3:1: E302 expected 2 blank lines, found 1 Build step 'Execute shell' marked build as failure Finished: FAILURE
エラーが無い場合
一方、エラーが出ない場合=flake8 .の出力が無い場合は、「ビルド成功」と判定される。
Started by an SCM change Building in workspace /var/lib/jenkins/jobs/Flake8 test/workspace Cleaning local Directory . Checking out http://localhost:80/svn/trunk/python at revision '2014-10-31T01:13:05.095 +0900' A hello_world.py At revision 12 no revision recorded for http://localhost:80/svn/trunk/python in the previous build [workspace] $ /bin/sh -xe /tmp/hudson7270646181000268555.sh + flake8 . Finished: SUCCESS
感想
すごく簡単。
コーディング規約はツールでのチェックを入れないと形骸化しそうなので、Jenkinsとの相性が良い。
ちなみに、ビルド成功/失敗の判定については、下記が参考になる。
Things you didn't know about Jenkins - Why does Jenkins think my build succeeded?
Ansibleを使ってみる
MacでAnsibleを使う
Macで使うとハマるという噂を聞いていたが、Macにインストールしてみる。
構成
Control Machine
- Mac OSX (10.10)
Managed Node
環境構築
1. MacにAnsibleをインストール
公式の手順に従う。
特にハマることは無かった。(sudoにしないとPermission Deniedになるくらい。)
$ brew update $ sudo brew install ansible $ ansible --version ansible 1.7.2
2. vagrant up
適当に。
今回は、特にポートフォワーディング等の設定は不要。
3. ssh設定
下記の設定をしておくと、簡単に接続できる。
※この場合、hostsに指定するのは"centos"
$ vagrant ssh-config --host centos >> ~/.ssh/config
これで、vagrant sshと同じように、VMにssh接続($ ssh centos)できるようになる。
参考:Mac OS XでVagrantとChefを使った環境構築のまとめ - Qiita
接続確認
hostsを作る
接続時のhostsファイルを作成。
$ echo "centos" > hosts
サンプル
$ ansible all -m ping -i hosts centos | success >> { "changed": false, "ping": "pong" } $ ansible all -i hosts -a "pwd" centos | success | rc=0 >> /home/vagrant
参考
ユーザ名とパスワードを使った方式でも動くはずだが、エラー。
the sshpass programが無く、別途インストールする必要が有る模様(未検証)。
$ ansible all -m ping -i hosts --ask-pass SSH password: 192.168.33.13 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program
参考:Ansible OS X Mavericks You Must Install the sshpass Program
Vagrantでmountに失敗した時の対処法
vagrant up
した時に、下記のエラーが出た時の対処法。
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:mount -t vboxsf -o uid=
id -u vagrant
,gid=getent group vagrant cut -d: -f3
vagrant /vagrant
mount -t vboxsf -o uid=id -u vagrant
,gid=id -g vagrant
vagrant /vagrant
VMにsshでログインし、以下のコマンドを実行することで直る。
sudo /etc/init.d/vboxadd setup
コマンドを検索してみたが、ちょいちょいshared folderやらVirtualBoxのGuestAdditionで引っかかっている方がいるっぽい。