20201114のLinuxに関する記事は3件です。

Golangのクロスコンパイル時にsqlite3がundefinedエラーになる問題の解決

やろうとしたこと

GolangのスクリプトをAmazon Linux上で動すためにクロスコンパイルをしようとした

起きたこと

Mac向けにビルドすると普通にビルドできて動くが、linux向けにビルドするとエラーに。
linux向けのクロスコンパイルの設定が間違っているのかと思って調べたら違い、どうもsqlite3のみで起きていそう

MacOS向けは上手くいく

使用したコマンド

$ GOOS=darwin GOARCH=amd64 go build -o main_for_mac ./main.go

ビルドに成功し、動作も正常だった。

linuxはsqlite3でundefinedが出る

使用したコマンド

$ GOOS=linux GOARCH=amd64 go build -o main_for_linux ./main.go

出たエラー

# github.com/dinedal/textql/storage
../{中略}/.go/pkg/mod/github.com/dinedal/textql{中略}/sqlite.go:30:28: undefined: sqlite3.SQLiteConn
../{中略}/.go/pkg/mod/github.com/dinedal/textql{中略}/sqlite.go:49:4: undefined: sqlite3.SQLiteDriver
...

調べて分かったこと:

go-sqlite3を使っているMacユーザーがたくさんはまっていた。
該当のissues
https://github.com/mattn/go-sqlite3/issues/384

原因はC言語のクロスコンパイルにおいては実行環境がOS依存であることだった。
sqliteの実装においてえ使用されている模様。

Cross-compiling C code (and by extension, cgo code) is tricky because the choice of C compiler depends on both the OS (Windows/Linux/Mac) and architecture (x86, x64, arm) of both the host and target. On top of that, there are multiple flavors of compilers for a given combination. I don't think listing all of them is feasible. But I do think it would be helpful to more thoroughly explain what a cross-compiler is and why it is needed, and list out some of the more common options. It would also be helpful to mention using docker as a means of "cross-compiling" (at least when targeting Linux)

解決した方法

MacにおけるC言語のコンパイル環境に問題があるので gcc-4.8.1-for-linux32-linux64 をインストールすることで解決する。

手順

Mac用のgccをインストール

gcc-4.8.1-for-linux32-linux64 をダウンロードしてインストール。

オプションをつけて実行

実行するコマンドは以下

build as usual env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-gcc go build

参考

多くの人が上記issueで問題にぶつかっていたため、親切な方が手順を別のissueにまとめてくれていた。

install [http://crossgcc.rts-software.org/download/gcc-4.8.1-for-linux32-linux64/gcc-4.8.1-for-linux64.dmg]gcc-4.8.1-for-linux32-linux64
build as usual env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=/usr/local/gcc-4.8.1-for-linux64/bin/x86_64-pc-linux-gcc go build
```

該当のissue
https://github.com/mattn/go-sqlite3/issues/797

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

LPIC202試験で紹介される主な設定ファイル(自分用メモ)

サービス   設定ファイル        説明      
BIND /etc/named.conf メイン設定ファイル  
Apache /usr/local/apache2/conf/httpd.conf メイン設定ファイル
Apache /usr/local/apache2/conf/extra/ 補助設定を格納
Squid /etc/squid/squid.conf 設定ファイル
nginx   /etc/nginx/nginx/conf メイン設定ファイル
samba /etc/samba/smb.conf 全体設定と共有定義から構成         
NFS /etc/exports エクスポートするディレクトリを記述
DHCP /etc/dhcp.conf パラメータを記述
PAM /etc/pam.d ユーザー認証を行うプログラムの設定ファイルが格納されている
OpenLDAP /etc/openldap/slapd.conf データベースの形式や管理者のDN、LDAPの格納ディレクトリを記述  
SSSD /etc/sssd/sssd.conf 認証サービスとの通信を管理して、情報をキャッシュさせる
Postfix /etc/postfix/main.cf MTAとしての基本的な設定ファイル
Devcot /etc/docecot.conf imapやpopなど、利用するプロトコルを設定
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

【MariaDB】LinuxにMariaDBをインストールして、DBと操作ユーザーを作成する

AWSにて、Linux2のEC2をDBサーバーとして使おうとMariaDBをインストールしたときのメモです。(圧倒的自分用)

まずは何はともあれ

sudo yum update -y

mariaDBのインストール

sudo yum -y install mariadb-server

mariaDB起動

sudo systemctl start mariadb

DBのrootアカウントのパスワードを設定

mysqladmin -u root password

rootアカウントで、設定したパスワードにてDBにログイン

mysql -u root -p

{データベース名}でDBを作成

CREATE DATABASE {データベース名} DEFAULT CHARACTER SET utf8 COLLATE uft8_general_ci;

作成した{データベース名}DBへの全操作権限を付与したユーザーを
{ユーザー名}と{パスワード}で作成

grant all on {データベース名}.* to {ユーザー名}@"%" identified by '{パスワード}';

次回以降、サーバ起動時にmariaDBも自動で起動するように設定

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