月: 2015年5月

jQuery UIでリストのソート機能を実装したときにFirefoxとかでinputのフォーカスがおかしくなる件

AngularJsのディレクティブでリストのソート機能を
実装していて困ったのでメモ。

ディレクティブでは実際には「jQuery UI」の「sortable」を
利用していた。

各々のバージョンは以下
jQuery v2.1.3
jQuery UI v1.11.4
AngularJS v1.3.15

実装したコードは以下。

app.directive('mySortable',function(){
    return {
        link:function(scope,el,attrs){
            el.sortable({
                revert: true,
                axis: 'y',
                cancel: "",
                handle: ".sortable-handle"
            });
            
            el.disableSelection().delegate('input,textarea','click',function(ev){
                ev.target.focus();
            });
            
            el.on( "sortdeactivate", function( event, ui ) {
                //ソートした時の挙動
                ・・・
            });
            
        }
    }
})

上記の状態だと「Firefox」と「IE」でソートは出来るのだけどソートする対象内に
あるinputタグにフォーカスが当たるけど全選択(Ctrl+a)とかができないし、
入力値がある場合にもなぜか必ず入力エリアの左側にカーソルが入ってしまう
現象が発生した。

結局以下↓の箇所を

el.disableSelection().delegate('input,textarea','click',function(ev){
    ev.target.focus();
});

【jQuery】sortable()を設定したタグ内のtextarea, inputタグに入力出来ない」このページの内容通りに以下↓のように変更。

el.bind('click.sortable mousedown.sortable',function(ev){
    ev.target.focus();
});

直った。。

jQuery UI の.disableSelection()がdeprecated(非推奨)になってる件

↑これとかの影響なのかな・・・。

■参考URL

【jQuery】sortable()を設定したタグ内のtextarea, inputタグに入力出来ない

Ticket #4429 (closed bug: notabug) Can’t select text in inputs within sortables

jQuery UI の.disableSelection()がdeprecated(非推奨)になってる件

Vagrantで立てたCnetOS7にLAMP環境を構築する

Vagrantで立てたCnetOS7にLAMP環境を構築する

ざっくりとローカル環境を構築する手順。

【とりあえず】

# yum update

【時間】

# timedatectl status
      Local time: Wed 2015-05-27 00:34:51 EDT
  Universal time: Wed 2015-05-27 04:34:51 UTC
        Timezone: America/New_York (EDT, -0400)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2015-03-08 01:59:59 EST
                  Sun 2015-03-08 03:00:00 EDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2015-11-01 01:59:59 EDT
                  Sun 2015-11-01 01:00:00 EST

# timedatectl set-timezone Asia/Tokyo

# timedatectl status
      Local time: Wed 2015-05-27 13:35:36 JST
  Universal time: Wed 2015-05-27 04:35:36 UTC
        Timezone: Asia/Tokyo (JST, +0900)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

# date
Wed May 27 13:35:46 JST 2015

【日本語化】

# yum -y install ibus-kkc vlgothic-* 

# localectl list-locales | grep -i ja
ja_JP
ja_JP.eucjp
ja_JP.ujis
ja_JP.utf8
japanese
japanese.euc

# localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: jp106
      X11 Layout: jp

# localectl set-locale LANG=ja_JP.utf8

# localectl status
   System Locale: LANG=ja_JP.utf8
       VC Keymap: jp106
      X11 Layout: jp

# source /etc/locale.conf

# echo $LANG
ja_JP.utf8

# date
2015年  5月 27日 水曜日 13:42:59 JST

【NTP】

# yum install chrony

# systemctl start chronyd.service

# systemctl enable chronyd.service

# systemctl status chronyd.service
chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled)
   Active: active (running) since 水 2015-05-27 13:53:36 JST; 7min ago
 Main PID: 4658 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─4658 /usr/sbin/chronyd -u chrony

 5月 27 13:53:36 localhost.localdomain chronyd[4658]: chronyd version 1.29.1 starting
 5月 27 13:53:36 localhost.localdomain chronyd[4658]: Linux kernel major=3 minor=10 patch=0
 5月 27 13:53:36 localhost.localdomain chronyd[4658]: hz=100 shift_hz=7 freq_scale=1.00000000 nominal_tick=10000 slew_delta_tick=833 max_tick_bias=1000 shift_pll=2
 5月 27 13:53:36 localhost.localdomain chronyd[4658]: Generated key 1
 5月 27 13:53:36 localhost.localdomain systemd[1]: Started NTP client/server.
 5月 27 13:53:41 localhost.localdomain chronyd[4658]: Selected source 157.7.235.92
 5月 27 13:53:41 localhost.localdomain chronyd[4658]: System clock wrong by 404.387741 seconds, adjustment started
 5月 27 14:00:25 localhost.localdomain chronyd[4658]: System clock was stepped by 404.388 seconds

・状態確認
# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^+ y.ns.gin.ntt.net              2   6    37    29   +714us[  -30ms] +/-   49ms
^+ li528-174.members.linode.     3   6    37    29   +111us[  -30ms] +/-   59ms
^+ chobi.paina.jp                2   6    37    29   -321us[  -31ms] +/-   47ms
^* v157-7-235-92.z1d6.static     2   6    37    29   -727us[  -32ms] +/-   38ms

「*」が現在同期をとっているサーバ

【SELinux】

# getenforce 
Enforcing

ローカルの開発環境なので無効にする
# vim /etc/selinux/config  
SELINUX=disabled

# reboot

# getenforce
Disabled

【Webサーバ】

# yum install httpd httpd-devel httpd-tools

# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: inactive (dead)

# systemctl start httpd.service

# systemctl enable httpd.service

# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Tue 2015-05-26 21:12:03 EDT; 1min 10s ago
 Main PID: 7308 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─7308 /usr/sbin/httpd -DFOREGROUND
           ├─7309 /usr/sbin/httpd -DFOREGROUND
           ├─7310 /usr/sbin/httpd -DFOREGROUND
           ├─7311 /usr/sbin/httpd -DFOREGROUND
           ├─7312 /usr/sbin/httpd -DFOREGROUND
           └─7313 /usr/sbin/httpd -DFOREGROUND

May 26 21:12:03 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
May 26 21:12:03 localhost.localdomain httpd[7308]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
May 26 21:12:03 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

# firewall-cmd --permanent --add-service=http
success

# firewall-cmd --reload
success

# pwd
/etc/httpd/conf

# cp httpd.conf httpd.conf.org

# vim httpd.conf

# pwd
/etc/httpd/conf.d

# cp userdir.conf userdir.conf.org

# vim userdir.conf

# systemctl restart httpd.service

【PHP】

# yum install php php-cli php-common php-devel php-gd php-mbstring php-mysql php-pdo php-xml php-xmlrpc php-pear

# pwd
/etc

# cp php.ini php.ini.org

# systemctl restart httpd.service

【データベース】

# yum install mariadb-server mariadb-devel mariadb-libs  

# systemctl start mariadb.service

# systemctl enable mariadb.service

# firewall-cmd --permanent --add-service=mysql
success

# firewall-cmd --reload
success

# systemctl status mariadb.service
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
   Active: active (running) since Tue 2015-05-26 22:22:28 EDT; 1min 24s ago
 Main PID: 12165 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─12165 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─12323 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: The latest information about MariaDB is available at http://mariadb.org/.
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: You can find additional information about the MySQL part at:
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: http://dev.mysql.com
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: Support MariaDB development by buying support/new features from MariaDB
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: Corporation Ab. You can contact us about this at sales@mariadb.com.
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: Alternatively consider joining our community based development effort:
May 26 22:22:26 localhost.localdomain mariadb-prepare-db-dir[12087]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
May 26 22:22:26 localhost.localdomain mysqld_safe[12165]: 150526 22:22:26 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
May 26 22:22:26 localhost.localdomain mysqld_safe[12165]: 150526 22:22:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
May 26 22:22:28 localhost.localdomain systemd[1]: Started MariaDB database server.

# mysqladmin -u root password '******'

# mysqladmin -p -u root -h localhost password '******'
Enter password: 

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

設定ファイルを変更する
# pwd
/etc

# cp my.cnf my.cnf.org

# diff my.cnf.org  my.cnf                                                                                                                                                                                                
10a11,12
> character-set-server = utf8
> 

※[mysqld] に、character-set-server = utf8 を追記。

# systemctl restart mariadb.service

MariaDB [(none)]> show variables like 'char%';
+--------------------------+----------------------------+
| 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)

【Samba】

# yum install samba samba-client samba-common samba-devel samba-libs

# systemctl start smb.service

# systemctl enable smb.service

# firewall-cmd --permanent --add-service=samba
success

# firewall-cmd --permanent --add-service=samba-client
success

# firewall-cmd --reload
success

・ユーザの追加
# pdbedit -a -u linuxusername
new password:
retype new password:
Unix username:        linuxusername
NT username:          
Account Flags:        [U          ]
User SID:             S-1-5-21-3433598194-894145024-3160967228-1000
Primary Group SID:    S-1-5-21-3433598194-894145024-3160967228-513
Full Name:            
Home Directory:       \\localhost\linuxusername
HomeDir Drive:        
Logon Script:         
Profile Path:         \\localhost\linuxusername\profile
Domain:               LOCALHOST
Account desc:         
Workstations:         
Munged dial:          
Logon time:           0
Logoff time:          Wed, 06 Feb 2036 10:06:39 EST
Kickoff time:         Wed, 06 Feb 2036 10:06:39 EST
Password last set:    Wed, 27 May 2015 00:03:41 EDT
Password can change:  Wed, 27 May 2015 00:03:41 EDT
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

・セクションの追加
# pwd
/etc/samba

# cp smb.conf smb.conf.org

# vim smb.conf

# diff smb.conf.org smb.conf
296a297,306
> 
>       comment = Document Root Directory
>       path = /var/www/html
>       public = yes
>       writable = yes
>       printable = no
> 
>       create mask = 0664
>       directory mask = 0775
> 

【サービスの公開状態確認】

# firewall-cmd  --list-services
dhcpv6-client http mysql samba samba-client ssh

CentOS7をVagrantで動かしたい

CentOS7をVagrantで動かしたい。

CentOS7の練習のために環境が欲しい。

$ vagrant box add CentOS7_minimal https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box                                                  
Downloading or copying the box...
Extracting box...ate: 9955k/s, Estimated time remaining: --:--:--)
Successfully added box 'CentOS7_minimal' with provider 'virtualbox'!

初期化。

$ vagrant init CentOS7_minima

VagrantfileでIPの指定してから起動

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'CentOS7_minimal'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

ARPCHECK=no /sbin/ifup eth1 2> /dev/null

Stdout from the command:



Stderr from the command:

エラー出た。

■[Sy] 【解決した】VagrantでCentOS7のVMを作ったらネットワーク設定でコケた(固定IP割り当てに失敗)
http://www.utano.jp/entry/2014/11/vagrant_centos7_network_error

上記サイトを参考にvagrantを新しくしてみる。

https://www.vagrantup.com/downloads.html

# rpm -Uvh vagrant_1.7.2_x86_64.rpm
# vagrant -v
Vagrant 1.7.2

CentOS7を起動してみる。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/takeuchi/fujita_cent7
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

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

共有フォルダのマウントで失敗している模様。

■vagrant起動で”Failed to mount folders in Linux guest”のエラーが出た件
http://l-light-note.hatenablog.com/entry/2015/04/04/212648

以下をやってみた。

$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Installed the plugin 'vagrant-vbguest (0.10.0)'!

一旦落として。

$ vagrant halt

再度起動。

$ vagrant up

起動できた。

そもそも共有フォルダ使ってないから使わないようにしたらよいかも。
ついでにVirtualBoxのアップデートもした。

■参考URL

[Sy] 【解決した】VagrantでCentOS7のVMを作ったらネットワーク設定でコケた(固定IP割り当てに失敗)
http://www.utano.jp/entry/2014/11/vagrant_centos7_network_error

VirtualBoxとVagrantをバージョンアップする
http://qiita.com/mashumashu/items/557dcb805e77315004b1

vagrant起動で”Failed to mount folders in Linux guest”のエラーが出た件
http://l-light-note.hatenablog.com/entry/2015/04/04/212648

Failed to mount folders in Linux guest. This is usually because the “vboxsf” file system is not available.を直す方法
http://qiita.com/DQNEO/items/2375dd8002a831268cb5

Vagrant で CentOS 6.5 を使っていたら Guest Additions の更新に失敗してハマった
http://qiita.com/a-suenami/items/3b04151ce6e7d5b72a3e

Vagrantでフォルダがmountできないエラーが出たときの対応
http://qiita.com/kazu69/items/812b236e84fee1db3900