ラベル Linux の投稿を表示しています。 すべての投稿を表示
ラベル Linux の投稿を表示しています。 すべての投稿を表示

2012年8月12日日曜日

[MySQL]インストール後に最初に行うこと

■概要 公開サービスでのMySQL利用を想定している場合、MySQLのインストール後のセキュリティ設定は不適切です。 セキュリティを強化するための設定は、個別に行うことも可能ですが、「mysql_secure_installation」コマンドを利用すると、より簡便に設定可能です。

 ■mysql_secure_installationの実行 

mysql_secure_installationを実行すると以下の設定変更が可能です。

  1. rootパスワードの設定 
  2. rootユーザによるリモートアクセスの禁止 
  3. 匿名(anonymous)ユーザの削除 
  4. デフォルトで作成されているtestデータベースの削除
bash-3.2$ 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.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] Y ->初期パスワードなし
New password:         ->rootパスワードを変更するため[Y]を入力
Re-enter new password:     ->rootパスワードを変更するため[Y]を再入力
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 ->匿名ユーザを削除するため[Y]を入力
 ... 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ユーザのリモートアクセスを禁止するため[Y]を入力
 ... 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 ->testデータベースを削除するため[Y]を入力
 - Dropping test database...
ERROR 1010 (HY000) at line 1: Error dropping database (can't rmdir './test/', errno: 17)
 ... 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 ->新しい設定を即時反映するため[Y]を入力
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!



以上です。

2012年3月30日金曜日

[MySQL][CentOS]同一サーバに複数のMySQLをインストールする


■概要
既にMySQLがインストールされているサーバに、別プロジェクトで使用するMySQLを
インストールしたので、方法をまとめておきます。

今回はソースからインストールオプションを指定してインストールしました。

■基本情報
・OS
CentOS 5.5

・既存MySQLインストール情報
バージョン: MySQL-5.1

ベースディレクトリ: /usr/local/mysql/
データディレクトリ: /var/lib/mysql/
ポート : 3308
ソケット : /usr/local/mysql/tmp/mysql.sock
設定 : /var/lib/mysql/my.cnf


・新規MySQLインストール情報
バージョン: MySQL-5.5.22
ベースディレクトリ: /usr/mysql5/
データディレクトリ: /data/mysql5/
ポート : 3308
ソケット : /usr/mysql5/tmp/mysql.sock
設定 : /data/mysql5/my.cnf

■インストール手順
# cd /usr/local/src/

・インストールするソースをダウンロードする
# wget -P /usr/local/src 'http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.22.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/'
# tar xzvf ./mysql-5.5.22.tar.gz

※取得するバージョンは指定可能

・新規MySQL用のユーザ/グループを作成する
# groupadd mysql5
# useradd -g mysql5 mysql5

・新規MySQLインストール用ディレクトリを作成する
# mkdir /usr/mysql5/
# chown -R mysql5:mysql5 /usr/mysql5/
# ls -l /usr/mysql5/

・新規MySQLソケット作成用ディレクトリを作成する
# mkdir /usr/mysql5/tmp/
# chown -R mysql5:mysql5 /usr/mysql5/tmp/
# ls -l /usr/mysql5/tmp/

・DBデータ保存用ディレクトリを作成する
# mkdir -p /data/mysql5/
# chown -R mysql5:mysql5 /data/mysql5
# ls -l

・新規MySQLのソースをビルドする

※MySQL5.5以降のビルドはcmakeが必要となります。
cmakeがインストールされていない場合、以下サイト等を参考にインストールします。
http://www.atmarkit.co.jp/flinux/rensai/buildlamp/lamp_45/45_1.html

# cd /usr/local/src/mysql-5.5.22
# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/mysql5 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=true \
-DMYSQL_TCP_PORT=3308 \
-DMYSQL_UNIX_ADDR=/usr/mysql5/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql5/ \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_READLINE=ON

※cmakeのオプションはmysql.infoで確認しました。
# less /usr/local/src/mysql-5.5.22/Docs/mysql.info
「*MySQL Source-Configuration Option Reference (`CMake')*」の章を参照

※設定ファイル(my.cnf)の配置ディレクトリを指定したい場合は、「-DSYSCONFDIR=ディレクトリパス」オプションを付与します。
サーバ毎の設定ファイルのデフォルトは「DATADIR/my.cnf」となります。(グローバルの設定は/etc/my.cnfが使用されます)
設定ファイルの指定は、MySQLの起動オプションでも指定可能です。

・パスを通す
# vim /etc/profile
以下を記載
export PATH="$PATH:/usr/mysql5/bin"

# /usr/mysql5/scripts/mysql_install_db --user=mysql5 --basedir=/usr/mysql5 --datadir=/data/mysql5

・起動する
# /usr/mysql5/bin/mysqld_safe --user=mysql5 --defaults-file=/etc/my5.cnf &

・rootユーザのパスワードを変更する
# mysqladmin -u root password "xxxxxxxx"
# mysqladmin -u root -h localhost password "xxxxxxxx"

・ログインする
# /usr/mysql5/bin/mysql -uroot -p

・匿名ユーザを削除する
# DELETE FROM mysql.user WHERE Host='localhost' AND User='';
# FLUSH PRIVILEGES;

・停止する
# ./bin/mysqladmin -uroot -p shutdown


以上です。

2011年8月7日日曜日

[LAMP][CentOS]さくらVPSセットアップ

■概要
さくらVPSにLAMP環境を構築します。

■基本情報
OS   : CentOS 5(2011/8時点の最小構成)
ディスク: 20GB
メモリ : 512MB

■パッケージ確認
Apache、MySQL、PHPそれぞれのインストールパッケージを確認します。
# yum list | grep httpd
httpd.x86_64 2.2.3-45.el5.centos.1 updates
httpd-devel.i386 2.2.3-45.el5.centos.1 updates
httpd-devel.x86_64 2.2.3-45.el5.centos.1 updates
httpd-manual.x86_64 2.2.3-45.el5.centos.1 updates
system-config-httpd.noarch 5:1.3.3.3-1.el5 base

# yum list | grep mysql
apr-util-mysql.x86_64 1.2.7-11.el5_5.2 base
bytefx-data-mysql.x86_64 1.2.4-2.el5.centos extras
freeradius-mysql.x86_64 1.1.3-1.6.el5 base
freeradius2-mysql.x86_64 2.1.7-7.el5 base
libdbi-dbd-mysql.x86_64 0.8.1a-1.2.2 base
mod_auth_mysql.x86_64 1:3.0.0-3.2.el5_3 base
mysql.i386 5.0.77-4.el5_6.6 updates
mysql.x86_64 5.0.77-4.el5_6.6 updates
mysql-bench.x86_64 5.0.77-4.el5_6.6 updates
mysql-connector-odbc.x86_64 3.51.26r1127-1.el5 base
mysql-devel.i386 5.0.77-4.el5_6.6 updates
mysql-devel.x86_64 5.0.77-4.el5_6.6 updates
mysql-server.x86_64 5.0.77-4.el5_6.6 updates
mysql-test.x86_64 5.0.77-4.el5_6.6 updates
pdns-backend-mysql.x86_64 2.9.21-4.el5.centos extras
php-mysql.x86_64 5.1.6-27.el5_5.3 base
php-pear-MDB2-Driver-mysql.noarch 1.4.1-3.el5.centos extras
php53-mysql.x86_64 5.3.3-1.el5_6.1 updates
qt4-mysql.x86_64 4.2.1-1 base
rsyslog-mysql.x86_64 3.22.1-3.el5_6.1 updates

# yum list | grep php
php.x86_64 5.1.6-27.el5_5.3 base
php-bcmath.x86_64 5.1.6-27.el5_5.3 base
php-cli.x86_64 5.1.6-27.el5_5.3 base
php-common.x86_64 5.1.6-27.el5_5.3 base
php-dba.x86_64 5.1.6-27.el5_5.3 base
php-dbase.x86_64 5.1.6-15.el5.centos.1 extras
php-devel.x86_64 5.1.6-27.el5_5.3 base
php-gd.x86_64 5.1.6-27.el5_5.3 base
php-imap.x86_64 5.1.6-27.el5_5.3 base
php-ldap.x86_64 5.1.6-27.el5_5.3 base
php-mbstring.x86_64 5.1.6-27.el5_5.3 base
php-mcrypt.x86_64 5.1.6-15.el5.centos.1 extras
php-mhash.x86_64 5.1.6-15.el5.centos.1 extras
php-mssql.x86_64 5.1.6-15.el5.centos.1 extras
php-mysql.x86_64 5.1.6-27.el5_5.3 base
php-ncurses.x86_64 5.1.6-27.el5_5.3 base
php-odbc.x86_64 5.1.6-27.el5_5.3 base
php-pdo.x86_64 5.1.6-27.el5_5.3 base
php-pear.noarch 1:1.4.9-6.el5 base
php-pear-Auth-SASL.noarch 1.0.2-4.el5.centos extras
php-pear-DB.noarch 1.7.13-1.el5.centos extras
php-pear-Date.noarch 1.4.7-2.el5.centos extras
php-pear-File.noarch 1.2.2-1.el5.centos extras
php-pear-HTTP-Request.noarch 1.4.2-1.el5.centos extras
php-pear-Log.noarch 1.9.13-1.el5.centos extras
php-pear-MDB2.noarch 2.4.1-2.el5.centos extras
php-pear-MDB2-Driver-mysql.noarch 1.4.1-3.el5.centos extras
php-pear-Mail.noarch 1.1.14-1.el5.centos extras
php-pear-Mail-Mime.noarch 1.4.0-1.el5.centos extras
php-pear-Net-SMTP.noarch 1.2.10-1.el5.centos extras
php-pear-Net-Sieve.noarch 1.1.5-2.el5.centos extras
php-pear-Net-Socket.noarch 1.0.8-1.el5.centos extras
php-pear-Net-URL.noarch 1.0.15-1.el5.centos extras
php-pecl-Fileinfo.x86_64 1.0.4-3.el5.centos extras
php-pecl-memcache.x86_64 2.2.3-1.el5_2 extras
php-pgsql.x86_64 5.1.6-27.el5_5.3 base
php-readline.x86_64 5.1.6-15.el5.centos.1 extras
php-snmp.x86_64 5.1.6-27.el5_5.3 base
php-soap.x86_64 5.1.6-27.el5_5.3 base
php-tidy.x86_64 5.1.6-15.el5.centos.1 extras
php-xml.x86_64 5.1.6-27.el5_5.3 base
php-xmlrpc.x86_64 5.1.6-27.el5_5.3 base
php53.x86_64 5.3.3-1.el5_6.1 updates
php53-bcmath.x86_64 5.3.3-1.el5_6.1 updates
php53-cli.x86_64 5.3.3-1.el5_6.1 updates
php53-common.x86_64 5.3.3-1.el5_6.1 updates
php53-dba.x86_64 5.3.3-1.el5_6.1 updates
php53-devel.x86_64 5.3.3-1.el5_6.1 updates
php53-gd.x86_64 5.3.3-1.el5_6.1 updates
php53-imap.x86_64 5.3.3-1.el5_6.1 updates
php53-intl.x86_64 5.3.3-1.el5_6.1 updates
php53-ldap.x86_64 5.3.3-1.el5_6.1 updates
php53-mbstring.x86_64 5.3.3-1.el5_6.1 updates
php53-mysql.x86_64 5.3.3-1.el5_6.1 updates
php53-odbc.x86_64 5.3.3-1.el5_6.1 updates
php53-pdo.x86_64 5.3.3-1.el5_6.1 updates
php53-pgsql.x86_64 5.3.3-1.el5_6.1 updates
php53-process.x86_64 5.3.3-1.el5_6.1 updates
php53-pspell.x86_64 5.3.3-1.el5_6.1 updates
php53-snmp.x86_64 5.3.3-1.el5_6.1 updates
php53-soap.x86_64 5.3.3-1.el5_6.1 updates
php53-xml.x86_64 5.3.3-1.el5_6.1 updates
php53-xmlrpc.x86_64 5.3.3-1.el5_6.1 updates

Apache2.2系、MySQL5.0系、PHP5.1系がインストール可能です。

■Apache
# yum -y install httpd
# httpd -v
Server version: Apache/2.2.3
Server built: May 4 2011 06:51:15

■MySQL

今回、MySQLは5.5系、PHPは5.3系をインストールしたい為、サードパーティのリポジトリを指定してインストールします。

リポジトリの登録
# rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# yum --enablerepo=remi install mysql mysql-server

MySQLサーバ起動
# /etc/rc.d/init.d/mysqld start
MySQL Daemon failed to start.
Starting mysqld: [FAILED]

失敗する。ログを確認してみる。
# cat /var/log/mysqld.log
110807 20:03:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
110807 20:03:29 [ERROR] Error message file '/usr/share/mysql/english/errmsg.sys' had only 480 error messages,
but it should contain at least 712 error messages.
Check that the above file is the right version for this program!
110807 20:03:29 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Unknown error 1146
110807 20:03:29 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110807 20:03:29 InnoDB: The InnoDB memory heap is disabled
110807 20:03:29 InnoDB: Mutexes and rw_locks use GCC atomic builtins
110807 20:03:29 InnoDB: Compressed tables use zlib 1.2.3
110807 20:03:29 InnoDB: Using Linux native AIO
110807 20:03:29 InnoDB: Initializing buffer pool, size = 128.0M
110807 20:03:29 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
110807 20:03:29 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
110807 20:03:30 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
110807 20:03:30 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
110807 20:03:31 InnoDB: Waiting for the background threads to start
110807 20:03:32 InnoDB: 1.1.8 started; log sequence number 0
110807 20:03:32 [ERROR] Aborting

110807 20:03:32 InnoDB: Starting shutdown...
110807 20:03:33 InnoDB: Shutdown completed; log sequence number 1595675
110807 20:03:33 [Note]
110807 20:03:33 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

メッセージファイル(/usr/share/mysql/english/errmsg.sys)の競合が発生しているようです。

該当ファイルの競合を確認
# rpm -q --whatprovides /usr/share/mysql/english/errmsg.sys
mysql-libs-5.5.15-1.el5.remi
mysql-5.0.77-4.el5_6.6

2つのバージョンが競合していることが分かりました。現状のmysqlをいったん削除します。
# yum -y remove mysql mysql-server mysql-libs

明示的にバージョン指定
# yum --enablerepo=remi install mysql-server.x86_64
# yum --enablerepo=remi install mysql-devel.x86_64

# mysql_install_db

# /etc/rc.d/init.d/mysqld start

因みにMySQL5.5系ではmy.cnfに以下の設定を記述すると起動しない。innodbがデフォルトエンジンだからかも。 
設定内容:skip_innodb

■PHP
# yum install -y --enablerepo=remi php
# php -v
PHP 5.3.6 (cli) (built: May 16 2011 19:18:05)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

以上です。

2011年7月10日日曜日

[Linux][CentOS]新規ユーザを追加する

■概要
Linuxで新しくサーバを構築する際に、必ず実行する手順であるユーザの追加方法を
まとめます。

以下CentOSで作業しますが、bashが使える環境であれば同様のコマンドを
使用できます。

■ユーザ登録
セキュリティ上、rootユーザは使用しないポリシーとし、
新規ユーザに適切なsudo権限を付与する運用がベターです。

・新規ユーザ用グループを作成

※rootユーザで作業する

# groupadd appmng

・新規ユーザ作成
# useradd -g appmng appmng
# ls -l /home/
合計 4
drwx------ 2 appmng appmng 4096  7月  1 15:28 2011 appmng
⇒作成されていること

・新規ユーザのパスワードを変更する
# passwd appmng
ユーザー appmng のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: 全ての認証トークンが正しく更新できました。

・新規ユーザにsudo権限を付与します。
# cp -pi /etc/sudoers /etc/sudoers.YYYYMMDD
# vim /etc/sudoers
ppmng  ALL=(ALL)       ALL

・rootユーザでの作業を終了します。
# exit

・新規ユーザのログイン確認
$ ssh appmng@xxx.xxx.xxx.xxx
$ uname -n
⇒ホスト名が表示される
$ id
uid=500(appmng) gid=500(appmng) 所属グループ=500(appmng)


以上です。

2011年2月9日水曜日

[cmd] wgetコマンドでhttpsリクエスト

wgetでhttpsリクエストを送るコマンドは以下の通り(良く使うオプションです)
wget -O file_name --header="header_name:header_value" "https://mail.google.com"

-O file_name 取得結果をファイルに保存します。
--header="header_name:header_value" httpヘッダを指定できます。複数使用可。
※wgetがSSL対応でコンパイルされている必要があります。

■HTTP関連のオプション
http://www.geocities.jp/fut_nis/html/wget-ja/HTTP-Options.html#HTTP-Options
■SSL関連のオプション
http://www.geocities.jp/fut_nis/html/wget-ja/HTTPS-_0028SSL_002fTLS_0029-Options.html


以上です。

2011年1月15日土曜日

[Linux][CentOS] yumの再インストール

yumの調子が悪くなったので、再インストールしました。
※具体的にはyum updateができなくなり、yum clean allも効果なしという状況でした。

まずは、環境情報を確認。

ホストネームを確認する
# uname -a
Linux localhost.localdomain 2.6.18-194.el5PAE #1 SMP Fri Apr 2 15:37:44 EDT 2010 i686 i686 i386 GNU/Linux

OSバージョンを確認する
# cat /etc/redhat-release
CentOS release 5.5 (Final)

rpmバージョンを確認する
# rpm -q rpm
rpm-4.4.2.3-18.el5

yum関連パッケージをアンインストール
# rpm -e --nodeps python-elementtree
# rpm -e --nodeps python-urlgrabber
# rpm -e --nodeps python-sqlite
# rpm -e --nodeps m2crypto
# rpm -e --nodeps rpm-python
# rpm -e --nodeps python-iniparse
# rpm -e --nodeps yum-metadata-parser
# rpm -e --nodeps yum yum-fastestmirror

再インストール用パッケージをダウンロード
# cd /usr/local/src
# mkdir yumrpm
# cd yumrpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/python-elementtree-1.2.6-5.i386.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/python-urlgrabber-3.1.0-5.el5.noarch.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/python-sqlite-1.1.7-1.2.1.i386.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/m2crypto-0.16-6.el5.6.i386.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/rpm-python-4.4.2.3-18.el5.i386.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/yum-3.2.22-26.el5.centos.noarch.rpm
# wget http://ftp.riken.jp/Linux/centos/5.5/os/i386/CentOS/yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm

yum関連パッケージを再インストール
# rpm -ivh python-elementtree-1.2.6-5.i386.rpm python-urlgrabber-3.1.0-5.el5.noarch.rpm python-sqlite-1.1.7-1.2.1.i386.rpm m2crypto-0.16-6.el5.6.i386.rpm rpm-python-4.4.2.3-18.el5.i386.rpm python-iniparse-0.2.3-4.el5.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm yum-3.2.22-26.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm
準備中...        ########################################### [100%]
1:yum-metadata-parser  ########################################### [ 11%]
2:rpm-python       ########################################### [ 22%]
3:m2crypto        ########################################### [ 33%]
4:python-sqlite     ########################################### [ 44%]
5:python-elementtree   ########################################### [ 56%]
6:python-urlgrabber   ########################################### [ 67%]
7:python-iniparse    ########################################### [ 78%]
8:yum-fastestmirror   ########################################### [ 89%]
9:yum          ########################################### [100%]

次のコマンドでエラーが出なければ完了
# yum list


以上です。

2010年3月14日日曜日

[Env] CentOSのセットアップ

MacのVMWare FusionにCentOSをインストールしました。

環境セットアップ情報を記録しておきます。

1.Apache&PHP
$ yum install -y php-mbstring

yumではインストールするパッケージに依存するパッケージもあわせてインストールされるため、php-mbstringを使用する際に必須となるApacheも自動的にインストールされる。






2.MySQL

$ yum -y install mysql-server // MySQLのサーバ
$ yum -y install mysql // MySQLのクライアント
$ yum -y install mysql-libs // MySQL関連のライブラリ
$ yum -y install mysql-devel // プログラムからMySQLへの接続に使用する







//状態を確認
$ service mysqld status
//起動
$ service mysqld start
//停止
$ service mysqld stop


以上です。

2010年1月8日金曜日

[Env] プロンプトの表示を変更する

LinuxやMacOSXでプロンプトの表示を変更したい場合があります。

ホームディレクトリ内の.bash_profile(ない場合は新規作成)に下記のように設定を加えることで実現できます。

export PS1=’[\u@\h \W]\$ ‘

[各種指定の意味]
\d 日付
\h ホスト名
\n 改行
\s シェルの名前
\t 時間
\u ユーザー名
\w ワークディレクトリ
\W ワークディレクトリのベース名
\# コマンド番号
\! ヒストリ番号
\$ 有効なUIDが0なら「#」、それ以外なら「$」
\nnn 8進数での文字コード
\\ バックスラッシュそのもの
\[ 非表示文字の開始
\] 非表示文字の終了


 /etc/bashrc,/etc/profileと,各ユーザーごとの.bash_rc,.bash_profileの間には,“呼び出し関係” がある。.bash_profileは,.bashrcを,.bashrcは,/etc/bashrcを読み出すようにあらかじめ指定されている。このため,あるユーザーがbashを起動すると,まず最初に全ユーザー共通の設定内容が適用され,そこに各ユーザーごとの個別の設定が上書きされる。
システムへのログイン時には,.bash_profileと/etc/profileが読み出される。その後,例えばGNOME端末などのシェルを起動するたびに,.bashrcが読み込まれる。しかし,.bash_profileは読み込まれない。従って,ログイン直後に1度だけ実行させたいプログラムは.bash_profileに記述するべきである。


引用元:http://itpro.nikkeibp.co.jp/article/Keyword/20070831/280849/

2009年12月21日月曜日

[cmd] gzipファイル展開せずに特定のファイルを取得する

仕事で使用したコマンドを記録しておきます。

$tar -tvf apache2.0.58.20091214.tar.gz

apache2.0.58.20091214/logs/

$tar -xvf apache2.0.58.20091214/logs/

$gunzip -c apache2.0.58.20091214.tar.gz | tar -xvf - apache2.0.58.20091214/logs/operation.log


$gunzip -c apache2.0.58.20091214.tar.gz | tar -xvf - apache2.0.58.20091214/logs/operation.log


以上です。

2009年10月21日水曜日

[Env] sarのインストール

sarを使用するにはsysstatパッケージをインストールする必要があります。

RedHatへのインストール(cat /etc/issueでバージョン確認)
# yum install sysstat (RHEL 5 以降)

# up2date -u sysstat? (RHEL 4, 3, 2.1 以前)

※パッケージをダウンロードしてインストールされたい場合は、下記 URL の情報をご参照ください。
http://www.sios.com/product/rhel/usersite/faq/faq4-36.html


sysstat パッケージは、インストール後に設定をするべき項目は特にない。

インストールをしますと、/etc/cron.d/sysstat による cron の設定が行われ、cron による自動実行により、情報が /var/log/sa/ 配下に保存される

収集したリソース情報のファイルは、デフォルトで 7日間分保存されます

デフォルトでは 7日間分のファイルが保存されるように設定されています。
この期間の設定は、/usr/lib/sa/sa2 スクリプト内の HISTORY 変数で定義されています。

# grep HISTORY /usr/lib/sa/sa2
HISTORY=7 <-------------------<修正する場合はここを変更します>
find /var/log/sa/ \( -name 'sar  -o -name 'sa  \) -mtime +"$HISTORY"
-exec rm -f {} \;

インストール作業録
cat /etc/issue
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
Kernel \r on an \m

yum install sysstat

インストールエラー
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
No package sysstat available.
Nothing to do

ネットワークに繋がっていないから
http://www.sios.com/product/rhel/usersite/faq/faq4-36.htmlからパッケージをダウンロードする

ネットにパッケージがない
rpmfind sysstat
1) rpm -ivh  -- 新規インストール
(2) rpm -Uvh  -- アップデート or 新規インストール
(3) rpm -Fvh   -- アップデートのみ
(4) rpm -e?? <パッケージ名>   -- 削除
パッケージダウンロード
http://pagesperso-orange.fr/sebastien.godard/download.htm

rpm -ivh sysstat-9.0.5-1.i586.rpm
エラー: 依存性の欠如:
libc.so.6(GLIBC_2.7) は sysstat-9.0.5-1.i586 に必要とされています
rpmlib(FileDigests) <= 4.6.0-1 は sysstat-9.0.5-1.i586 に必要とされています block 4096byte * block数 l


以上です。

2009年10月15日木曜日

[Env] Linux Alias設定について

エイリアスは,ログイン時に,bashが起動され,その過程で設定されます。
※ 各ユーザのログインシェルは /etc/passwd に書かれています。

rootにログインすると,以下の順でスクリプトが実行されます。

・/etc/profile を実行

・/etc/profile.d/*.sh を実行

・/root/.bash_profile を実行

・/root/.bashrc を実行

最後の.bashrcに「alias cp='cp -i'」というエイリアスが書かれています。

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

一般ユーザの.bashrcには,このエイリアスは書かれていないことから,

OSの制限として, ルート権限により,無制限にファイルコピー,削除ができないようになっていると思われます。

※一般ユーザにも制限を適用する場合は/etc/profile, /etc/bashrcに記述するか/etc/skelに記述してしまえば良いです。


以上です。