カテゴリー: 技術系memo

  • GitLab CEのデフォルトのブランチ名を変える

    GitLabo CEでデフォルト設定を変えないと、プロジェクトを作った時のGitリポジトリのイニシャルブランチ名が「master」のままになってしまう。SVNなどから移行するときに、ブランチ名が「Main」だと別ブランチになってしまうので、今後に備えて、デフォルトのブランチ名を変えておく。

    1. GitLaboの管理画面に入る
    2. 設定からリポジトリを選択する(Settings からRepositoriesを選択する)
    3. 「Default initial branch name」を展開する
    4. ブランチ名を入力して、変更を保存する
  • git svn initを実行したらエラーになった

    Windows10で、git svn initを実行して、SVNのリポジトリをGitのリポジトリに変換しようとしたところ、perlでエラーになった。

    C:\Users\hoge\Documents\SVN>git svn init -T http://svn.xenos.jp/svn/app1/Trunk/ -t http://svn.xenos.jp/svn/app1/Tags/ --username=hoge
    svn: E235000: In file 'subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c' line 1666: assertion failed (get_current_pool_cb != NULL)
          1 [main] perl 1052 cygwin_exception::open_stackdumpfile: Dumping stack trace to perl.exe.stackdump
    C:\Users\hoge\Documents\SVN>
    C:\Users\hoge\Documents\SVN>git --version
    git version 2.27.0.windows.1
    C:\Users\hoge\Documents\SVN>
    

    バージョンを確認したら、新しいGitのバージョンが出ていたので、2.29.2にアップデートして、もう一度、試したら、成功した。

    参考: https://teratail.com/questions/266878

  • Google Cloud SQLでネットワーク接続制限を解除する

    Google Cloud SQLで、接続元のIPアドレスを固定できず、どこからでも接続できる設定にする。基本的にセキュリティがゆるゆるになるので、開発のときか、確認のための一時的な設定にした方がよい。

    1. GCPの管理画面で、Cloud SQLを開く。
    2. サイドメニュから「接続」を選択する。
    3. 接続の「パブリックIP」にチェックを入れる(もしくは入っていることを確認する)。
    4. 「+ネットワークを追加」をクリックする
    5. ネットワークに「0.0.0.0/0」を指定して、完了をクリックする。
    6. 次に「保存」をクリックする(保存しないとネットワークに反映されない)。

    これで、外部からCloud SQLのDBに接続できるようになる。

  • Magentoのインストールでハマったところ

    インストールのときの「Username」と「Password」がわからない。

    ubuntu@ip-172-31-45-120:/var/www/html$ sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/html/
    
    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Creating a "magento/project-community-edition" project at "./"
    Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit 
    https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
        Authentication required (repo.magento.com):
          Username:
          Password:
    Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit 
    https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
    Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit 
    https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
    Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit 
    https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
    
    In RemoteFilesystem.php line 746:
    
      Invalid credentials for 'https://repo.magento.com/packages.json', aborting.
    
    
    create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [ [ 
    []]]
    
    ubuntu@ip-172-31-45-120:/var/www/html$
    

    この「Username」と「Password」は、MangentのMarketplaceで、「Create A New Access Key」で発行するAccess Keyがこれにあたり、Public KeyとPrivate Keyがユーザ名とパスワードにあたる。(いや、これ、わかりにくい)

    Username = Public Key
    Password = Private Key

    参考: https://qiita.com/yutahonaga/items/bfb09205ca16c20aa44d

  • Bitnami Redmineで3.4.6から4.1.1にアップグレード

    Bitnami Redmineで、Redmineの3.4.6を使っている。3.4系が古いので、Redmineの4.1.1にアップグレードにアップグレードしたときの作業を残す。基本的には、Bitnamiのドキュメントの流れでインストールはできた。インストーラーを普通に走らせるとパスなどは変わるので、そこらへんはアレンジしてる。

    ■参考
    https://docs.bitnami.com/general/apps/redmine/administration/upgrade/

    ■やったこと

    アップデート前の環境のDBのユーザ名とパスワードをファイルから抜く。対象のファイルは、下記。

    /opt/redmine-3.4.6-1/apps/redmine/htdocs/config/database.yml
    

    接続の確認をする

    /opt/redmine-3.4.6-1/mysql/bin/mysql -u bitnami -p
    

    データを保存するフォルダを作る

    mkdir data
    cd data
    

    mysqldumpでデータベースのデータを保存する

    /opt/redmine-3.4.6-1/mysql/bin/mysqldump bitnami -p --databases bitnami_redmine --add-drop-database < bitnami_redmine.sql
    

    Redmineのファイルを保存する

     tar czf redmine_files.tar.gz -C /opt/redmine-3.4.6-1/apps/redmine/htdocs/files .
    

    プラグインのファイルを保存する

    tar czf redmine_plugins.tar.gz -C /opt/redmine-3.4.6-1/apps/redmine/htdocs/plugins .

    現在の環境のbitnami redmineを停止する

    sudo /opt/redmine-3.4.6-1/ctlscript.sh stop
    

    新しいバージョンのbitnami redmineのインストーラを実行する。ウィザード形式なので、ウィザードにしたがって設定をする。

    sudo ./bitnami-redmine-4.1.1-5-linux-x64-installer.run
    

    インストールができたら、新しいRedmineが起動しているので、アクセスして、アクセスできることを確認する。

    アクセスができ(=インストールされている)ていれば、次にApacheを停止する

    sudo /opt/redmine-4.1.1-5/ctlscript.sh stop apache
    

    新しいデータベースの接続情報を確認する。下記のファイルに記載されている。

    /opt/redmine-4.1.1-5/apps/redmine/htdocs/config/database.yml

    旧環境のデータを保存したディレクトリに移動し、下記のコマンドで、データベースのデータを入れる。

    /opt/redmine-4.1.1-5/mysql/bin/mysql -u bitnami -p < ./bitnami_redmine.sql
    

    次に、データを展開する。プラグインを使っているようであれば、プラグインも同じように展開する。

    sudo tar xzf ./redmine_files.tar.gz -C /opt/redmine-4.1.1-5/apps/redmine/htdocs/files
    

    Productionログのパーミッションを一時的に変更する(後から戻す)。

    sudo chmod 666 /opt/redmine-4.1.1-5/apps/redmine/htdocs/log/production.log
    

    新しい環境のRedmineの実行環境のディレクトリに移動する

    cd /opt/redmine-4.1.1-5/apps/redmine/htdocs/
    

    次にDBのマイグレーションを実行する。

    sudo /opt/redmine-4.1.1-5/ruby/bin/ruby bin/rake db:migrate RAILS_ENV=production
    

    キャッシュをクリーンナップする

    sudo /opt/redmine-4.1.1-5/ruby/bin/ruby bin/rake tmp:clear

    Productionログの権限を元に戻す

    sudo chmod 644 /opt/redmine-4.1.1-5/apps/redmine/htdocs/log/production.log
    

    Apacheを起動する

    sudo /opt/redmine-4.1.1-5/ctlscript.sh start apache
    

    設定ファイルなどの変更が必要な場合には変更する。

  • WSL2でDockerを使えるようにインストールする

    メモとして。前提として、WSL2のインストールは終わっている。

    Docker Desktop for Windowsをダウンロードする。下記のURLにアクセスして、「Get Docker」からダウンロードする。

    https://hub.docker.com/editions/community/docker-ce-desktop-windows/

    ダウンロードしたインストーラー(EXEファイル)を実行する。インストールのときに、「Install required Windows components for WSL2」にチェックが入っているので、WSL2対応もばっちり。

    インストールが終わったら、Windows10の再起動が入る。

    で、なにをしたらいいのかわからないので、チュートリアルを実施。

    チュートリアルの通りにやったら、チュートリアルのコンテナが立ち上がった。

    このコンテナがどこで動いているのか気になって、WSL2のUbuntuでpsコマンドをたたいてみると、dockerに関連したプロセスが起動しているので、WSL2の上で動作していることが確認できた。

     root       185  0.0  0.5 1463396 31664 pts/1   Ssl+ 20:06   0:00 /mnt/wsl/docker-desktop/docker-desktop-proxy --distro-n 
  • UbuntuのPHPを7.2から、7.4にしてみた

    Ubuntu 18.04のPHPをPHP7.2からPHP7.4に上げた。PHPを使っているのは、Wordpress。そのメモ。でも、途中が消えてる気がする、というか消えてる。

    ubuntu@ip-10-0-0-122:~$ php -v
    PHP 7.2.24-0ubuntu0.18.04.7 (cli) (built: Oct  7 2020 15:24:25) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.24-0ubuntu0.18.04.7, Copyright (c) 1999-2018, by Zend Technologies
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo apt install software-properties-common
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    software-properties-common is already the newest version (0.96.24.32.14).
    software-properties-common set to manually installed.
    The following packages were automatically installed and are no longer required:
      libdumbnet1 libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
      libnginx-mod-stream linux-aws-5.3-headers-5.3.0-1017 linux-aws-5.3-headers-5.3.0-1019
      linux-aws-5.3-headers-5.3.0-1023 linux-aws-5.3-headers-5.3.0-1028 linux-aws-5.3-headers-5.3.0-1030
      linux-aws-5.3-headers-5.3.0-1032 linux-aws-5.3-headers-5.3.0-1033 linux-aws-5.3-headers-5.3.0-1034
      linux-aws-5.3-headers-5.3.0-1035 linux-aws-headers-4.15.0-1041 linux-aws-headers-4.15.0-1043
      linux-aws-headers-4.15.0-1044 linux-aws-headers-4.15.0-1045 linux-aws-headers-4.15.0-1047
      linux-aws-headers-4.15.0-1048 linux-aws-headers-4.15.0-1050 linux-aws-headers-4.15.0-1052
      linux-aws-headers-4.15.0-1054 linux-aws-headers-4.15.0-1056 linux-aws-headers-4.15.0-1057
      linux-aws-headers-4.15.0-1058 linux-aws-headers-4.15.0-1060 linux-aws-headers-4.15.0-1063
      linux-aws-headers-4.15.0-1065 linux-headers-5.3.0-1035-aws linux-image-5.3.0-1035-aws linux-modules-5.3.0-1035-aws
      nginx-common nginx-core
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo add-apt-repository ppa:ondrej/php
     Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.
    Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa
    You can get more information about the packages at https://deb.sury.org
    IMPORTANT: The -backports is now required on older Ubuntu releases.
    BUGS&FEATURES: This PPA now has a issue tracker:
    https://deb.sury.org/#bug-reporting
    CAVEATS:
    1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
    2. If you are using apache2, you are advised to add ppa:ondrej/apache2
    3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
       or ppa:ondrej/nginx
    PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/
    WARNING: add-apt-repository is broken with non-UTF-8 locales, see
    https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:
    # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
     More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
    Press [ENTER] to continue or Ctrl-c to cancel adding it.
    Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
    Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease [20.8 kB]
    Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
    Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages [71.9 kB]
    Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main Translation-en [29.5 kB]
    Fetched 374 kB in 1s (398 kB/s)
    Reading package lists... Done
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo apt update
    Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
    Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    Hit:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
    Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
    Fetched 163 kB in 0s (399 kB/s)
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    20 packages can be upgraded. Run 'apt list --upgradable' to see them.
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ php -v
    PHP 7.4.11 (cli) (built: Oct 10 2020 19:44:50) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
    ubuntu@ip-10-0-0-122:~$
    

    このあと、Nginxのコンフィグで、php7.2-fpmからphp7.4-fpmに指定を変更して、Nginxを再起動。

    WordPressにアクセスしたら、php7.4-mysqlが入っていないと言われ、使えず。aptでインストールする。

    sudo apt install php7.4-mysql

    そのあと、Wordpressのヘルスチェックを確認。gdもないというので、aptでインストール。

    sudo apt install php7.4-gd

    これでバージョンアップは終わり。

  • WSL2でDockerを使えるようにインストールする

    自分のメモとして。

    前提として、WSL2のインストールは終わっている。

    Docker Desktop for Windowsをダウンロードする。下記のURLにアクセスして、「Get Docker」からダウンロードする。

    https://hub.docker.com/editions/community/docker-ce-desktop-windows/

    ダウンロードしたインストーラー(EXEファイル)を実行する。インストールのときに、「Install required Windows components for WSL2」にチェックが入っているので、WSL2対応もばっちり。

    インストールが終わったら、Windows10の再起動が入る。

    で、なにをしたらいいのかわからないので、チュートリアルを実施。

    チュートリアルの通りにやったら、チュートリアルのコンテナが立ち上がった。

    このコンテナがどこで動いているのか気になって、WSL2のUbuntuでpsコマンドをたたいてみると、dockerに関連したプロセスが起動しているので、WSL2の上で動作していることが確認できた。

    root      185  0.0  0.5 1463396 31664 pts/1  Ssl+ 20:06  0:00 /mnt/wsl/docker-desktop/docker-desktop-proxy --distro-n

    Dockerのインストールというかセットアップが簡単すぎて、正直よくわからない。利用する側にしてみると、どのみちブラックボックスなので、このくらい簡単なのがいいのだろう。

  • デプロイしたアプリにアクセスしたら ”HRESULT からの例外:0x801310“ が発生した

    ASP.NET(MVC5)で作成したアプリを変更してデプロイした。デプロイ後、Invoke-WebRequestでアクセスしたところ、アプリケーションエラーが発生した。エラー内容は下記。

    Invoke-WebRequest : '/API' アプリケーションでサーバー エラーが発生しました。
    ファイルまたはアセンブリ 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicK
    eyToken=31bf3856ad364e35'、またはその依存関係の 1 つが読み込めませんでした。見つかったアセンブリのマニフェスト定義はア
    センブリ参照に一致しません。 (HRESULT からの例外:0x80131040)
    説明: 現在の Web 要求を実行中に、ハンドルされていない例外が発生しました。エラーに関する詳細および例外の発生場所について
    は、スタック トレースを参照してください。
    例外の詳細: System.IO.FileLoadException: ファイルまたはアセンブリ 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform,
    Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'、またはその依存関係の 1 つが読み込めませんでした。見
    つかったアセンブリのマニフェスト定義はアセンブリ参照に一致しません。 (HRESULT からの例外:0x80131040)
    ソース エラー:
    現在の Web 要求の実行中にハンドルされていない例外が生成されました。障害の原因および発生場所に関する情報については、下の
    例外スタック トレースを使って確認できます。
    アセンブリ読み込みトレース: 以下の情報は、アセンブリ 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1
    .0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' を読み込めなかった原因を調べるのに役立ちます。
    警告: アセンブリ バインドのログ記録がオフにされています。
    アセンブリ バインドのエラー ログを有効にするには、レジストリ値 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) を 1
    に設定してください。
    注意: アセンブリ バインドのエラー ログに関連するパフォーマンス ペナルティがあります。
    この機能をオフにするには、レジストリ値 [HKLM\Software\Microsoft\Fusion!EnableLog] を削除します。
    スタック トレース:
    [FileLoadException: ファイルまたはアセンブリ 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Cult
    ure=neutral, PublicKeyToken=31bf3856ad364e35'、またはその依存関係の 1 つが読み込めませんでした。見つかったアセンブリの
    マニフェスト定義はアセンブリ参照に一致しません。 (HRESULT からの例外:0x80131040)]
       System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly
    , StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
       System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly
    , StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +96
       System.Type.GetType(String typeName) +62
       System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +15
       System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2406
       System.Web.Configuration.CompilationSection.get_RecompilationHash() +110
       System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +551
       System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +59
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +155
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMap
    PathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception ap
    pDomainCreationException) +746
    [HttpException (0x80004005): ファイルまたはアセンブリ 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.
    1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'、またはその依存関係の 1 つが読み込めませんでした。見つかったアセ
    ンブリのマニフェスト定義はアセンブリ参照に一致しません。 (HRESULT からの例外:0x80131040)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737
    バージョン情報: Microsoft .NET Framework バージョン:4.0.30319; ASP.NET バージョン:4.8.4075.0
    発生場所 行:1 文字:1
    + Invoke-WebRequest http://xxxx:8080/api/xxxxCopy/
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest]、WebExce
        ption
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    

    Visual Studioで開発してテストしていると何も問題がなかった。原因は、Web.configをデプロイしていなかったこと。Visual Studioの環境や.Net Framework 4.8の環境は、毎月更新されていく。その環境でコンパイルしたときに、もともとのWeb.configに記載された情報と新しくコンパイルされたものの情報が異なった。そのために、実行時にエラーになった。解決策としては、新しくコンパイルした方のWeb.configを使うこと。環境に合わせて変更する必要があれば変更する。

  • CTIMEの単位は秒

    Oracle DatabaseのV$LOCKテーブルのCTIMEの単位は秒。

    CTIME: 3600

    の場合は、3600秒なので、1時間。