2015年5月4日月曜日

proxyサーバ導入

アメリカにいってるフレから日本のサイトがいくつか見れない><とチャットで不満をいっていたのでプロキシサーバをはじめて自宅サバにいれてみた。

http://qiita.com/pcnikki/items/404329f9ad9cb6e235d4
を参考にしこしことインストール作業を実施・・
portマッピングもしてフレのIPを許可してアクセスしてもらったら
見れなかったサイトもみれるようになったー!とのこと

仕事で得た知識を友達のためにつかえるのは至極気持ち良い・・!と思った今日この頃
アクセスはできるけどちょっと重い・・とのことなので
ちょこちょこ調べて改善できるかどうかひまなときヤッテミヨウ


2015年3月18日水曜日

リマインド

達人が語る,インフラエンジニアの心得
http://gihyo.jp/admin/serial/01/eng_knowhow

2014年10月24日金曜日

history コマンド実行履歴を表示

■コマンド履歴を表示する
------------------------------------------------------
[root@xxxxxxxxx ~]# history
    1  cd share/
    2  ls -l
    3  cd files
~~中略~~~~~~~
[root@xxxxxxxxx ~]# echo ${HISTTIMEFORMAT}
[root@dti-vps-srv741 ~]#
------------------------------------------------------
■コマンド履歴を日付時刻付で表示する
環境変数HISTTIMEFORMATに日付フォーマットを設定すると
historyコマンドの実行結果に日付時刻も記録するようになる
------------------------------------------------------
[xxxxxx@xxxxxxxx ~]$ history
    1  2014-10-24 10:32:05 /etc/init.d/tomcat5 start
    2  2014-10-24 10:32:05 vi /etc/init.d/tomcat5
    3  2014-10-24 10:32:05 EXIT
~~中略~~~~~~~
[xxxxxx@xxxxxxxx ~]$ echo ${HISTTIMEFORMAT}
%F %T
[xxxxxx@xxxxxxxx ~]$
------------------------------------------------------


■コマンド履歴を削除する
------------------------------------------------------
[xxxxxx@xxxxxxxx ~]$ history -c[xxxxxx@xxxxxxxx ~]$ history    1  2014-10-24 10:58:43 history[xxxxxx@xxxxxxxx ~]$

------------------------------------------------------

2014年10月21日火曜日

個人事業主メモ 退職 切り替え 個人事業主 SE

必要な手続き
http://egsguide.com/owner.php

退職届フォーマット
http://www.template.usefulful.net/down/syanai16_2.lzh


就職、社内文書

2014年9月30日火曜日

bash の脆弱性  SehllShock (CVE-2014-6721)

対応
yumつかってるなら
yum update bashで9月26日にだされた修正パッチをあてればよい


実際どのような箇所が問題なのか詳しく説明してくれているサイト様、すごいよくわかる・・!
http://moro-archive.hatenablog.com/entry/2014/09/27/200553



root@xxxxxx]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable  ←コイツがでるとアウト
this is a test

上記のようになると脆弱性ありありなので
yum update bashを実行
その後

[root@xxxxxx]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
this is a test

デナクナッター


----  仕事にて古いredhatの対応もせねばならなくなりそうなので色々まとめ     ------

■redhat or centosなら下記コマンドを実行してOSversionを確認する
cat /etc/redhat-release


■通常のredhat4は既にサポート切れ(2012/02/29)だが、延長契約をしてれば2015/02/29までredhatのレポジトリから
bashのアップデートで対応が可能。延長契約しているのかどうかをユーザ様に確認

#RHEL4 ELSは、2005年に出荷開始された「Red Hat Enterprise Linux 4」の7年間の標準サポートに加え、3年間の延長サポートを提供するもの。これにより、2012年2月29日までの標準サポートを最大2015年2月末まで延長が可能となる。

■現状脆弱性確認
[root@xxxxxx]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable   ←下記のthis is a test以外が表示された場合脆弱性あり
this is a test ←この文字列のみ表示された場合脆弱性なし

■バッシュ対応確認チェックスクリプト
https://github.com/hannob/bashcheck

[root@dti-vps-srv741 ~]# sh bashcheck
Testing /bin/bash ...
Bash version 4.1.2(1)-release

Variable function parser pre/suffixed [(), redhat], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Found non-exploitable CVE-2014-6277 (lcamtuf bug #1)
Not vulnerable to CVE-2014-6278 (lcamtuf bug #2)

上記のように表示されていれば対応完了済
対応できていないwarningやらerrorなどの文字列が含まれた結果が表示されるかと

■update対応
☆redhat 5~などなら
yum update bash-*
のみで対応できる。

☆redhat 4は延長サポートをうけていれば
 up2date -u bash-*
 で対応可能

☆redhat 4は延長サポートをうけていない場合
1・オラクルからでてる修正パッチをwgetで入手
wget https://oss.oracle.com/el4/SRPMS-updates/bash-3.0-27.0.2.el4.src.rpm
2・リビルド
rpmbuild -rebuild bash-3.0-27.0.2.el4.src.rpm
(rpmbuildコマンドが使えない場合使えるようインストールしておくこと)
3・インストール
rpm -Uvh bash-3.0-27.0.3.i386.rpm

■現状脆弱性確認
[root@xxxxxx]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
this is a test

上記結果となっていればインストール対応完了


バッシュversion確認
rpm -qa | egrep '^bash'

2014年9月29日月曜日

postfix メモ

■動いてるかもしれないデフォルトのsendmailを止める
/etc/rc.d/init.d/sendmail stop

■postfixインストール
yum -y install postfix

■postfix起動
[root@dti-vps-srv741 trunk]# service postfix restart
Shutting down postfix:                                     [FAILED]
Starting postfix:                                          [  OK  ]

■MTA変更前の設定確認
[root@dti-vps-srv741 trunk]# alternatives --display mta
mta - status is manual.
 link currently points to /usr/sbin/sendmail.sendmail    ←デフォルトはsendmail  

■MTAの切り替え
[root@xxxxx trunk]# alternatives --config mta

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail                      ・・・デフォルトはsendmailになってる
   2           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2  ・・postfixは2なので2を入力しエンター

■MTA変更後の設定確認
[root@xxxxx trunk]# alternatives --display mta
mta - status is manual.
 link currently points to /usr/sbin/sendmail.postfix    ←postfixになったことを確認

■メール送信テスト
[[root@xxxxx trunk]# /usr/sbin/sendmail -f <送信元メアド> <送信先メアド> <<EOM
From: <送信元メアド>
To: <送信先メアド>
Subject:テストです
Content-Type:text/plain;charset=UTF-8;
テストでメールを送ってみました。

EOM


送信先メアドで上記の送信テストのメールを受信できたかを確認


2014年9月19日金曜日

linux 権限系コマンドメモ

■現在のディレクトリ配下のroot権限になっているものを探す
find ./ -user root

■現在のディレクトリ配下のroot権限になっているものに対して一括でchown userA.groupAを実行する

find ./ -user root | xargs -i -r chown userA.groupA {}


■SVNの状態を確認する
svn st -u

■ファイルを更新する(SVN)
svn up -r HEAD
※リビジョンはリリースするときにどれを適用するのか決める

2014年9月10日水曜日

手動とcron実行・及び違うサーバで同じシェルスクリプト叩いて実行結果が違った時の確認

実行するときの環境変数の差を疑うべし

実行ユーザでprintenvした環境変数と
cronで実行したprintenvを比べてLANG設定とかちゃんと同じか確認する

# vi /etc/crontab
------------------------------------------------------------------------
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

*/1 * * * * root printenv > /root/printenv.txt
---------------------------------------------------------------

# less /root/printenv.txt
----------------------------------------
MAILTO=root
SHELL=/bin/bash
USER=root
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PWD=/
LANG=ja_JP.UTF-8
SHLVL=1
HOME=/
LOGNAME=root
_=/usr/bin/printenv
----------------------------------------



検証環境と本番環境で違っていたので上記の方法で確認して本番環境に
LANG設定がされてなかったのを確認

2014年7月17日木曜日

MySQL メモ

■カラムの追加と削除
http://www.dbonline.jp/mysql/table/index20.html

2014年7月16日水曜日

置換を行う REPLACE SQL

■テーブルのあるカラムを対象にabcという文字列が存在している場合、abcをdefに置き換えてアップデートする 特定行だけにしたい場合はwhere句をつける

UPDATE テーブル名 SET カラム名=REPLACE(カラム名,'abc','drg') ;

2014年7月15日火曜日

改行コードを入れる SQL

INSERT INTO NANTOKA_TABLE (textbody) VALUES ('改行を' || chr(10) || 'いれます');

chr(13) : CR    chr(10) : LF

2014年7月14日月曜日

MySQL コマンドラインメモ

1■エラーを無視してインポートするMySQLのコマンド( force)
http://nob-log.info/2013/02/15/mysql-force-import/

2■コマンドラインで実行するときのオプション
http://dev.mysql.com/doc/refman/4.1/ja/mysql.html


3■MySQLのコマンドラインで-pオプションを使わずにパスワードを指定する方法
http://heartbeats.jp/hbblog/2010/03/mysql-p.html
これをやらないと毎回
Warning: Using a password on the command line interface can be insecure.
がでてめんどい。


2+3の複合
シェルスクリプトでselect実行結果を変数にいれたいとき
-e  SQL文を渡すためのオプション
B   実行結果の枠線を消す
N   カラム名を表示しない

変数名=`mysql -uユーザ名 DB名 -NBe "select ~~"`

セレクトで得たid群分処理を回したい

ids=`mysql -uユーザ名 DB名 -NBe "select id from xxxxx"`
for i in $ids
do
 echo $i      
done

みたいな感じ ids に 1 2 3 と結果がはいった場合
for分は3回実行され $i は 1 2 3と順次中身がとりだされ実行される

2014年7月4日金曜日

cakePHPメモ

CakePHPの共通のライブラリの作り方

http://ameblo.jp/itboy/entry-11354038711.html

CakePHP:モデル内でコンポーネントを呼び出す

http://mac-studio.info/cakephp%EF%BC%9A%E3%83%A2%E3%83%87%E3%83%AB%E5%86%85%E3%81%A7%E3%82%B3%E3%83%B3%E3%83%9D%E3%83%BC%E3%83%8D%E3%83%B3%E3%83%88%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%99

CakePHPでコントローラーを複数のディレクトリに整理する方法

http://d.hatena.ne.jp/yandod/20080510/1210416583


[CakePHP2]コンポーネントでloadModelできる便利メソッドを作る

http://www.happyquality.com/2012/08/24/2449.htm

CakePHP2でComponentからHTTPリクエストのクエリパラメータを取得する方法

http://tech.oga-ria.com/get-request-query-parameter-at-component-in-cakephp/

2014年7月1日火曜日

cakephpでユーザ定義定数を読みだす

http://hakomori.net/cakephp-original-constant/

defineだけ記述したものでやりたく上記を参考にしてやってみたが
エラーが発生した・・とほほ


$configを最低でもひとつ定義していないと上記画面になるっぽい
下記のような$configをてきとーに一個かいてみたら上記画面はでなくなり、問題なく動作しました。
$config['test'] = array(
  "test_a"=>"abc",
  "test_b"=>"def",
 "test_c"=>"ghi",
);

2014年6月18日水曜日

Google Maps API V3 逆ジオコーディング

参考
https://developers.google.com/maps/documentation/javascript/geocoding?hl=ja
http://pcrice.blog129.fc2.com/blog-entry-161.html
https://sites.google.com/site/gmapsapi3/Home/services
http://negimemo.net/1860




現在地の緯度・経度を取得してそれを引数に都道府県を特定したかったので
上記を参考に取得確認できるようなものをてけとーにかいたのでメモ

<html>
<body>
<head>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>

<script type="text/javascript">
if (navigator.geolocation) {

    // 現在の位置情報を取得
    navigator.geolocation.getCurrentPosition(

      // (1)位置情報の取得に成功した場合
      function (pos){
        reversegeocoding(pos.coords.latitude,pos.coords.longitude);
      },
      // (2)位置情報の取得に失敗した場合
      function (error) {
        var message = "";

        switch (error.code) {

          // 位置情報が取得できない場合
          case error.POSITION_UNAVAILABLE:
            message = "位置情報の取得ができませんでした。";
            break;

          // Geolocationの使用が許可されない場合
          case error.PERMISSION_DENIED:
            message = "位置情報取得の使用許可がされませんでした。";
            break;

          // タイムアウトした場合
          case error.PERMISSION_DENIED_TIMEOUT:
            message = "位置情報取得中にタイムアウトしました。";
            break;
        }
                window.alert(message);
        }
    );
} else {
    window.alert("本ブラウザではGeolocationが使えません");
}

function reversegeocoding(lat,lng){

    var geocoder;
        alert("id: " + lat); // 緯度
        alert("keido: " + lng); // 経度
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(lat,lng);

if (geocoder) {
            geocoder.geocode({'latLng': latlng}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                        for (var r = 0; r < results.length; r ++) {
                                var end = 0;
                                var address = results[r].address_components;
                                for (var i = 0; i < address.length; i++) {
                                        switch (address[i].types[0]) {
                                                case "administrative_area_level_1":
                                                alert(address[i].long_name);
                                                end = 1;
                                                break;
                                        }
                                }
                                if(end == 1){
                                        break;
                                }
                        }

                }else{
                    alert("Geocoder failed due to: " + status);
                }
                });
        }
}
</script>
</body>
</html>

2014年6月12日木曜日

vi --LinuxCommand


■■ 編集モードへ移る ■■
・現在のカーソル位置から挿入
i

・現在のカーソル位置から置換
R

・現在行の末尾に追加
A

■■ 終了 ■■■■■■■■
・保存
:w

・保存して終了
:wq

・保存せずに終了
:q

・変更した行も保存せずに終了
:q!

■■ 検索 ■■■■■■■■
・前方検索
/正規表現

・後方検索
?正規表現

・次の候補
n

・前の候補
N

■■■■■■■■■■■■■
・行表示
:set number

・指定行に飛ぶ
 517行目に飛ぶ
:517

・範囲選択での削除
  1. 削除範囲の開始行で「ms」と入力します。
  2. 削除範囲の終了行で「me」と入力します。
  3. :'s,'ed」と入力し、エンターを押します。
参考
http://d.hatena.ne.jp/nattou_curry_2/20090915/1253022774#delete


2014年6月9日月曜日

jQuery 値を取得する

http://www.jquerystudy.info/reference/
http://www.jquerystudy.info/reference/manipulation/text.html

・jQuery 選択されているラジオボタンの値を取得する
http://symfoware.blog68.fc2.com/blog-entry-871.html

・jQueryでチェックボックスのチェック状態を調べる
http://d.hatena.ne.jp/replication/20130613/1371137959

・jQueryでチェックされたcheckboxの値を取得して配列に格納する方法、また、配列をcheckboxの値に設定する方法
http://knt45.hatenablog.com/entry/2013/04/15/131531

2014年5月22日木曜日

シンボリックリンクを作成する ln --LinuxCommand

ln -s <参照先> シンボリックリンク名

・/var/www/share配下にproperty_imagesという名のシンボリックリンクを作成
  向き先は/opt/images/public
ln -s /opt/images/public /var/www/share/property_images

2014年5月18日日曜日

apache2.4 mysql5.6 php5.5 linuxインストールメモ

※centos6.4, httpd-2.4.6, MySQL-5.6.14, php-5.5.6
■最新化
yum update
■makeの下準備
yum install gcc gcc-c++ zlib zlib-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel curl curl-devel openssl-devel
■Apache
yum install -y pcre-devel
wget http://archive.apache.org/dist/httpd/httpd-2.4.6.tar.gz
tar zxvf httpd-2.4.6.tar.gz
cd httpd-2.4.6
cd ./srclib/
wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-1.5.1.tar.gz
wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-util-1.5.3.tar.gz
tar zxvf apr-1.5.1.tar.gz
tar zxvf apr-util-1.5.3.tar.gz
mv apr-1.5.0 apr
mv apr-util-1.5.3 apr-util
cd ..
./configure --with-included-apr --enable-mods-shared=all
make
make install
/usr/local/apache2/bin/httpd -v

cp build/rpm/httpd.init /etc/rc.d/init.d/httpd
vim /etc/rc.d/init.d/httpd ← bin,pidのあたりを修正する

ps -aux | grep httpd
kill [process number]

service httpd [start,stop,restart]

vim /etc/hosts ← hostname を追加する

htpasswd -c .htpasswd xxxxxx

/usr/local/apache2/bin/httpd -S -DSSL
/usr/local/apache2/bin/httpd -M
■MySQL
yum install libaio libaio-devel
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.14-1.linux_glibc2.5.x86_64.rpm-bundle.tar
tar xvf MySQL-5.6.14-1.linux_glibc2.5.x86_64.rpm-bundle.tar
rpm -ivh MySQL-shared-5.6.14-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-client-5.6.14-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-server-5.6.14-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.14-1.linux_glibc2.5.x86_64.rpm

ls /etc/my.cnf
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
service mysql start

view ~/.mysql_secret ← パスワードの確認
mysql -u root -p
SET PASSWORD = PASSWORD('root');
■PHP
wget http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
vim /etc/yum.repos.d/epel.repo ← enabled=0
yum --enablerepo=epel install libmcrypt-devel
wget http://jp1.php.net/get/php-5.5.6.tar.gz/from/this/mirror
tar zxvf php-5.5.6.tar.gz
cd php-5.5.6
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --enable-mbstring --enable-mbregex --with-mcrypt --enable-calendar --with-libdir=lib64 --with-mysql --with-mysqli --with-openssl --with-curl --with-curlwrappers --enable-zip
[20140724]./configure --prefix=/usr/local/php --with-apxs2=/etc/httpd/bin/apxs --enable-mbstring --enable-mbregex --with-mcrypt --enable-calendar --with-libdir=lib64 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-curl --enable-zip --enable-memcache --with-gd --with-zlibmake
make test
make install

/usr/local/php/bin/php -v
cd /usr/bin
ln -s /usr/local/php/bin/php php
php -r 'phpinfo();'  | grep php.ini
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini ← time.zone = Asia/Tokyo
■SVN
yum install subversion
svn help
svn export https://xxxxxxxx
■phpmadmin
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.9/phpMyAdmin-4.0.9-all-languages.zip?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Findex.php&ts=1385817138&use_mirror=jaist
unzip phpMyAdmin-4.0.9-all-languages.zip
mv phpMyAdmin-4.0.9-all-languages phpmyadmin
mv phpMyAdmin-4.0.9-all-languages.zip ./org
cd phpmyadmin/
cp config.sample.inc.php config.inc.php
vim config.inc.php

2014年5月13日火曜日

phpadminインストール メモ linux

■phpadminインストール
cd /root/src
wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.0/phpMyAdmin-4.2.0-all-languages.tar.gz/download#
tar xvfz download
mv phpMyAdmin-4.2.0-all-languages /etc/httpd/htdocs/phpmyadmin
cp /etc/httpd/htdocs/phpmyadmin/config.sample.inc.php /etc/httpd/htdocs/phpmyadmin/config.inc.php
chmod 660 /etc/httpd/htdocs/phpmyadmin/config.inc.php
vi /etc/httpd/htdocs/phpmyadmin/config.inc.php

$cfg['blowfish_secret'] = 'denen';
$cfg['Lang'] = 'ja-utf-8';

Basic認証設置
/etc/httpd/bin/htpasswd -c /etc/httpd/htdocs/phpmyadmin/.htpasswd xxxxx  ←xxxはユーザ名
パスワード: xxxxxxx

vi /etc/httpd/htdocs/phpmyadmin/.htaccess

AuthType Basic
AuthName "Please Enter Your Password"
AuthUserFile /etc/httpd/htdocs/phpmyadmin/.htpasswd
Require valid-user