コンテンツへスキップ

[root@localhost system]# systemctl status postgresql-13.service
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since 水 2021-06-23 05:57:55 JST; 1h 9min ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 2260 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 2265 (postmaster)
   CGroup: /system.slice/postgresql-13.service
           tq2265 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/data
           tq2269 postgres: checkpointer
           tq2270 postgres: background writer
           tq2271 postgres: walwriter
           tq2272 postgres: autovacuum launcher
           tq2273 postgres: stats collector
           mq2274 postgres: logical replication launcher

 6月 23 05:57:54 localhost.localdomain systemd[1]: Starting PostgreSQL 13 database server...
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.031 JST [2265] LOG:  PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.…しています
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.034 JST [2265] LOG:  IPv6アドレス"::1"、ポート5432で待ち受けています
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.034 JST [2265] LOG:  IPv4アドレス"127.0.0.1"、ポート5432で待ち受けています
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.035 JST [2265] LOG:  Unixソケット"/var/run/postgresql/.s.PGSQL.5432"で待ち受けています
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.037 JST [2265] LOG:  Unixソケット"/tmp/.s.PGSQL.5432"で待ち受けています
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.041 JST [2268] LOG:  データベースシステムは 2021-06-23 05:57:44 JST にシャットダウンしました
 6月 23 05:57:55 localhost.localdomain postmaster[2265]: 2021-06-23 05:57:55.045 JST [2265] LOG:  データベースシステムの接続受け付け準備が整いました
 6月 23 05:57:55 localhost.localdomain systemd[1]: Started PostgreSQL 13 database server.
Hint: Some lines were ellipsized, use -l to show in full.
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  It is recommended to use systemd
# "dropin" feature;  i.e. create file with suffix .conf under
# /etc/systemd/system/postgresql-13.service.d directory overriding the
# unit's defaults. You can also use "systemctl edit postgresql-13"
# Look at systemd.unit(5) manual page for more info.

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-13-setup.
[Unit]
Description=PostgreSQL 13 database server
Documentation=https://www.postgresql.org/docs/13/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
#Environment=PGDATA=/var/lib/pgsql/13/data/
Environment=PGDATA=/var/lib/pgsql/data

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-13/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT


# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

[Install]
WantedBy=multi-user.target

 

ファイル

root@localhost myProject]# tree
.
|-- ansible.cfg
|-- group_vars
|   `-- db.yml
|-- hosts
|-- roles
|   |-- postgresql
|   |   |-- defaults
|   |   |   `-- main.yml
|   |   |-- handlers
|   |   |   `-- main.yml
|   |   |-- tasks
|   |   |   |-- configurations.yml
|   |   |   |-- createDbCluster.yml
|   |   |   |-- main.yml
|   |   |   |-- packages.yml
|   |   |   `-- services.yml
|   |   `-- templates
|   |       `-- postgresql.conf.j2
|   `-- test1
|       `-- tasks
|           |-- hashTest.yml
|           `-- main.yml
`-- site.yml

9 directories, 14 files

db.yml

[root@localhost myProject]# more group_vars/db.yml
---
postgresql_version: "12"

dbs:
  db1:
    dataDirectory: /var/lib/pgsql/data1
    port: 5432
  db2:
    dataDirectory: /var/lib/pgsql/data2
    port: 5433

task

[root@localhost myProject]# more roles/test1/tasks/main.yml
- name: "hash test"
  import_tasks: hashTest.yml
[root@localhost myProject]# more roles/test1/tasks/hashTest.yml
---
- name: "print dict"
  #debug:
  #  var: item
  file: path={{ item.value.dataDirectory }} state=directory owner=root group=root mode=0755
  with_dict: "{{ dbs }}"

実行結果

[root@localhost myProject]# ansible-playbook -i ./hosts site.yml
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.exceptions import InvalidSignature

PLAY [db] *********************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************
ok: [localhost]

TASK [test1 : print dict] *****************************************************************************************************************************************************
changed: [localhost] => (item={u'key': u'db1', u'value': {u'dataDirectory': u'/var/lib/pgsql/data1', u'port': 5432}})
changed: [localhost] => (item={u'key': u'db2', u'value': {u'dataDirectory': u'/var/lib/pgsql/data2', u'port': 5433}})

PLAY RECAP ********************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

$e = New-Object -ComObject Excel.Application
$e.Visible = $true
$book  = $e.Workbooks.Add()
$sheet = $book.Worksheets.Item(1)
$sheet.Cells.Item(7,3) = "実線"

# ------< 実線 >----------
$sheet.cells.item(7.3).borders.LineStyle = 1 #実線
#$sheet.cells.item(7,3).borders.Weight = 2    # 線の太さ

# 列幅を自動調整する
$range = $sheet.usedRange
$range.EntireColumn.AutoFit() | out-null

# セルの結合
$c1 = $sheet.Cells(2,3)
$c2 = $sheet.Cells(2,4)
$sheet.range($c1,$c2).mergeCells = 1
$sheet.cells.item(2,3).borders.Weight = 2    # 線の太さ
$sheet.cells.item(2,4).borders.Weight = 2    # 線の太さ

# Excelを閉じる
$e.Quit()
# プロセスを解放する
$e = $null
[GC]::Collect()

 

他のブックのシートをコピーする。

$file1 = 'E:\my-document\エクセル\template.xlsx' # source's fullpath
$file2 = 'E:\my-document\エクセル\Test05.xlsx' # destination's fullpath
$xl = new-object -c excel.application
$xl.displayAlerts = $false # don't prompt the user
$xl.visible = $true
$workBook1 = $xl.workbooks.open($file1, $null, $true) # open source, readonly
#$workBook2 = $xl.workbooks.open($file2) # open target

# 新しいbookを作成
$workBook2 = $xl.Workbooks.Add() # index1に追加される

# コピーするシートをセット
$sheetToCopy = $workBook1.sheets.item('テンプレートシート') # source sheet to copy

#シート名アレイ
$sheetLists = ("サーバ1","サーバ2","サーバ3")

$i = 1
foreach($sheetName in $sheetLists) {
    $sh1_wb2 = $workBook2.sheets.item($i)
    $sheetToCopy.copy($sh1_wb2)
    $workBook2.WorkSheets.item("テンプレートシート").name = [string]$sheetName
    $i++
}

# ブック作成時にデフォルトで作成されるシートを削除
$workBook2.WorkSheets.item("Sheet1").delete()
$workBook2.WorkSheets.item("Sheet2").delete()
$workBook2.WorkSheets.item("Sheet3").delete()

$workBook1.close($false) # 保存なし
$workBook2.SaveAs($file2)
#$workBook2.close($true) # 保存あり
$xl.quit()
$xl = $null
[gc]::Collect()

 

testinfra サンプル

$ more test_service2.py
import pytest

@pytest.mark.parametrize("name,version", [
    ("httpd","2.2.5"),
    ("python", "2.9"),
])

def test_packages(host, name, version):
    pkg = host.package(name)
    assert pkg.is_installed
    assert pkg.version.startsith(version)

@pytest.mark.parametrize("name", [
    ("httpd"),
    ("chronyd"),
])
def test_service(host, name):
    service = host.service(name)
    assert service.is_running

実行結果

$ py.test -v ./test_service2.py
/usr/local/lib/python3.6/site-packages/testinfra-6.0.0-py3.6.egg/_testinfra_renamed.py:10: DeprecationWarning: testinfra package has been renamed to pytest-testinfra. Please `pip install pytest-testinfra` and `pip uninstall testinfra` and update your package requirements to avoid this message
============================================================================= test session starts =============================================================================
platform linux -- Python 3.6.8, pytest-6.2.4, py-1.10.0, pluggy-1.0.0.dev0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/user1
plugins: testinfra-6.0.0, testinfra-6.3.0
collected 4 items

test_service2.py::test_packages[local-httpd-2.2.5] PASSED                                                                                                               [ 25%]
test_service2.py::test_packages[local-python-2.9] PASSED                                                                                                                [ 50%]
test_service2.py::test_service[local-httpd] PASSED                                                                                                                      [ 75%]
test_service2.py::test_service[local-chronyd] PASSED                                                                                                                    [100%]

============================================================================== 4 passed in 0.68s ==============================================================================

 

$oldSystemPath = [System.Environment]::GetEnvironmentVariable("path","Machine")
$newSystemPath = $oldSystemPath + ";" + <追加したいパス>
[System.Environment]::SetenvironmentVariable("Path",$newSystemPath,"Machine")

パスの確認

[System.Environment]::GetEnvironmentVariable("path","Machine") -split ";"

# 1Mバイトのファイルを作成
@(1..10) | Foreach{
    $random_bin = new-object byte[] (1024*1024); (new-object Random).NextBytes($random_bin); [IO.File]::WriteAllBytes("c:\tmp\test$_.dat", $random_bin)
}
# 最終更新日が任意のファイルを作成
for($i=0;$i -le 90;$i++){
    $file = $i.tostring() + ".log"
    $filepath = (join-path D:\log $file)
    new-item $filepath |out-null
    $j = "-" + $i
    Set-ItemProperty $filepath -Name LastWriteTime -Value (get-date).addDays($j) 
}

 

$a=@(3,2,1,5,4,8)
$b=@(4,2,3,1,5,6)
Compare-Object ($a|sort-object) ($b|sort-object) -IncludeEqual | foreach-object {
    $direction = $_.SideIndicator
    $value = $_.InputObject
    if( $direction -eq "<="){
        write-host("aにだけあり[{0}]" -f $value)
    } elseif ( $direction -eq "=>"){
        write-host("bにだけあり[{0}]" -f $value)
    } else {
        write-host("aとbにあり[{0}]" -f $value)
    }
}

 

compmgmt.msc:コンピュータの管理
devmgmt.msc :デバイスマネージャ
diskmgmt.msc:ディスクの管理
eventvwr.msc:イベントビューア
fsmgmt.msc :共有フォルダ
gpedit.msc :グループポリシー
lusrmgr.msc :ローカルユーザーとグループ
perfmon.msc :パフォーマンス
rsop.msc :ポリシーの結果セット
services.msc:サービス
secpol.msc :ローカルセキュリティ設定