Pippi Life

主に仕事に関連するITのことや、プライベートもちょいちょい書きます。

CentOS 7にMySQL5.6.22をインストールする。

仕事でCMSを使う機会があって、MySQLを導入する必要がありました。

ということで、MySQL導入します。

MariaDBの何かしらがインストールされていないか確認

yum list installed | grep maria

入っていました。

mariadb-libs.x86_64              1:5.5.35-3.el7                        @anaconda

MySQLを入れるのでアンインストール

yum -y remove mariadb-libs

MySQLのインストール

#コミュニティのリポジトリを追加
yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

#それぞれ追加していきましょう。
yum -y install mysql
yum -y install mysql-devel
yum -y install mysql-server
yum -y install mysql-utilities

mysqlデーモンの起動コマンド

service mysqld start

DB初期設定はこのコマンド

/usr/bin/mysql_secure_installation

そうするとこんなん出てきます。

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    ←確か空エンター
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y    ←rootのパスワードを設定するか?yes!
New password:
Re-enter new password:      ←パスワードを入力
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y       ←アノニマスユーザー削除する?yes!
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y   ←rootのリモート接続はできないようにする?yes!
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y  ←テストDB削除する?yes!
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!
#なんかエラー出てるけど、まあいいか!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y     ←権限設定をリロードしとく?yes!
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

接続してみましょう。

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql
mysql show databases;

無事に接続されました。

梅雨ですが、ベランダは元気です。

私の家はマンションの3階にあるのですが、日当たりはあまりよくないです。 しかしなにか作りたいという気持ちが募り募った結果、今ベランダに4つのプランターが並んでいますw

バジル、ゴーヤ、トマト、モロヘイヤ。

初夏になって、バジルが元気な季節になりました。 バジルは生命力が強いのか、水をあげる以外放置してもどんどん葉っぱを増やしてくれます。 葉っぱは摘み取って、市販のトマトソースと一緒にとか、絶品ですよ。

100均の安いソースとパスタでも、バジルをたっぷりいれるだけでさわやかな美味しさが!! さらにチーズを入れたらもっと幸せな味に!

秋冬になったら残念ながら枯れ落ちてしまうらしいですが、 夏のあいだにバジルは使い切れないほど生い茂る「らしい」ので、乾燥させれば冬も使えそう!!ww

LINUXでCLOUDWATCHのカスタムメトリクス導入

AWSのCloudwatchは標準で以下のものが見れます。 あ、CloudwatchってAWSモニタリングサービスです。

CPU使用率 ・ディスクI/O量・回数 ・ネットワーク情報量 ・状態 ってことで、デフォルトにはディスク使用率やメモリがないんですね。 なので手動で設定する必要があります。

以下が、設定方法です。

 

Amazon Linux にログインして、以下のコマンドを発行。

sudo yum install perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https

だだだっと流れた後に以下が出ればOKです!

Complete!

次に以下のコマンドでAmazon CloudWatch モニタリングスクリプトをダウンロードします。

wget http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip

 

これを解凍すると、ディレクトリが作成されるので、配置する場所で実施すれば良いです。

unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
cd aws-scripts-mon

以下のコマンドを発行してみましょう。--verifyついていると、お試し実行です。

./mon-put-instance-data.pl --disk-space-util --disk-path=/ <span style="color: #ff0000;">--verify</span> --verbose

これとか

Successfully reported metrics to CloudWatch. Reference Id: ~~~

とかでたならOK!

Verification completed successfully. No actual metrics sent to CloudWatch.

こうなるのはエラーです。

ちなみに、CentOSとかだと出たように記憶しています。

Digest/SHAがないよと怒られています。

 

Can't locate Digest/SHA.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . .) at AwsSignatureV4.pm line 23.
BEGIN failed--compilation aborted at AwsSignatureV4.pm line 23.
Compilation failed in require at CloudWatchClient.pm line 21.
BEGIN failed--compilation aborted at CloudWatchClient.pm line 21.
Compilation failed in require at ./mon-put-instance-data.pl line 86.
BEGIN failed--compilation aborted at ./mon-put-instance-data.pl line 86.

その時はこれ

sudo yum install -y perl-Digest-SHA

カスタムメトリクスは定期的にコマンド発行して、データをAWS上に格納していく必要があります。

クーロンを設定してみます。

crontab -e

以下を追加

*/5 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --disk-space-util --disk-path=/ --verbose
*/5 * * * * /home/centos/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/

うん、いい感じ!

アフェリエイトもちょっと始めてみました(笑) オフィシャルでちょくちょくお世話になっていますが、ここのクーポンはお得(^_^)

クラウドソーシング「ランサーズ」

AWS Cloudwatchのキャッシュ

AWSのCludwatchのカスタムメトリクスを使うためのmon-get-instance-stats.pl はキャッシュを作成して、それをインスタンスIDとしてデータをAWS上にputします。なので

インスタンス作成

→Cludwatch使う

インスタンスのAMI取得

インスタンス削除

→取得したAMIからインスタンスローンチ

すると、古いインスタンスIDでCludwatchにデータ収集されてしまいます。まぁ、それでドハマりしたんですけども。。。

 

/var/tmp/aws-mon配下にある、

instance-id

placement/availability-zone

aws configureに設定する内容が入っています。

こいつを削除すればOK。

cd /var/tmp
rm -rf aws-mon

AMIからAutoScalingするときとか、Cloudinitなんかで削除するとかしないとダメですね。

 

Apacheでhttpをhttpsにリダイレクトする。

いやー全く知らなかったもので恥ずかしいですが、

Apacheでhttpをhttpsにリダイレクトする必要があったので、記述。

以下のファイルを編集します。

vi /etc/httpd/conf/httpd.conf

それでもって、以下を追加します。

<ifModule mod_rewrite.c>
      RewriteEngine On
      LogLevel alert rewrite:trace3
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifModule>

AWSのCentOSのエラー対策

クラウドAWS

OS:CentOS 7

 

エラーの確認のためにコマンドを打ったら、エラーがずぉーっと出ていました。

egrep -i "warning|error" /var/log/messages

エラー①

rsyslogd-2307: warning: ~ action is deprecated, consider using the 'stop' statement instead [try http://www.rsyslog.com/e/2307 ]

エラー②

kernel: Error: Driver 'pcspkr' is already registered, aborting...

解決したので備忘録的に記述します。

エラー①の対策
vi /etc/rsyslog.d/21-cloudinit.conf

/21-cloudinit.confは名前から察するにクラウドイニットの設定ファイルだろうと思いますが

記述がCentOS7に対応していないっぽい。

# comment out the following line to allow CLOUDINIT messages through.
# Doing so means you'll also get CLOUDINIT messages in /var/log/syslog
&amp; ~

この~(チルダ)部分をstopに書き換えます。

# comment out the following line to allow CLOUDINIT messages through.
# Doing so means you'll also get CLOUDINIT messages in /var/log/syslog
&amp; stop
こう書き換える。OSを再起動したら出なくなりました。
エラー②の対策
どうやら同じ名前で、すでに読み込まれているのだとか。
なので重複している、pcspkrというモジュールを読み込まないようにします。
/etc/modprobe.d/配下に適当にファイルを設置して、
エラーにならないようにします。ディレクトリに移動してファイルを作成
vi avoiderror.list
で、以下を追加
blacklist pcspkr
そしたらOSリブートでエラーは表示されないはず。めでたしめでたし。

AWSのAmazonLinuxをローンチしたら最初にやること

AWSの恩恵をうけるうちの一つはCLIだと思います。

CLIを使って環境構築とか。

 

 

以下のコマンドを発行

aws configure

そうするとこんな感じに出てきます。

AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]:ap-northeast-1
Default output format [None]:json

アクセスキーと、シークレットキーはAWSを操作するための鍵みたいなもんですね

ROLEを使ってサーバーの権限を管理するほうが、個人的にはオススメです。

アクセスキーとシークレットキーが流出してしまうと大変な目にあいます。

 

ROLEについては別途記載を予定しますが、いつになることやら。。。