■
def get_weekdays_for_subject(subject):
weekdays = []
with open("input/timetable.csv",encoding="utf-8") as f:
for row in f:
colums = row.rstrip().split(",")
day = colums[0]
if row.find(subject) >= 0:
weekdays.append(day)
return weekdays
def main():
subject = '理科'
weekdays = get_weekdays_for_subject(subject)
print("「{}」は{}にあります".format(subject,",".join(weekdays)))
if __name__ == '__main__':
main()
----------------
def count_subjects():
pass
s_count = {}
with open('input/timetable.csv', encoding='utf-8') as f:
for row in f:
columns = row.rstrip().split(",")
day = columns[0]
for col in columns:
if col != day:
if col in s_count.keys():
s_count[col] += 1
else:
s_count[col] = 1
return s_count
def main():
subject_counts = count_subjects()
for subject, count in subject_counts.items():
pass
print('{}は{}回'.format(subject, count))
if __name__ == '__main__':
main()
----------------------
def replace_subject(row, week_day, p_sub, a_sub):
pass
if row.startswith(week_day):
return row.replace(p_sub, a_sub, 1)
else:
return row
def main():
with open('input/timetable.csv', encoding='utf-8') as f:
for row in f:
new_row = replace_subject(row, '月曜日', '体育', 'ダンス')
print(new_row, end='')
if __name__ == '__main__':
main()
月曜日,国語,算数,社会,体育,体育
火曜日,算数,外国語,理科,国語,音楽
水曜日,体育,社会,家庭,国語,算数
木曜日,国語,図画工作,理科,算数,国語
金曜日,算数,社会,体育,理科,生活
Openstack
・Openstack サーバ環境
# yum install -y https://repos.fedorapeople.org/repos/openstack/openstack-juno/rdo-release-juno-1.noarch.rpm # yum install -y openstack-packstack # yum install -y qemu-kvm # ssh-keygen -t rsa # packstack --gen-answer=param.txt # systemctl stop NetworkManager # systemctl disable NetworkManager ※Openstack のネットワークが動作するシステムでは NetworkManager は動作しないこと、と警告が出た。 # systemctl stop ntpd ※chrony が動作しているから、停止する必要があるらしい # packstack --answer-file=param.txt
・Openstack クライアント環境 (RHEL7)
1.パッケージのインストール # yum install -y https://repos.fedorapeople.org/repos/openstack/openstack-juno/rdo-release-juno-1.noarch.rpm # yum install -y epel-release # yum install -y bash-completion python-novaclient python-neutronclient python-glanceclient python-cinderclient python-swiftclient python-keystoneclient python-openstackclient 2.oepnrc の作成 ※Openstack サーバ環境の /root/keystonerc_admin を流用 # source openrc # nova keypair-add key-temporary > key-temporary.pem # chmod 600 key-temporary.pem
OpenLDAP サーバ
・OpenLDAP サーバの基本的な設定
1.以下のパッケージの導入
openldap openldap-clients openldap-servers
2.Berkeley DB のパフォーマンスチューニング用のファイル作成
# cp -rp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
3./root/slapd.conf の作成
# cp -rp /usr/share/openldap-servers/slapd.conf.obsolete /root/slapd.conf
4./root/slapd.conf に追記
database config
access to *
by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
by * none
database bdb
suffix "dc=example,dc=com"
checkpoint 1024 15
rootdn "cn=Manager,dc=example,dc=com"
rootpw {SSHA}HjIlhOG0qV8+sVbL40ND5UnODaaEm50h5.設定ファイルの削除
# rm -fr /etc/openldap/slapd.d/* # echo "" |slapadd -f /root/slapd.conf
6.slapd.conf を変換
# slaptest -f /root/slapd.conf -F /etc/openldap/slapd.d/
7.ディレクトリの権限変更
# chown -R ldap:ldap /etc/openldap/slapd.d/ # chmod -R u+rwX /etc/openldap/slapd.d/ # chown -R ldap:ldap /var/lib/ldap/
8./etc/sysconfig/ldap ファイルに ldapi サポートの確認
SLAPD_LDAPI=yes
9.slapd の起動
# service slapd status # chkconfig slapd on
※参考情報
http://qiita.com/mykysyk@github/items/25e6adbfdb313afaf339
http://www.openldap.org/doc/admin24/index.html
http://www5f.biglobe.ne.jp/~inachi/openldap/admin23/index-ja.html
・cn=config へのアクセス
# ldapsearch -Y EXTERNAL -H ldapi:/// -b "cn=config"
・cn=config の rootpw の設定追加
# cat test
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}NtFL4k34N3FHDdr5kXFdfpPFVGCPJ8Cn
# ldapmodify -Y EXTERNAL -H ldapi:/// -f test
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={0}config,cn=config"
#※参考情報
https://mowa-net.jp/wiki/LDAP
・OpenLDAP クライアントの基本的な設定 (nslcd の場合)
1.以下のパッケージの導入
nscd nss-pam-ldapd pam_ldap
2./etc/sysconfig/authconfig の編集
#yes に変更 FORCELEGACY=yes
3.authconfig の実行
# authconfig --enableldap --enableldapauth --ldapserver=192.168.110.135 --ldapbasedn="dc=example,dc=com" --enablemkhomedir --update # chkconfig nslcd on
・エントリの追加
# cat test.ldif
dn: dc=example,dc=com
objectClass: top
objectClass: domain
dc: example
dn: ou=Group,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: Group
dn: ou=People,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: People
#
# ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f test.ldif
Enter LDAP Password:
adding new entry "dc=example,dc=com"
adding new entry "ou=Group,dc=example,dc=com"
adding new entry "ou=People,dc=example,dc=com"
# cat user.ldif
dn: uid=luser1,ou=People,dc=example,dc=com
givenName: ldap
sn: user1
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetorgperson
objectClass: posixAccount
uid:luser1
cn:ldap user1
homeDirectory: /home/luser1
userPassword: {SSHA}NtFL4k34N3FHDdr5kXFdfpPFVGCPJ8Cn
dn: cn=lgroup1,ou=Group,dc=example,dc=com
objectClass: posixGroup
objectClass: top
cn: lgroup1
gidNumber: 1001
# ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f user.ldif
Enter LDAP Password:
adding new entry "uid=luser1,ou=People,dc=example,dc=com"
adding new entry "cn=lgroup1,ou=Group,dc=example,dc=com"
#
zabbix
Documentation
http://www.zabbix.com/download.php
2.2
https://www.zabbix.com/documentation/2.2/jp/manual/installation/install_from_packages
2.0
https://www.zabbix.com/documentation/2.0/jp/manual/installation/install_from_packages
1.8
http://www.zabbix.jp/documents/installation/install-rpm
https://www.scsk.jp/lib/product/oss/pdf/oss_16.pdf
●zabbix サーバ
1.パッケージのインストール
# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
# yum -y install zabbix-server-mysql zabbix-web-mysql
# yum -y install mysql-server
※場合よっては、以下。
# yum -y install httpd mysql-server php php-mysql
2./etc/my.cnf の編集
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
[mysqld]
default-character-set=utf8
skip-character-set-client-handshake
innodb_file_per_table
innodb_buffer_pool_size=64M
innodb_log_file_size=16M
innodb_log_files_in_group=2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
※MySQL5.5 で、default-character-set → character-set-server になったらしい。
http://kennyqi.com/archives/334.html
3.MySQL の起動
# service mysqld start
# chkconfig mysqld on
4.DB の構築
zabbix データベースとユーザーを作成
# mysql -uroot
psql> create database zabbix character set utf8 collate utf8_bin;
psql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
psql> flush privileges;
psql> quit;
初期スキーマとデータをインポートします。
# cd /usr/share/doc/zabbix-server-mysql-2.4.5/create/
# mysql -uroot zabbix < schema.sql
# mysql -uroot zabbix < images.sql
# mysql -uroot zabbix < data.sql
5.Zabbix サーバプロセスの開始
# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password
# service zabbix-server start
# chkconfig zabbix-server on
/etc/php.ini を変更
date.timezone = Asia/Tokyo
7.httpd プロセスの開始
# service httpd start
# chkconfig httpd on
8.Web インタフェースのインストール
以下を参照してインストール
http://blog.torigoya.net/2012/03/10/centos6-zabbix/
http://www.letsplay-network.info/zabbix-24/
https://blog.apar.jp/linux/334/
インストール後、Adimin/zabbix でログイン。
●zabbix エージェント
1.zabbix パッケージのインストール
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum -y install zabbix-agent
2./etc/zabbix/zabbix_agentd.conf の編集
Server=192.168.11.18★zabbix サーバ
Hostname=HTTP01.testdomain1zabbix エージェントのホスト名
ListenIP=192.168.11.19★zabbix エージェントが listen する IP アドレス
※zabbix サーバの場合は、本項は不要
3.
# service zabbix-agent restart
# chkconfig zabbix-agent on
https://blog.apar.jp/linux/334/
http://blog.torigoya.net/2012/03/10/centos6-zabbix/
http://comp.senseofwonder.org/2009/05/200905291334.html
https://blog.apar.jp/zabbix/1081/
http://changineer.info/server/monitoring/monitoring_zabbix.html
●Zabbix の Web Interface 日本語化
http://katzplus.com/centos-6/zabbix/zabbix-%E3%81%AE-web-interface-%E6%97%A5%E6%9C%AC%E8%AA%9E%E5%8C%96/
http://www.slideshare.net/zembutsu/is-the-order-an-automation-of-operation-and-monitoring
http://pocketstudio.jp/log3/2014/04/29/spoke_at_zabbix_jp_6th/
https://gist.github.com/zembutsu/7640108
http://knowledge.sakura.ad.jp/tech/2406/
DNS サーバの構築 (マスター、スレーブ)
環境は以下の通り。
mas:RHEL61.example.com (192.168.110.135) sla:RHEL66.example.com (192.168.110.136)
・マスター・サーバ/スレーブ・サーバ
1./etc/sysconfig/named の編集
#IPv6 の無効 OPTIONS="-4"
・マスター・サーバ
1.named.conf (/var/named/chroot/etc/named.conf) の編集
acl local-net {
10.0.1.1;
192.168.110.0/24;
};
options
{
directory "/var/named";
#rndc によるダンプ情報のファイル
dump-file "data/cache_dump.db";
#rndc によるステータス情報のファイル
statistics-file "data/named_stats.txt";
#rndc によるメモリ情報のファイル
memstatistics-file "data/named_mem_stats.txt";
#BIND がクライアントからのクエリを受け取るport と NIC を指定
listen-on port 53 { 127.0.0.1; 192.168.110.135;};
#listen-on-v6 port 53 { ::1; };
#クエリが出来るクライアントを指定
allow-query { local-net; };
#キャッシュされた情報に対するクエリが出来るクライアントを指定
allow-query-cache { local-net; };
#再帰的なサーバーとして動作するかどうかを指定
recursion yes;
#DNSSEC を無効
dnssec-enable no;
dnssec-validation no;
dnssec-lookaside no;
};
logging
{
channel default_debug {
file "data/named.log" versions 3 size 10m;
severity dynamic;
print-time yes;
print-severity yes;
print-category yes;
};
#クエリ情報を queries.log に出力
channel "log_queries" {
file "data/queries.log" versions 3 size 10m;
severity info;
print-time yes;
print-severity yes;
print-category yes;
};
category queries { "log_queries"; };
};
view "internal"
{
match-clients { local-net; };
recursion yes;
zone "." IN {
type hint;
file "/var/named/named.ca";
};
include "/etc/named.rfc1912.zones";
zone "example.com" {
type master;
file "example.com.db";
#ゾーン転送要求を許可するスレーブサーバの IP アドレス指定 (192.168.110.136)
#自身からの dig の axfr を許可するため自身の IP アドレス指定 (192.168.110.135)
allow-transfer { 192.168.110.136; 192.168.110.135;};
#ゾーン情報に変更が加えられた際に他のネームサーバに変更を通知
notify yes;
#notify が yes の場合、通知先となるサーバの IP アドレスを指定
also-notify { 192.168.110.136; };
};
zone "110.168.192.in-addr.arpa" {
type master;
file "192.168.110.0.local.rev";
#ゾーン転送要求を許可するスレーブサーバの IP アドレス指定 (192.168.110.136)
#自身に対して dig の axfr を許可するため自身の IP アドレス指定 (192.168.110.135)
allow-transfer { 192.168.110.136; 192.168.110.135;};
#ゾーン情報に変更が加えられた際に他のネームサーバに変更を通知
notify yes;
#notify が yes の場合、通知先となるサーバの IP アドレスを指定
also-notify { 192.168.110.136; };
};
};
2.ゾーンファイルの編集
/var/named/chroot/var/named/example.com.db の編集。
$ttl 38400
@ IN SOA RHEL61.example.com. root.RHEL61.example.com. (
0000000001
10800
3600
604800
38400 )
IN NS RHEL61.example.com.
RHEL61.example.com. IN A 192.168.110.135
RHEL66.example.com. IN A 192.168.110.136
RHEL61.example.com.→RHEL61.example.com となる
^
RHEL61.example.com →RHEL61.example.com.example.com となる
^
/var/named/chroot/var/named/192.168.110.0.local.rev の編集。
$ttl 38400
@ IN SOA RHEL61.example.com. root.RHEL61.example.com. (
0000000001
10800
3600
604800
38400 )
IN NS RHEL61.example.com.
135 IN PTR RHEL61.example.com.
136 IN PTR RHEL66.example.com.※以下でゾーン情報をダンプして確認可能
# rndc dumpdb -zones # cat /var/named/chroot/var/named/data/cache_dump.db
・スレーブ・サーバ
1.named.conf (/var/named/chroot/etc/named.conf) の編集
acl local-net {
10.0.1.1;
192.168.110.0/24;
};
options
{
directory "/var/named";
#rndc によるダンプ情報のファイル
dump-file "data/cache_dump.db";
#rndc によるステータス情報のファイル
statistics-file "data/named_stats.txt";
#rndc によるメモリ情報のファイル
memstatistics-file "data/named_mem_stats.txt";
#BIND がクライアントからのクエリを受け取るport と NIC を指定
listen-on port 53 { 127.0.0.1; 192.168.110.136;};
#listen-on-v6 port 53 { ::1; };
#クエリが出来るクライアントを指定
allow-query { local-net; };
#キャッシュされた情報に対するクエリが出来るクライアントを指定
allow-query-cache { local-net; };
#再帰的なサーバーとして動作するかどうかを指定
recursion yes;
#DNSSEC を無効
dnssec-enable no;
dnssec-validation no;
dnssec-lookaside no;
};
logging
{
channel default_debug {
file "data/named.log" versions 3 size 10m;
severity dynamic;
print-time yes;
print-severity yes;
print-category yes;
};
#クエリ情報を queries.log に出力
channel "log_queries" {
file "data/queries.log" versions 3 size 10m;
severity info;
print-time yes;
print-severity yes;
print-category yes;
};
category queries { "log_queries"; };
};
view "internal"
{
match-clients { local-net; };
recursion yes;
zone "." IN {
type hint;
file "/var/named/named.ca";
};
include "/etc/named.rfc1912.zones";
zone "example.com" {
type slave;
file "slaves/example.com.db";
#マスターサーバの IP アドレス指定 (192.168.110.135)
masters { 192.168.110.135; };
};
zone "110.168.192.in-addr.arpa" {
type slave;
file "slaves/192.168.110.0.local.rev";
#マスターサーバの IP アドレス指定 (192.168.110.135)
masters { 192.168.110.135; };
};
};※参考情報
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html-single/Deployment_Guide/index.html
14.2. BIND
https://lists.openshift.redhat.com/docs/manuals/enterprise/RHEL-5-manual/ja-JP/Deployment_Guide/s2-bind-introduction-bind.htm
http://www.atmarkit.co.jp/flinux/index/indexfiles/bind9index.html
https://www.suse.com/ja-jp/documentation/sles10/book_sle_reference/data/cha.dns.htmll
http://www.eis.co.jp/category/dns_bind/
http://www.maruko2.com/mw/rndc%E3%81%A7named%E3%82%92%E3%82%B3%E3%83%B3%E3%83%88%E3%83%AD%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B
独自の yum リポジトリを作成
1.createrepo パッケージを導入。
# yum install createrepo
# mkdir /mnt/local_repo/
3.上記のディレクトリに rpm パッケージを格納し以下のコマンド。
# createrepo --database /mnt/local_repo
4.yum リポジトリのファイルを /etc/yum.repos.d に作成。
あとは、yum コマンドを実行。
※/etc/yum.repos.d/original.repo として以下を作成。
[local-myrepository] name=My repository baseurl=file:///mnt/local_repo gpgcheck=0 enabled=1
※該当のリポジトリを更新する場合は以下のコマンド
# createrepo -update /mnt/local_repo
1.先に作成したディレクトリを httpd で公開するディレクトリに移動。
mv /mnt/local_repo /var/www/html/
2.createrepo をコマンドを実行し、httpd を再起動。
createrepo --database /var/www/html/local_repo
3.該当の yum リポジトリのファイルを /etc/yum.repos.d に作成。
あとは、yum コマンドを実行。
[local-myrepository] name=My repository baseurl=http://192.168.110.135/local_repo gpgcheck=0 enabled=1
※参考 URL
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html-single/Deployment_Guide/index.html#ch-yum
第6章 Yum
http://zokibayashi.hatenablog.com/entry/2015/04/24/074048
https://access.redhat.com/ja/node/395763
http://blog.asial.co.jp/319
http://momijiame.tumblr.com/post/87789692026/%E8%87%AA%E5%88%86%E7%94%A8%E3%81%AE-yum-%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%82%92%E4%BD%9C%E3%82%8B
http://knowledge.sakura.ad.jp/tech/1086/
・利用可能なリポジトリ ID を一覧表示 (enabled、disabled 含む)
# yum repolist all
・利用可能なリポジトリ ID を一覧表示 (enabled のみ)
# yum repolist :: リポジトリー ID リポジトリー名 状態 base CentOS-6 - Base 6,518 extras CentOS-6 - Extras 38 updates CentOS-6 - Updates 1,370 repolist: 7,926
・特定のリポジトリを enable、disable
# yum-config-manager --enable <リポジトリ ID > # # yum-config-manager --enable base # # yum-config-manager --disable <リポジトリ ID > # # yum-config-manager --disable base
・一括で disable
# yum-config-manager --disable
鍵ベース認証による ssh 接続
・鍵ベース認証による ssh 接続
※鍵はユーザーごとに別々に生成する必要がある
1.接続元
# ssh-keygen -t rsa ★鍵作成 (RSA) Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase):★Enterキーのみでも可。ここでパスフレーズを入力した場合は ssh 接続でパスフレーズを入力することになる Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 0b:f5:3c:b2:74:d4:27:00:3c:41:45:f6:21:a4:4c:88 root@RHEL66.example.com The key's randomart image is: +--[ RSA 2048]----+ | . +=*B . | | E .ooo = . | | +.. + . | | . + o | | . S = | | o = . | | o | | | | | +-----------------+ # # chmod 700 ~/.ssh ★権限変更
2.接続先
# ssh-keygen -t rsa ★鍵作成 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 95:0c:67:81:da:a2:b6:60:9e:fd:19:b3:22:34:bc:a6 root@RHEL61.example.com The key's randomart image is: +--[ RSA 2048]----+ | ..+. | | .= . | | o + | | o .. | | . . .S | | * o | | + B .o | | * + = | |Eo . o+ | +-----------------+ # # chmod 700 ~/.ssh ★権限変更
3.接続元
# scp .ssh/id_rsa.pub xxx.xxx.xxx.xxx:/root/.ssh/authorized_keys The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established. RSA key fingerprint is 1b:5e:46:6b:df:d8:f1:17:84:a7:a2:98:b6:c5:fc:9d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'xxx.xxx.xxx.xxx' (RSA) to the list of known hosts. root@xxx.xxx.xxx.xxx's password: id_rsa.pub 100% 405 0.4KB/s 00:00
4.接続先
# chmod 600 .ssh/authorized_keys
あとは ssh コマンドで接続するだけ。
・パスワード認証を無効化
パスワード認証を無効化し、鍵ベース認証のみにする場合は、
/etc/ssh/sshd_config に以下を設定し、sshd サービスを再起動する。
PasswordAuthentication no
・パスフレーズの削除
# ssh-keygen -p -P <古いパスフレーズ> -N <古いパスフレーズ> -f /root/.ssh/id_rsa
※参考情報
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html-single/Deployment_Guide/index.html
→第12章 OpenSSH
http://www.atmarkit.co.jp/ait/articles/1503/20/news007.html