20200402のLinuxに関する記事は9件です。

CentOSにMavenをインストールする方法

  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • tar (GNU tar) 1.26
    • GNU Wget 1.14 built on linux-gnu.

アーカイブをダウンロードする

# 1. rootユーザーに切り替える
$ sudo su -
[sudo] password for ponsuke: 

# 2. ダウンロードする
# wget https://www.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
--2020-04-02 16:32:40--  https://www.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
Resolving www.apache.org (www.apache.org)... 40.79.78.1, 95.216.24.32, 2a01:4f9:2a:185f::2
...省略...
100%[=========================================================================================================================================================================>] 7,956,528   2.58MB/s   in 2.9s   

2020-04-02 16:33:48 (2.58 MB/s) - ‘apache-maven-3.2.5-bin.tar.gz’ saved [7956528/7956528]

解凍して配置する

# tar xzvf apache-maven-3.2.5-bin.tar.gz -C /opt/
apache-maven-3.2.5/README.txt
...省略...
apache-maven-3.2.5/lib/slf4j-simple-1.7.5.jar

パスを通す

# 1. rootユーザーから自分に切り替える
# exit
logout

# 2. .bash_profileにパスを設定する
$ vi ~/.bash_profile
↓これを追記する
PATH=$PATH:/opt/apache-maven-3.2.5/bin/

# 3. .bash_profileを反映する
$ source ~/.bash_profile 
[1]+  Done                    exec ibus-daemon -dx

# 4. PATHを確認する
$ printenv PATH
/sbin:/bin:...省略...:/opt/apache-maven-3.2.5/bin/

Mavenが使えるか確認するためにバージョンを見てみる

# 注意 : コマンドはmavenではない
$ maven --version
bash: maven: command not found

# mvnが正しい
$ mvn --version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T02:29:23+09:00)
Maven home: /opt/apache-maven-3.2.5
Java version: 1.8.0_212, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.12.2.el7.x86_64", arch: "amd64", family: "unix"
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Linux】PATHを通す

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

tar (child): cannot run bzip2: No such file or directoryとなった時の対応方法

  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • tar (GNU tar) 1.26

事象 : .tar.bz2 を解凍しようとしたら怒られた

Sublime Text 3がバージョンアップしたので新しいのを配置しようとした。
圧縮ファイルの拡張子は.tar.bz2だった。解凍しようとしたら怒られた。

$ tar xvf sublime_text_3_build_3211_x64.tar.bz2
tar (child): cannot run bzip2: No such file or directory
tar (child): trying lbzip2
tar (child): lbzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

原因 : bzip2 コマンドがないから

tar (child): bzip2: Cannot exec: No such file or directory - Qiita

対応 : bzip2 コマンドをインストールする

$ sudo yum install bzip2
[sudo] password for ponsuke: 
Loaded plugins: fastestmirror, ovl
Repository google-chrome is listed more than once in the configuration
Determining fastest mirrors
...省略...
Installed:
  bzip2.x86_64 0:1.0.6-13.el7                                                                                                                                                                                      

Complete!

# 再度回答を試みると解凍できた!
$ tar xvf sublime_text_3_build_3211_x64.tar.bz2
sublime_text_3/
sublime_text_3/python3.3.zip
...省略...
sublime_text_3/Icon/48x48/sublime-text.png
$
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Linux・GCP】Gitコマンド使った時に出たエラー対処した件

https://www.topgate.co.jp/gcp04-google-compute-engine-run-application
ここをやろうとした時に対処した。

【参考サイト】
git initコマンドの使い方:https://www.sejuku.net/blog/71268

【1】
Initialized empty Git repository in
上記はOKだった時の表示。

【2】
git commitした時に以下のエラーが出た。
以下のエラーがでた
git commit -m “Initial Commit”
error: pathspec 'Commit”' did not match any file(s) known to git.

https://teratail.com/questions/161970
こちらを参照。

ダブルコートではなく、シングルでいけばOK

【3】
以下のエラーがでた
git commit -m 'Initial Commit'

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got '@')

*はマスクした部分

https://qiita.com/Taylor-U/items/3f329895766e613b3acf
ここで解決した。

要は、gitコマンドに関する設定をしていなかった。

https://note.nkmk.me/git-config-setting/
ここで設定確認、変更ができるみたい。

git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

たしかに、これしか出てこなかった。
なので、設定し、add ,commitしなおしたら行けました。

git add .
git commit -m 'Initial Commit'
[master (root-commit) bb4b386] Initial Commit
5 files changed, 84 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 app.yaml
create mode 100644 main.py
create mode 100644 main_test.py

======

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【Linux】Gitコマンド

GCPを使っている時、リポジトリにgitコマンドを使ってあげた。
gitコマンドについて無知だったので、調べてみた。
やろうとしたのは以下。
https://www.topgate.co.jp/gcp04-google-compute-engine-run-application
GCP ではソースコードの管理に Git を利用するとのこと。

gitについて
https://employment.en-japan.com/engineerhub/entry/2017/01/31/110000
今回やるのは、githubに上がっているリポジトリを複製してGCPで使うこと。
要は、ソースコードの管理をするためのコマンド。
図とかもあるので参考になる。

gitの基本コマンドとかもここを読んでおく
https://qiita.com/konweb/items/621722f67fdd8f86a017

併せて、リポジトリについてもおさえておく。
https://www.otsuka-shokai.co.jp/words/repository.html
アプリケーション開発の際に、システムを構成するデータやプログラムの情報が納められたデータベースのことを指す。
GCPのリポジトリにサンプルコードを格納するイメージかな?

============

ステージを理解して git をもっと便利に使う:http://daretoku-unix.blogspot.com/2009/08/git.html

・gitの概念
「「stageする」=「特定の変更内容をindexに登録する」=「次回コミットに含めるようgitに指示する」」
↑ここがポイント

https://kimromi.hatenablog.jp/entry/2015/08/04/082357
git add の使い方
ステージング領域に追加し、コミット対象にするコマンドです。

https://tech-blog.rakus.co.jp/entry/20190930/git
commitの使い方

http://www-creators.com/archives/2106
git commitの使い方

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

ApacheをSSL化しようとしたら起動しない。

1. はじめに

ApacheにSSL自己証明書を設定した時に詰まった部分があったので、備忘録として残します。

2. 証明書の作成

まず、以下コマンドで証明書を発行。

openssl ecparam -name prime256v1 -genkey -out server.key
openssl req -new -key server.key > server.csr
openssl ca -in server.csr -out server.crt

作成した証明書、秘密鍵を移動させます。

mv server.crt /etc/httpd/conf/ssl.crt/server.crt
mv server.key /etc/httpd/conf/ssl.key/server.key

3. 設定の変更

証明書、秘密鍵の保存場所を指定します。

vi /etc/httpd/conf.d/ssl.conf
--snip--
<VirtualHost *:443>
--snip--
#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
--snip--

4. Apacheの再起動

再起動するとエラーが発生。

systemctl restart httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

journalctl -xe を見ても何も情報がない。。。
/var/log/httpd/error_log を確認すると Permission 関連のエラーが。
どうやらSELINUXが悪さしているみたい。

/var/log/httpd/error_log
[Thu Apr 02 10:02:29.534751 2020] [ssl:emerg] [pid 19565] AH02312: Fatal error initialising mod_ssl, exiting.
[Thu Apr 02 10:02:33.453638 2020] [core:notice] [pid 19576] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Thu Apr 02 10:02:33.455370 2020] [suexec:notice] [pid 19576] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Apr 02 10:02:33.455600 2020] [ssl:emerg] [pid 19576] (13)Permission denied: AH02201: Init: Can't open server certificate file /etc/httpd/conf/ssl.crt/wild_server.crt

調べてみるとSELinuxのセキュリティポリシーで各ファイルに適切なラベルが付与されていないとダメらしい。
ラベルは「ll -Z」コマンドで確認できる。

[root@149_centos ssl.key]# ll -Z
-rwxrwxrwx. hoge hoge unconfined_u:object_r:user_home_t:s0 wild_server.key

これを「restorecon」コマンドで適切なラベルを付け直す。

[root@149_centos ssl.key]# restorecon wild_server.key
[root@149_centos ssl.key]#
[root@149_centos ssl.key]# ll -Z
-rwxrwxrwx. hoge hoge unconfined_u:object_r:httpd_config_t:s0 wild_server.key

結果、「systemctl restart httpd.service」コマンドで正常に再起動しSSL化が出来た。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

自分の~/.bashrcに必ず追加しているもの

もっとあるんだけどとりあえずこれは必ず書いてます。
Historyは、個人的に超重要だったりします。

export HISTTIMEFORMAT='%F %T ' 
export HISTSIZE=50000 

export LANG=ja_JP.UTF-8 

alias ggg='cat ~/.bashrc | grep git' 

alias la='ls -la' 
alias lt='ls -lt' 

alias gcd='cd /var/www/html && pwd' 
alias gcommit='git commit -am' 
alias gfetch='git fetch' 
alias gpull='git pull' 
alias gpush='git push -u origin master' 

alias gone='git log --oneline' 
alias glog='git log' 
alias gstat='git status'

set -o vi

たいしたこと書いてないので申し訳なす。。
emacs派の人とは仲良く出来ないと思ってます。。。。。。。。。。。。。。。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

localhostのポートを使用しているプロセスを調べて、停止する方法

はじめに

ローカルで開発をしていると、自分が使用したいポート番号に、以前に開発した時に使用したプロセスが残っていることがある。
そんな時の、対処法を記述する。

対処法

localhostの3000番ポートで動いているプロセスを把握したい時には以下のコマンドを使用する。

ターミナル
$ lsof -i :3000

com.docke 25316 takuya   41u \
IPv6 0xc293b929f41a59e9      0t0  TCP *:hbci (LISTEN)

以上のように、3000番ポートで動いているプロセスのPID番号が把握できる。
ここでは、PID番号が25316なので、以下のようにしてプロセスを停止する。

ターミナル
$ kill -9 25316

-9は強制終了のオプションだそう。

以上

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Ubuntu Linuxで、Tabをqにする

TL;DR

  • やんごとなき理由で、Tabキーをqキーにしたい
  • 対象はUbuntu Linux
  • xevでキーコードとkeysymを調べてxmodmapで割り当てる

環境

$ uname -srvmpio
Linux 4.18.0-25-generic #26~18.04.1-Ubuntu SMP Thu Jun 27 07:28:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

xmodmapxev

xmodmapというコマンドで、キーの割り当てを変更できます。

$ xmodmap -e "keycode [keycode] = [keysym]"

[keycode]が指す物理的なキーを、[keysym]が指す内容に割り当てることができます。

これらを調べるには、xevコマンドを使います。

$ xev

コマンド起動後にキーを押すと、キーコードとkeysymを調べることができます。

"q"を押した場合は、keycodeは24で、keysymはqです。

KeyPress event, serial 37, synthetic NO, window 0x5e00001,
    root 0x17e, subw 0x0, time 5825075, (42,674), root:(197,823),
    state 0x0, keycode 24 (keysym 0x71, q), same_screen YES,
    XLookupString gives 1 bytes: (71) "q"
    XmbLookupString gives 1 bytes: (71) "q"
    XFilterEvent returns: False

"Tab"を押した場合は、keycodeは23で、keysymはTabです。

KeyPress event, serial 37, synthetic NO, window 0x5e00001,
    root 0x17e, subw 0x0, time 5804891, (141,203), root:(296,352),
    state 0x0, keycode 23 (keysym 0xff09, Tab), same_screen YES,
    XLookupString gives 1 bytes: (09) " "
    XmbLookupString gives 1 bytes: (09) "   "
    XFilterEvent returns: False

Tabをqにする

ここまでの情報が得られたので、Tabをqにするには、以下のようにします。

$ xmodmap -e "keycode 23 = q"

元に戻すには、以下のようにします。

$ xmodmap -e "keycode 23 = Tab"

なお、この変更は現在のX Windowセッションのみで、永続的な適用は行われません。

個人的には、それで問題ないので…。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む