【Linux】mkisofsでファイル名の長さが短くなる
mkisofsは、その名の通りisoファイルを作成するコマンドです。
実際に、iso化した後、中身を見ると、ファイル名が本来よりも短くなってしまいます。
以下の用にオプションをつけて実行することで、107文字まで許容されます。
# mkisofs -joliet-long -o [出力iso] [対象]
以上
【jQuery】要素に独自データ data-xxx="value"を設定してjQueryから取得する
htmlの要素として、独自のパラメーターを設定しておいて、クリックなどのイベント時に設定した値を使う場合の書き方
HTML側
data-xxx="パラメーター"という形で記述
<span class="like-btn fa fa-paperclip" data-id="100"></span> #### JavaScript側 getAttribute('data-xxx')で取得できる
以上
OpenStack CinderのNFS backup ドライバー設定【Liverty】
権限について深く考えずに設定していたら、以下のエラーが出てきた。
2016-04-28 18:27:24.891 19077 ERROR oslo_messaging.rpc.dispatcher mkdir(name, mode)
2016-04-28 18:27:24.891 19077 ERROR oslo_messaging.rpc.dispatcher OSError: [Errno 13] Permission denied: '/mnt/cinder_backup/c841208c81a84c535fa19ba7bec54a32
設定を見直したので、備忘録
必要な設定は以下。
Cinder側
- /etc/cinder.conf
NFS Server側
- /etc/exports
- バックアップ用ディレクトリの権限
Cinder側
/etc/cinder.confには以下を追記
backup_driver = cinder.backup.drivers.nfs
backup_mount_point_base = /mnt/cinder_backup # マウント先ディレクトリ
backup_share = [NFS Server IP]:/var/nfs/cinder_backup # マウント対象ディレクトリ
NFS Server側
/etc/exportsには以下のように記載
/var/nfs/cinder_backup [マウントを許可するIPアドレス]/24(rw,wdelay,all_squash,no_subtree_check)
バックアップ用ディレクトリの権限設定
# mkdir /var/nfs/cinder_backup
# chown nfsnobody:nfsnobody /var/nfs/cinder_backup
設定は以上。
バックアップを実行すると以下のように、NFSのディレクトリがマウントされる
[root@hoge ~(keystone_admin)]# df
ファイルシス 1K-ブロック 使用 使用可 使用% マウント位置
/dev/mapper/centos-root 36476416 9578548 25021900 28% /
devtmpfs 2962872 0 2962872 0% /dev
tmpfs 2973388 0 2973388 0% /dev/shm
tmpfs 2973388 268940 2704448 10% /run
tmpfs 2973388 0 2973388 0% /sys/fs/cgroup
/dev/loop0 1900368 6148 1772980 1% /srv/node/swiftloopback
/dev/sda1 508588 169464 339124 34% /boot
tmpfs 594680 0 594680 0% /run/user/0
tmpfs 594680 0 594680 0% /run/user/163
192.168.23.9:/var/nfs/cinder_backup 37300736 9403904 27896832 26% /mnt/cinder_backup/c841208c81a84c535fa19ba7bec54a32
バックアップを実行すると、以下のようにバックアップした実体が作成される
[root@hoge ~(keystone_admin)]# ls -rlt /mnt/cinder_backup/c841208c81a84c535fa19ba7bec54a32/7b/be/7bbe00c4-46b8-4b3a-8837-c612b7f28f0f/
合計 15488
-rw-rw---- 1 nfsnobody nfsnobody 13456903 4月 28 18:31 backup-00001
-rw-rw---- 1 nfsnobody nfsnobody 2392351 4月 28 18:31 backup_sha256file
-rw-rw---- 1 nfsnobody nfsnobody 2135 4月 28 18:31 backup_metadata
以上
【kvm】vncで接続するためのiptablesの設定
下記を/etc/sysconfig/iptablesに記載する。
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A OUTPUT -p tcp --sport 11051 -j ACCEPT
-A INPUT -p tcp --dport 11050 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5900:5920 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
iptablesを再起動
# systemctl restart iptables
【rails】DBをPostgreSQLに変更するとcounter cultureが使えなくなったのでgemを修正
railsのDBがsqliteの時は、counter cultureでculture_fix_countsを普通に実行できていたが、DBをpostgresqlに変えると、以下のようなエラーが出るようになった。
irb(main):007:0> Picture.counter_culture_fix_counts
PG::GroupingError: ERROR: column "albums.pictures_count" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...id, albums.album_id, COUNT(pictures.id) AS count, albums.pic...
^
: SELECT albums.album_id, albums.album_id, COUNT(pictures.id) AS count, albums.pictures_count FROM "albums" LEFT JOIN pictures AS pictures ON albums.album_id = pictures.album_id GROUP BY "albums"."album_id" ORDER BY "albums"."album_id" ASC LIMIT 1000 OFFSET 0
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "albums.pictures_count" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...id, albums.album_id, COUNT(pictures.id) AS count, albums.pic...
^
: SELECT albums.album_id, albums.album_id, COUNT(pictures.id) AS count, albums.pictures_count FROM "albums" LEFT JOIN pictures AS pictures ON albums.album_id = pictures.album_id GROUP BY "albums"."album_id" ORDER BY "albums"."album_id" ASC LIMIT 1000 OFFSET 0
以下の通りに修正
修正対象ファイル
/home/hoge/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/counter_culture-0.1.34/lib/counter_culture.rb
修正箇所
変更前
while (records = counts_query.reorder(full_primary_key(klass) + " ASC").offset(start).limit(batch_size).group(full_primary_key(klass)).to_a).any?
変更後
while (records = counts_query.reorder(full_primary_key(klass) + " ASC").offset(start).limit(batch_size).group(full_primary_key(klass),"#{klass.table_name}.#{column_name}").to_a).any?
以上
【Ruby On Rails 4】DBをPostgresqlに変更する(Ubuntu Server14.04)
sqliteはDBの更新処理時の排他制御がいまいちなので、postgresqlに乗り換える。
必要なパッケージのインストール
$ sudo apt-get install postgresql libpq-dev
Gemfileのsqliteを削除して、postgresを追加
$ vi Gemfile
- gem 'sqlite3'
+ gem "pg"
gemを追加します。
$ bundle install
PostgreSQLサーバの初期設定
PostgreSQL上に、以下2つの管理用ユーザーを作成します。
- postgres
- hoge
ここでは、次の2つを使うことにします。
- gnDwPsFVM5kMU (postgres)
- diiNv2bid4aTI (hoge)
念のためこれらのパスワードは /root ディレクトリに記録します。
$ sudo -s
% echo "gnDwPsFVM5kMU" > /root/postgres_postgres_password
% echo "diiNv2bid4aTI" > /root/postgres_hoge_password
% chmod 400 /root/postgres_*_password
% exit
adminユーザーとamin_productionデータベースを作ります。
% sudo su - postgres
% createuser -a hoge
% createdb -E UTF8 -O hoge hoge_production -T template0
% psql -c "alter user postgres with password 'gnDwPsFVM5kMU'"
% psql -c "alter user hoge with password 'diiNv2bid4aTI'"
% exit
DB接続時の認証をパスワード認証に変更します。
% sudo vi /etc/postgresql/9.3/main/pg_hba.conf
- local all all peer
+ local all all md5
設定を反映します。
% sudo service postgresql reload
DBにhogeユーザーでログインします。 hogeユーザーのパスワードを入力すると、ログインできます。 ログインできれば、postgresqlの設定は完了です。
$ psql -U hoge hoge_production
Password for user hoge:
psql (9.3.12)
Type "help" for help.
hoge_production=#
Railsでpostgresqlを使う設定
config/database.ymlを以下の通り編集します。
default: &default
adapter: postgresql
username: hoge
password: il9aA35JcBx
encoding: utf8
pool: 5
host: localhost
development:
<<: *default
database: hoge_development
test:
<<: *default
database: hoge_test
production:
<<: *default
database: hoge_production
productionモードでDBを作成します。
$ RAILS_ENV=production rake db:create
$ RAILS_ENV=production rake db:migrate
これで、railsからpostgresqlを利用する設定は完了です。
確認
railsのDBコンソールに接続できれば、正常に設定できています。
$ rails c -e production
以上、Ubuntu14.04でrailsのDBをpostgresqlに変更する手順でした。