java.lang.System.currentTimeMillis()のサンプル

Javaコード
package sample;
import java.sql.Timestamp;
public class TimeStamapDemo {
public static void main(String[] args) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); System.out.println(“現在時刻:\n”  +   timestamp);
}
}

結果
現在時刻:
2018-02-15 14:11:15.034

「Java入門」System.arraycopy()のサンプル

Javaコード
package com.arkgame.study;
import java.util.Arrays;

public class ArraycopyDemo {

public static void main(String[] args) {
int[] ctn = { 12, 24, 56, 78, 51 };
System.out.println(Arrays.toString(ctn));
System.arraycopy(ctn, 0, ctn, 3, 2);
System.out.println(Arrays.toString(ctn));

int[] ctn2 = new int[6];
System.arraycopy(ctn, 1, ctn2, 0, 3);
System.out.println(Arrays.toString(ctn2));

try {
System.arraycopy(ctn, 0, ctn2, 0, ctn.length + 1);
} catch (IndexOutOfBoundsException ex) {

System.out.println(“occur IndexOutOfBoundsException “);
}
System.out.println(Arrays.toString(ctn2));
}

}
実行結果
[12, 24, 56, 78, 51]
[12, 24, 56, 12, 24]
[24, 56, 12, 0, 0, 0]
occur IndexOutOfBoundsException
[24, 56, 12, 0, 0, 0]

「Oracle入門」コマンドexpdp/impdpの実行方法

1.DIRECTORYオブジェクトの作成
CREATE DIRECTORY ディレクトリオブジェクト名 AS ‘OSのディレクトリ(絶対パス)’;
SQL構文:
CREATE OR REPLACE DIRECTORY DUMPDIR AS ‘/HOME/ORACLE/DUMPDIR’;

2.expdpの実行
SQL構文:
EXPDP SYSTEM/MANAGER@TEST DIRECTORY=DUMPDIR DUMPFILE=INFO_CFT.DUMP SCHEMAS=INFO_CFT LOGFILE=INFO_CFT_DUMP.LOG

3.impdpの実行
SQL構文:
impdp system/manager@test directory=dumpdir dumpfile=info_cft.dump schemas=info_cft logfile=info_cft_dump.log

CentOS7にL2TP1.3.6/ipsec3.15 vpn環境を構築するメモ

1.依存パッケージをインストール
#yum install -y make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof vim-enhanced man
#yum install xl2tpd
#yum install libreswan

2.ipsec.confの設定
#cat /etc/ipsec.conf
config setup
protostack=netkey
dumpdir=/var/run/pluto/
nat_traversal=yes
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v4:100.64.0.0/10,%v6:fd00::/8,%v6:fe80::/10
conn L2TP-PSK-NAT
rightsubnet=vhost:%priv
also=L2TP-PSK-noNAT
conn L2TP-PSK-noNAT
authby=secret
pfs=no
auto=add
keyingtries=3
dpddelay=30
dpdtimeout=120
dpdaction=clear
rekey=no
ikelifetime=8h
keylife=1h
type=transport
left=xxx.xxx.xxx.xxx
#xxx.xxx.xxx.xxx
leftprotoport=17/1701
right=%any
rightprotoport=17/%any

3.l2tp_psk.confを作成
#vi /etc/ipsec.d/l2tp_psk.conf
conn L2TP-PSK-NAT
rightsubnet=vhost:%priv
also=L2TP-PSK-noNAT
conn L2TP-PSK-noNAT
authby=secret
pfs=no
auto=add
keyingtries=3
dpddelay=30
dpdtimeout=120
dpdaction=clear
rekey=no
ikelifetime=8h
keylife=1h
type=transport
left=xxx.xxx.xxx.xxx
#xxx.xxx.xxx.xxx
leftprotoport=17/1701
right=%any
rightprotoport=17/%any

4.ipsec.secretsの作成
# cat /etc/ipsec.secrets
#include /etc/ipsec.d/*.secrets
xxx.xxx.xxx.xxx %any: PSK “123456789”
#xxx.xxx.xxx.xxx

5.sysctl.confの修正
# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.ip_forward = 1
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.accept_source_route = 0

#sysctl -p

6.ipsecのチェック
# ipsec setup start
# ipsec verify

Verifying installed system and configuration files

Version check and ipsec on-path [OK]
Libreswan 3.15 (netkey) on 3.10.0-514.el7.x86_64
Checking for IPsec support in kernel [OK]
NETKEY: Testing XFRM related proc values
ICMP default/send_redirects [OK]
ICMP default/accept_redirects [OK]
XFRM larval drop [OK]
Pluto ipsec.conf syntax [OK]
Hardware random device [N/A]
Two or more interfaces found, checking IP forwarding [OK]
Checking rp_filter [ENABLED]
/proc/sys/net/ipv4/conf/ens160/rp_filter [ENABLED]
/proc/sys/net/ipv4/conf/ens192/rp_filter [ENABLED]
rp_filter is not fully aware of IPsec and should be disabled
Checking that pluto is running [OK]
Pluto listening for IKE on udp 500 [OK]
Pluto listening for IKE/NAT-T on udp 4500 [OK]
Pluto ipsec.secret syntax [OK]
Checking ‘ip’ command [OK]
Checking ‘iptables’ command [OK]
Checking ‘prelink’ command does not interfere with FIPSChecking for obsolete ipsec.conf options [OK]
Opportunistic Encryption [DISABLED]

ipsec verify: encountered 5 errors – see ‘man ipsec_verify’ for help

7.ipsecを起動
# systemctl start ipsec
# systemctl enable ipsec

8.xl2tpd.confを修正
# cat /etc/xl2tpd/xl2tpd.conf
[global]
listen-addr = xxx.xxx.xxx.xxx
ipsec saref = yes
[lns default]
ip range = 192.168.1.128-192.168.1.254
local ip = 192.168.1.99
require chap = yes
refuse pap = yes
require authentication = yes
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

9.options.xl2tpdの修正
# cat /etc/ppp/options.xl2tpd
require-mschap-v2
ipcp-accept-local
ipcp-accept-remote
#dns
ms-dns xxx.xxx.88.10
ms-dns xxx.xxx.1.10
#ms-dns 8.8.8.8
ipcp-accept-local
ipcp-accept-remote
noccp
auth
crtscts
idle 1800
mtu 1410
mru 1410
nodefaultroute
debug
lock
proxyarp
connect-delay 5000

10.xl2tpdに接続するユーザを作成
# cat /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
lancer * 123 *
#ログインユーザとパスワード

11.xl2tpdの起動
# systemctl start xl2tpd
# systemctl status xl2tpd

「MariaDB入門」GRANT/REVOKEで権限を設定するメモ

1.データベース権限の追加
GRANT 権限 ON dbname.* TO ‘username’@’hostname’;

GRANT SELECT, INSERT ON USERINFO_SSDB.* TO ‘system_manager’@’172.17.2.100’;

2.テーブル権限の追加
GRANT 権限 ON dbname.テーブル名 TO ‘username’@’hostname’;

GRANT SELECT, INSERT ON USERINFO_SSDB.STUDENT_TBL TO ‘system_manager’@’172.17.2.100’;

3.カラム権限の追加
GRANT 権限 (column_name) ON dbname.テーブル名 TO ‘username’@’hostname’;

GRANT SELECT (COL1), INSERT (COL1,COL2) ON USERINFO_SSDB.STUDENT_TBL TO ‘system_manager’@’172.17.2.100’;

4.ユーザーの権限の追加
SHOW GRANTS FOR ‘username’@’hostname’;

SHOW GRANTS FOR ‘system_manager’@’172.17.2.100’;

5.権限の削除
REVOKE 権限 ON 権限レベル FROM ‘username’@’hostname’;

REVOKE select ON USERINFO_SSDB.STUDENT_TBL FROM ‘system_manager’@’172.17.2.100’;

CentOS 7.3にMariaDB10.2.8をインストールするメモ

インストールコマンド
#tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local
#cd /usr/local
#ln -s mariadb-10.2.8-linux-x86_64.tar.gz/ mysql

設定ファイルの作成
#cd /usr/local/mysql/support-files
#mkdir /etc/mysql/
#cp my-huge.cnf /etc/mysql/my.cnf /
#vim /etc/mysql/my.cnf
[mysqld]
datadir = /app/mysqldb
innodb_file_per_table = on
skip_name_resolve = on

dbファイルの作成
#cd /usr/local/mysql/
#scripts/mysql_install_db –user=mysql –datadir=/app/mysqldb
#ls /app/mysqldb

logファイルの作成
#mkdir /var/log/mariadb/
#chown mysql /var/log/mariadb/

サービス起動
#cp support-files/mysql.server /etc/init.d/mysqld
#chkconfig –add mysqld
#service mysqld start
#ss -nutl

PATH環境変数を設定
#vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:$PATH
# . /etc/profile.d/mysql.sh

mysqlセキュリティスクリプトの実行
#cd /usr/local/mysql
#mysql_secure_installation

#mysql -uroot -ppassword

「python入門」readline()でファイルを読み込む方法

pythonコード
f = open(“demo.txt”)
line = f.readline()
while line:
print line,
# print(line, end = ”)
line = f.readline()

f.close()

「jquery入門」val().change()の使い方

例1
$(‘#userForm’).find(‘input[type=”text”]’).val(‘yamada’).change();

例2
$(“#cftLoginTime”).change(function(){
//処理コード
});
例3
$(“input”).val(“yamada”).change();

Ubuntuにnginxをインストールするメモ

PGPキーを追加
wget http://nginx.org/keys/nginx_signing.key -O – | sudo apt-key add –

リポジトリを追加
/etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/ubuntu/ CODENAME nginx
deb-src http://nginx.org/packages/ubuntu/ CODENAME nginx

nginxをインストール
sudo apt update
sudo apt install nginx

UbuntuにJDK8をインストールするメモ

インストール
#sudo add-apt-repository ppa:webupd8team/java
#sudo apt update
#sudo apt install oracle-java8-installer
バージョンの確認
#java -version
#javac -version