Monthly Archives: 10月 2016

Linuxでtelenetのインストールとmemcachedの状態を調べる方法

1.telenetをインストール
#yum install telnet-server
#yum install telnet
#vi /etc/xinetd.d/telnet

service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = yes
}

xinetd起動
#/etc/init.d/xinetd restart

memcached起動
#/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -u root

2.状態の確認
#echo stats | nc localhost 10210
#ps -ef|grep memcached

memcached停止
#kill -9 pid

# telnet 127.0.0.1 10210
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
stats

3.操作コマンド
STAT pid 12362
STAT uptime 1469315
STAT time 1339671194
STAT version 1.4.9
STAT libevent 1.4.9-stable
STAT pointer_size 64
STAT rusage_user 3695.485200
STAT rusage_system 14751.273465
STAT curr_connections 69
STAT total_connections 855430
STAT connection_structures 74
STAT reserved_fds 20
STAT cmd_get 328806688
STAT cmd_set 75441133
STAT cmd_flush 34
STAT cmd_touch 0
STAT get_hits 253547177
STAT get_misses 75259511
STAT delete_misses 4
STAT delete_hits 565730
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 545701515844
STAT bytes_written 1649639749866
STAT limit_maxbytes 2147483648
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 14
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 30705763
STAT evicted_unfetched 0
STAT bytes 61380700
STAT curr_items 28786
STAT total_items 75441133
STAT evictions 0
STAT reclaimed 39957976
END

MySQLでストアドプロシージャのみバックアップする方法

1.ストアドプロシージャとデータベース
mysqldump –opt -R -uusername -p kddbname >kddbname.sql

2.ストアドプロシージャ
mysqldump –skip-opt -t -d -R -uusername -p kddbname >kdsp_dbname.sql

パラメータ説明
-d: –no-data
-t: –no-create-info
-R: –routines

SQLServerでテーブルの作成、データ挿入、PROCEDUREの作成操作方法

1.テーブルを作成(table create)
CREATE TABLE employee(
id INTEGER NOT NULL PRIMARY KEY,
first_name VARCHAR(10),
last_name VARCHAR(10),
salary DECIMAL(10,2),
start_Date DATETIME,
region VARCHAR(10),
city VARCHAR(20),
managerid INTEGER
);
2.データの挿入(insert)
1> INSERT INTO employee VALUES (1, ‘二郎’ , ‘山田’, 20,’2015-03-22′,’関東’,’川崎’,3);
2> GO

(1 rows affected)
1> INSERT INTO employee VALUES (2, ‘太郎’, ‘佐藤’,30,’2013-07-21′,’西日本’,’福岡’,4);
2> GO

(1 rows affected)
1> INSERT INTO employee VALUES (3, ‘太郎’ , ‘金沢’, 40,’2011-12-01′,’関東’,’埼玉’,5);
2> GO

(1 rows affected)
1> INSERT INTO employee VALUES (4, ‘太郎’ , ‘鈴木’, 50,’2016-03-03′,’西日本’,’東京’,6);
2> GO

(1 rows affected)
3.テーブルのクエリー(select)
select * from employee;

4.ストアド プロシージャの作成
CREATE PROCEDURE InstOrUpdateTran
@FirstName nVarChar(50),
@LastName nVarChar(25),
@Salary Money
AS
IF EXISTS(SELECT * From Employee Where First_name = @FirstName)
UPDATE Employee SET Last_NAME = @LastName, Salary = @Salary
WHERE First_name = @FirstName
ELSE
INSERT INTO Employee (ID,First_Name, Last_Name, Salary)
SELECT 99, @FirstName, @LastName, @Salary
5.テーブルの削除
drop table employee;

SQL Serverで日付と時刻をフォーマットする方法

DECLARE @dt datetime
SET @dt=GETDATE()

1.yyyy-m-d
SELECT REPLACE(CONVERT(varchar(10),@dt,120),N’-0′,’-‘)
  
2.yyyy年mm月dd日
方法1
SELECT STUFF(STUFF(CONVERT(char(8),@dt,112),5,0,N’年’),8,0,N’月’)+N’日’

方法2
SELECT DATENAME(Year,@dt)+N’年’+DATENAME(Month,@dt)+N’月’+DATENAME(Day,@dt)+N’日’

3.yyyy年m月d日
SELECT DATENAME(Year,@dt)+N’年’+CAST(DATEPART(Month,@dt) AS varchar)+N’月’+DATENAME(Day,@dt)+N’日’
4.yyyy-mm-dd hh:mi:ss:mmm
SELECT CONVERT(char(11),@dt,120)+CONVERT(char(12),@dt,114)

MySQLにFROM_UNIXTIMEとUNIX_TIMESTAMP()の使い方

1.FROM_UNIXTIME()
UNIX タイムスタンプを日付として書式設定します
例文
SELECT FROM_UNIXTIME( time, ‘%Y-%m-%d’ ) AS time
FROM table

2.UNIX_TIMESTAMP()
UNIX タイムスタンプを返します
例文
SELECT UNIX_TIMESTAMP( ‘2016-07-04’ )

phpクラスでconstとdefineを使って定数を定義する方法

phpコード例1
<?php
define(“STUDYPHP”,”startnews24″);
class CftConstDemo
{
const constant = ‘constant value’;

function showConstant() {
echo self::constant . “<br>”;
}
}

echo CftConstDemo::constant . “<br>”;

$classname = “CftConstDemo”;
echo $classname::constant . “<br>”;

$class = new CftConstDemo();
$class->showConstant();
echo $class::constant.”<br>”;
//print_r(get_defined_constants());
?>

phpコード例2
<?php
if(1){
const a = ‘java’;
}
echo a; //NG
?>

phpコード例3
<?php
const FOO = ‘STUDYPHP’;

for ($i = 0; $i < 32; ++$i) {
define(‘STUDYPHP_’ . $i, 1 << $i);
}
?>

phpコード例4
<?php
const PHP = 2 << 6; // NG
define(‘PHP’, 2 << 6); // OK
?>

php入門–file_get_contents()とcurl関数でコンテンツを取得する

1.file_get_contents
<?php
$url = “http://www.xxx.com”;
$contents = file_get_contents($url);

//$getcontent = iconv(“shift-jis”, “utf-8”,$contents);
echo $contents;
?>
2.fopen->fread->fclose
<?php
$handle = fopen (“http://www.xxx.com”, “rb”);
$contents = “”;
do {
$data = fread($handle, 1024);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while(true);
fclose ($handle);
echo $contents;
?>
3.curl
<?php
$url = “http://www.xxx.com”;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.”:”.US_PWD);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
?>

ディスクIO性能評価ツールmongoperfの使い方

1.mongoperf
–help, -h
Returns information on the options and use of mongoperf.

<jsonconfig>
mongoperf accepts configuration options in the form of a file that holds a JSON document. You must stream the content of this file into mongoperf, as in the following operation:

2.mongoperf < config
In this example config is the name of a file that holds a JSON document that resembles the following example:

{
nThreads:<n>,
fileSizeMB:<n>,
sleepMicros:<n>,
mmf:<bool>,
r:<bool>,
w:<bool>,
recSizeKB:<n>,
syncDelay:<n>
}

3.Configuration Fields
mongoperf.nThreads
Type: Integer.

Default: 1

Defines the number of threads mongoperf will use in the test. To saturate your system’s storage system you will need multiple threads. Consider setting nThreads to 16.

mongoperf.fileSizeMB
Type: Integer.

Default: 1 megabyte (i.e. 10242 bytes)

Test file size.

詳細内容 こちら

Macでdjangoをインストールする方法

pipのアップグレード
sudo pip install –upgrade pip

djangoのインストール
sudo pip install Django

インストール結果を確認
python -c “import django; print(django.__path__)”

djangoバージョンを確認
python -m django –version

LinuxでOS環境情報とミドルウェアバージョンを調べるコマンド

Ubuntu

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION=”Ubuntu 14.04.4 LTS”
CentOS

$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
Java
$ java -version
java version “1.8.0_91”
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
Maven
$ mvn -v
Node.js
$ node -v

NPM
$ npm -v

$ ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]

Nginx
$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)
Httpd (Apache)

$ httpd -v
Server version: Apache/2.4.16 (Unix)
Server built: Jul 31 2015 15:53:26
MongoDB

$ mongod –version

$ mongo –version
MongoDB shell version: 3.2.3
OpenSSH

$ ssh -V
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6, OpenSSL 1.0.1f 6 Jan 2014
cURL

$ curl –version

Git
$ git –version
git version 2.5.4 (Apple Git-61)
Bash

$ bash –version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.
Zsh

2 / 3123