ギャバンITサービス
お菓子の家が作れるシステムエンジニアです

サービスの操作

systemctl配下で動くサービス一覧 # systemctl list-units 自分用サービスユニットファイル例 1 2 3 4 5 6 7 8 9 10 11 12 # cat /etc/systemd/system/gvis.service [Unit] Description = gvis daemon [Service] ExecStart = /gvis/script/000_serviceStart.sh Restart = no Type = simple [Install] WantedBy = multi-user.target サービス開始例 # systemctl start docker.service サービス停止例 # systemctl stop docker.service サービス有効化例 # systemctl enable gvis.service サービス無効化例 # systemctl disable gvis.service サービス有効かどうか確認 # systemctl is-enable xrdp

rcloneでgoogle drive活用

google driveの自分の利用領域へlinuxのフォルダを同期コピーさせる。 rcloneというのはコマンドラインのことで、google drive以外にもawsとかazureとか同期処理ができるらしい。 性能はcyberduckのコピーよりもかなり速い(cyberduckは検算もしてるし丁寧ではあるが・・・)。 手元PCの中に100GBのzipファイルが2つ3つあったとして、9:00に初めたら昼には終わる。 Google Cloudの中からだったらもっと速い。転送レートはローカルの2.5~3倍は出る。 いつか壊れるバックアップ置き場をローカルで数TB確保するより、壊れないし速いしずっといい。 rcloneのインストールとmanの展開 curlで取ってきて/usr/binに展開しmandbに追加 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 $ cd $ mkdir rclone $ cd rclone $ curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 12.3M 100 12.3M 0 0 8717k 0 0:00:01 0:00:01 --:--:-- 8717k $ ls rclone-current-linux-amd64.zip $ unzip rclone-current-linux-amd64.zip Archive: rclone-current-linux-amd64.zip creating: rclone-v1.53.3-linux-amd64/ inflating: rclone-v1.53.3-linux-amd64/README.html inflating: rclone-v1.53.3-linux-amd64/rclone.1 inflating: rclone-v1.53.3-linux-amd64/rclone inflating: rclone-v1.53.3-linux-amd64/README.txt inflating: rclone-v1.53.3-linux-amd64/git-log.txt $ ls rclone-current-linux-amd64.zip rclone-v1.53.3-linux-amd64 $ cd rclone-v1.53.3-linux-amd64/ $ ls git-log.txt rclone rclone.1 README.html README.txt $ ls -l total 40200 -rw-r--r-- 1 nari docker 1935 Nov 20 02:13 git-log.txt -rwxr-xr-x 1 nari docker 37654528 Nov 20 02:15 rclone -rw-r--r-- 1 nari docker 1177819 Nov 20 02:04 rclone.1 -rw-r--r-- 1 nari docker 1282524 Nov 20 02:04 README.html -rw-r--r-- 1 nari docker 1037677 Nov 20 02:04 README.txt $ sudo cp rclone -p /usr/bin/ $ sudo chown root:root /usr/bin/rclone $ sudo chmod 755 /usr/bin/rclone $ mkdir -p /usr/local/share/man/man1 $ sudo cp rclone.1 /usr/local/share/man/ $ sudo mandb $ rclone version rclone v1.53.3 - os/arch: linux/amd64 - go version: go1.15.5 $ rcloneするosユーザの作成 googleアカウントとdriveは事前に作っておく。 ここではgvisDriveとして識別させてる。 ...

 ⭐️

gitの基礎

ホンマの最初はgitlabが動くvmを作ったけど、普段はgoogle cloudのdockerコンテナでgitlab動かして使ってる。 djangoのソースやドキュメントを維持するために使ってるんやけど、最初の頃にgit操作勉強したときのメモ。 クローンからブランチ作成まで勉強させてもらった。 参考URL クローン git clone (URL.git) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 nari@nariUbun18:~/Desktop$ git clone http://nawhlinux.intra.gavann-it.com:10080/naritomi/memos.git Cloning into 'memos'... remote: Enumerating objects: 1258, done. remote: Counting objects: 100% (1258/1258), done. remote: Compressing objects: 100% (939/939), done. remote: Total 1258 (delta 269), reused 1256 (delta 268) Receiving objects: 100% (1258/1258), 814.57 MiB | 20.89 MiB/s, done. Resolving deltas: 100% (269/269), done. Checking out files: 100% (1092/1092), done. nari@nariUbun18:~/Desktop$ ls memos nari@nariUbun18:~/Desktop$ cd memos/ nari@nariUbun18:~/Desktop/memos$ ls 01_URL_ショートカット集 09_linuxノウハウ 16_KVMノウハウ 23_git 02_windowsノウハウ 10_VBAノウハウ 17_xamppノウハウ 24_AWS 03_dotnetノウハウ 11_電話ノウハウ 18_oracleノウハウ 25_GoogleCloud 05_vmwareノウハウ 12_LANノウハウ 19_c 26_docker 06_奉行ノウハウ 13_全銀手順 20_routerノウハウ README.md 07_hyperV-VirtualPCノウハウ 14_メール 21_teratadaノウハウ 08_terastationノウハウ 15_MySQLノウハウ 22_SQLノウハウ nari@nariUbun18:~/Desktop/memos$ ブランチ一覧確認とブランチ切り替え git branch -a git checkout -b (branch name)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 nari@nariUbun18:~/Desktop/memos$ git branch -a * master remotes/origin/20190923 remotes/origin/2nd remotes/origin/HEAD -> origin/master remotes/origin/master nari@nariUbun18:~/Desktop/memos$ git checkout -b 20190926 Switched to a new branch '20190926' nari@nariUbun18:~/Desktop/memos$ git branch -a * 20190926 master remotes/origin/20190923 remotes/origin/2nd remotes/origin/HEAD -> origin/master remotes/origin/master nari@nariUbun18:~/Desktop/memos$ gitログの確認 git log –oneline 1 2 3 4 5 6 7 nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ git log --oneline 316450c (origin/master, origin/HEAD, master) Merge branch '20190923' into 'master' c401f18 (origin/20190923) 1)ノウハウを追加 a4c6680 (origin/2nd) 追記してコミット 35ff8ff Ubuntu setup1 c553dc1 Add README.md nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ ファイル/フォルダを追加 git add (folder or filename)) 1 2 3 4 5 6 7 8 9 nari@nariUbun18:~/Desktop/memos$ cd 23_git/ nari@nariUbun18:~/Desktop/memos/23_git$ ls -l 合計 6556 drwxr-xr-x 3 nari nari 4096 9月 26 04:35 git -rw-r--r-- 1 nari nari 6704532 9月 26 04:35 git.zip drwxrwxr-x 2 nari nari 4096 9月 26 04:50 gitCommand nari@nariUbun18:~/Desktop/memos/23_git$ nari@nariUbun18:~/Desktop/memos/23_git$ git add gitCommand nari@nariUbun18:~/Desktop/memos/23_git$ ファイル/フォルダを削除 git rm (folder or filename) ブランチをコミット git commit -a -m “任意のコメント” 1 2 3 4 5 nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ git commit -a -m "gitコマンドの追記" [20190926 afd002e] gitコマンドの追記 1 file changed, 73 insertions(+) create mode 100644 23_git/gitCommand/gitCommand.txt nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ コミットのコメントを修正 git commit –amend -m “任意のコメント” 1 2 3 4 5 6 7 8 9 10 11 12 13 nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ git commit --amend -m "GITコマンドの追記" [20190926 505c6b3] GITコマンドの追記 Date: Thu Sep 26 05:06:13 2019 +0900 1 file changed, 73 insertions(+) create mode 100644 23_git/gitCommand/gitCommand.txt nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ git log --oneline 505c6b3 (HEAD -> 20190926) GITコマンドの追記 316450c (origin/master, origin/HEAD, master) Merge branch '20190923' into 'master' c401f18 (origin/20190923) 1)ノウハウを追加 a4c6680 (origin/2nd) 追記してコミット 35ff8ff Ubuntu setup1 c553dc1 Add README.md nari@nariUbun18:~/Desktop/memos/23_git/gitCommand$ コミットのコメント複数行を修正 git commit –amend ※専用エディタが起動する ...

gitlabのインストール

初めて環境作ったときのコマンドライン。 当時はvmwareでcentos7を立てて作ったけど、今はdockerコンテナで動いている。 インストール curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 [nari@linux4ruby ~]$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 6463 0 6463 0 0 7526 0 --:--:-- --:--:-- --:--:-- 7532[sudo] nari のパスワード: Detected operating system as centos/7. Checking for curl... Detected curl... Downloading repository file: https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/config_file.repo?os=centos&dist=7&source=script done. Installing pygpgme to verify GPG signatures... 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: ftp.jaist.ac.jp * extras: ftp.jaist.ac.jp * ius: mirrors.kernel.org * updates: ftp.jaist.ac.jp gitlab_gitlab-ce-source/signature | 836 B 00:00:00 https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey から鍵を取得中です。 Importing GPG key 0xE15E78F4: Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>" Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4 From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg から鍵を取得中です。 gitlab_gitlab-ce-source/signature | 951 B 00:00:00 !!! gitlab_gitlab-ce-source/primary | 175 B 00:00:01 パッケージ pygpgme-0.3-9.el7.x86_64 はインストール済みか最新バージョンです 何もしません Installing yum-utils... 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: mirrors.aliyun.com * extras: ftp.jaist.ac.jp * ius: mirrors.kernel.org * updates: ftp.jaist.ac.jp パッケージ yum-utils-1.1.31-46.el7_5.noarch はインストール済みか最新バージョンです 何もしません Generating yum cache for gitlab_gitlab-ce... Importing GPG key 0xE15E78F4: Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>" Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4 From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey The repository is setup! You can now install packages. [nari@linux4ruby ~]$ [nari@linux4ruby ~]$ sudo yum install gitlab-ce 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: ftp.jaist.ac.jp * extras: ftp.jaist.ac.jp * ius: mirrors.kernel.org * updates: ftp.jaist.ac.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ gitlab-ce.x86_64 0:11.4.4-ce.0.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================================================================== Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================================================================== インストール中: gitlab-ce x86_64 11.4.4-ce.0.el7 gitlab_gitlab-ce 435 M トランザクションの要約 ================================================================================================================================== インストール 1 パッケージ 総ダウンロード容量: 435 M インストール容量: 1.3 G Is this ok [y/d/N]: y Downloading packages: 警告: /var/cache/yum/x86_64/7/gitlab_gitlab-ce/packages/gitlab-ce-11.4.4-ce.0.el7.x86_64.rpm: ヘッダー V4 RSA/SHA1 Signature、鍵 ID f27eab47: NOKEY gitlab-ce-11.4.4-ce.0.el7.x86_64.rpm の公開鍵がインストールされていません gitlab-ce-11.4.4-ce.0.el7.x86_64.rpm | 435 MB 00:00:21 https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey から鍵を取得中です。 Importing GPG key 0xE15E78F4: Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>" Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4 From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey 上記の処理を行います。よろしいでしょうか? [y/N]y https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg から鍵を取得中です。 Importing GPG key 0xF27EAB47: Userid : "GitLab, Inc. <support@gitlab.com>" Fingerprint: dbef 8977 4ddb 9eb3 7d9f c3a0 3cfc f9ba f27e ab47 From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg 上記の処理を行います。よろしいでしょうか? [y/N]y Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : gitlab-ce-11.4.4-ce.0.el7.x86_64 1/1 It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md 検証中 : gitlab-ce-11.4.4-ce.0.el7.x86_64 1/1 インストール: gitlab-ce.x86_64 0:11.4.4-ce.0.el7 完了しました! [nari@linux4ruby ~]$ アクセスURLを指定 sudo cat /etc/gitlab/gitlab.rb | grep external_url 1 2 3 4 5 6 7 8 9 [nari@linux4ruby ~]$ sudo cat /etc/gitlab/gitlab.rb | grep external_url ##! For more details on configuring external_url see: #external_url 'http://gitlab.example.com' external_url 'http://192.168.1.87' # registry_external_url 'https://registry.gitlab.example.com' # pages_external_url "http://pages.example.com/" # gitlab_pages['artifacts_server_url'] = nil # Defaults to external_url + '/api/v4' # mattermost_external_url 'http://mattermost.example.com' [nari@linux4ruby ~]$ 初期設定 sudo gitlab-ctl reconfigure 1 2 3 4 5 6 7 8 9 [nari@linux4ruby ~]$ sudo gitlab-ctl reconfigure :(長いので省略) Running handlers: Running handlers complete Chef Client finished, 435/620 resources updated in 02 minutes 20 seconds gitlab Reconfigured! [nari@linux4ruby ~]$ gitのユーザ作成 groupadd gitgroup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 [root@linux4ruby ~]# groupadd gitgroup [root@linux4ruby ~]# useradd -g gitrgoup gituser useradd: グループ 'gitrgoup' は存在しません [root@linux4ruby ~]# useradd -g gitrgoup gitusergoup gituserroup gituser [root@linux4ruby ~]# [root@linux4ruby ~]# passwd gituser ユーザー gituser のパスワードを変更。 新しいパスワード: よくないパスワード: このパスワードは 8 未満の文字列です。 新しいパスワードを再入力してください: passwd: すべての認証トークンが正しく更新できました。 [root@linux4ruby ~]# cd / [root@linux4ruby /]# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var [root@linux4ruby /]# mkdir /git/-server [root@linux4ruby /]# chown gituser:gitgroup /git-server [root@linux4ruby /]# [root@linux4ruby /]# [root@linux4ruby /]# exit ログアウト [nari@linux4ruby git]$ sudo gituser [sudo] nari のパスワード: sudo: gituser: コマンドが見つかりません [nari@linux4ruby git]$ sudo gituser sudo: gituser: コマンドが見つかりません [nari@linux4ruby git]$ su - gituser パスワード: [gituser@linux4ruby ~]$ pwd /home/gituser [gituser@linux4ruby ~]$ cd /git-server/ [gituser@linux4ruby git-server]$ ls [gituser@linux4ruby git-server]$ mkdir sample1-rep.git [gituser@linux4ruby git-server]$ ls sample1-rep.git [gituser@linux4ruby git-server]$ [gituser@linux4ruby git-server]$ [gituser@linux4ruby git-server]$ ls sample1-rep.git [gituser@linux4ruby git-server]$ cd sample1-rep.git/ [gituser@linux4ruby sample1-rep.git]$ ls [gituser@linux4ruby sample1-rep.git]$ [gituser@linux4ruby sample1-rep.git]$ [gituser@linux4ruby sample1-rep.git]$ git init --bare --shared Initialized empty shared Git repository in /git-server/sample1-rep.git/ [gituser@linux4ruby sample1-rep.git]$ ls -la 合計 16 drwxrwsr-x. 7 gituser gitgroup 119 10月 17 11:02 . drwxr-xr-x. 3 gituser gitgroup 29 10月 17 11:02 .. -rw-rw-r--. 1 gituser gitgroup 23 10月 17 11:02 HEAD drwxrwsr-x. 2 gituser gitgroup 6 10月 17 11:02 branches -rw-rw-r--. 1 gituser gitgroup 126 10月 17 11:02 config -rw-rw-r--. 1 gituser gitgroup 73 10月 17 11:02 description drwxrwsr-x. 2 gituser gitgroup 4096 10月 17 11:02 hooks drwxrwsr-x. 2 gituser gitgroup 21 10月 17 11:02 info drwxrwsr-x. 4 gituser gitgroup 30 10月 17 11:02 objects drwxrwsr-x. 4 gituser gitgroup 31 10月 17 11:02 refs [gituser@linux4ruby sample1-rep.git]$ exit ログアウト [nari@linux4ruby git]$ [nari@linux4ruby git]$

 ⭐️

linuxの基礎

忘れそうなコマンド類のメモ。 crontabで定期実行する例 指定は分、時、日、月、曜日を指定。 毎日11:00にとあるシェルを動かす場合 00 11 * * * /bin/sh /gvis/script/hogehoge.sh 1月15日と6月15日の11:00にとあるシェルを動かす場合 00 11 15 1,6 * /bin/sh /gvis/script/hogehoge.sh 毎週月曜から金曜の11:00にとあるシェルを動かす場合 00 11 * * 1-5 /bin/sh /gvis/script/hogehoge.sh 5分おきにとあるシェルを動かす場合 */5 * * * * /bin/sh /gvis/script/hogehoge.sh crontabのコマンドライン crontabの登録内容をテキストに書き出して保存。 crontab -l > res.txt テキストからcrontab登録。 crontab ./res.txt ほとんど使わないけど、crontabの直接編集。 オッサンはnanoじゃなくviに慣れてるので、いったんテキストファイルをviで編集してからでないと登録しない。 crontab -e 変更前と変更後を維持したいから、直接編集は使わない。 業務利用だったら、diffで比較して差分が必要な箇所だけになってることを確認するのも理由。 ローカルlinuxのcrontab 実際のrootのcrontab設定。 シェルは間違って動くと困るものもあるので、実行権はつけてない。 (dockerのエンジン停止とか困る) 代わりに/bin/shで呼び出す。 ちゃんと書けば、書いておいたタイミングで確実に動いてくれる。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #daily shutdown 59 23 * * * /bin/sh /gvis/script/901_OSstop.sh > /dev/null 59 11 * * 1-5 /bin/sh /gvis/script/901_OSstop.sh > /dev/null #Timely procdure 00,10,20,30,40,50 * * * * sync 01,11,21,31,41,51 0-23 * * * /bin/sh /gvis/script/903_ping_kanshi.sh 172.16.17.15 Yamaha_rtx1210 > /dev/null 05,15,25,35,45,55 0-23 * * * /bin/sh /gvis/script/802_CHKdiskStat.sh > /dev/null 06,16,26,36,46,56 6-21 * * * /bin/sh /gvis/script/803_CHKonlchkStat.sh > /dev/null 07,17,27,37,47,57 0-23 * * * /bin/sh /gvis/script/804_CHKsyslogStat.sh > /dev/null 09,19,29,39,49,59 6-23 * * * /bin/sh /gvis/script/805_CHKgavann-it.sh > /dev/null ### */2 0-23 * * * /bin/sh /gvis/script/808_CHKnetlogStat.sh > /dev/null */2 0-23 * * * /bin/sh /gvis/script/808_CHKnetlogStat2.sh > /dev/null #monthly GoogleDrive every Weekday 30 9 * * 1-5 /bin/sh /gvis/script/gdr/003_SyncNari.sh > /dev/null #daily Report 11 5 * * * /bin/sh /gvis/script/801_daily_report.sh > /dev/null 11 10 * * * /bin/sh /gvis/script/801_daily_report.sh > /dev/null #daily rm 00 7 * * * /bin/find /gvis/ -name ".*DS_Store" -print -exec rm {} ";" 01 7 * * * /bin/find /gvis/ -name "Thumbs.db" -print -exec rm {} ";" 02 7 * * * /bin/find /nari/ -name ".*DS_Store" -print -exec rm {} ";" 03 7 * * * /bin/find /nari/ -name "Thumbs.db" -print -exec rm {} ";" fsckしてからマウント ディスクの不整合を整えてマウントする。 ...