2025年03月22日
ブログエディタってもう無いのね
2023年06月05日
6年ぶり
結果、何か文書を書くというのが面倒くさく感じてすっかり離れていたが、
リモートワークだなんだでPC以外の環境を充実させたので、ついでにデスクトップPCもようやくリニューアル。
2017年08月11日
CentOS7でPython3.6をyumでインストールする
ソースからいつもインストールしていたが、面倒くさくなってきたのでyumでインストールする方法を調べた。
IUS Community ProjectというRHELやCentOS向けに、最新のソフトウェアのRPMを提供しているリポジトリを登録。
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
リポジトリが登録出来たらyumでインストール。
yum install -y python36u python36u-devel python36u-libs python36u-pip python36u-setuptools python36u-tools
後でpip使うときに必要になるので、下記もインストールしておく。
sudo yum groupinstall "Development Tools"
Version確認。
python3.6 -V pip3.6 -V
参考
- CentOS7にPython3.4をインストールする[記事]
2017年02月12日
CentOS 7にReview Board 2.5.7をインストールする
仕事で使ってみようかと思って、ReviewBoardをインストールしてみる。
前準備
Review BoradはyumでEPELリポジトリからインストールできるので、EPELを有効にしておく。
yum install epel-release
MySQL インストール
MySQLをインストールするため、MySQL公式リポジトリを登録してインストール。
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
MySQL5.7.4から360日のパスワード有効期限がデフォルトでつくようになったので、/etc/my.cnfで下記記載をして無効にしておく。ついでにUTF-8の設定もしておく。
[mysql] default-character-set=utf8 [mysqld] character-set-server = utf8 default_password_lifetime=0
あとは、自動起動設定をして起動する。
systemctl enable mysqld.service systemctl start mysqld.service
mysqlが起動したら/var/log/mysqld.logに初期パスワードが記載されているので、それを覚えて初期設定する。
[Note] A temporary password is generated for root@localhost: <初期パスワード>
初期設定のコマンド。
mysql_secure_installation
ReviewBoardで使うデータベースとユーザーを作成しておく。
create database reviewboard; grant all on reviewboard.* to reviewboard@localhost identified by 'パスワード';
Review Board インストール
Review Boardをインストール。Apacheやwsgi,pythonが依存関係でインストールされる。
yum install ReviewBoard
PiPとMemcacheはインストールされないようなのでインストールしておく。pipは古いのが入るのでアップデートする。
yum install memcached yum install python-pip pip install --upgrade pip
FirewallはHTTPが通るようにする。
firewall-cmd --permanent --add-service=http
ReviewBoardを実行して、生成された設定ファイルをapacheの下にコピーして再起動。
rb-site install /var/www/html/reviewboard chown -R apache: /var/www/html/reviewboard cp /var/www/html/reviewboard/conf/apache-wsgi.conf /etc/httpd/conf.d/ systemctl restart httpd
http://<サーバーのアドレス>/reviewboard/でアクセスできる。
2016年12月25日
CentOS7且つPython3でGeoIP2を使用する
環境はCentOS7.3で、Python3.4.3で確認した。
まずMAX MIND社[GeoLite2]からGeoLite2データベースを取得する。
wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
gzipで圧縮されているので解凍する。
gunzip -d GeoLite2-City.mmdb.gz
続いて、PythonのGeoIPライブラリをインストールする。
/usr/local/python-3.4/bin/pip install geoip2
後は、Pythonでgeoip2.databaseをimportして使用する。
一先ずClassにして必要そうな値を返すサンプルを作成。
#! /usr/bin/env python3 # -*- coding: utf-8 -*- # import sys import geoip2.database class GeoIP: def __init__(self): self.reader=geoip2.database.Reader('GeoLite2-City.mmdb') def getGeoLocation(self,ip): record = self.reader.city(ip) return(record.country.name,record.city.name,record.country.iso_code,record.location.latitude,record.location.longitude) if __name__== "__main__": if len(sys.argv) == 2: ipadress = sys.argv[1] else: ipadress = '8.8.8.8' geodata = GeoIP() print(geodata.getGeoLocation(ipadress)[0]) print(geodata.getGeoLocation(ipadress)[1]) print(geodata.getGeoLocation(ipadress)[2]) print(geodata.getGeoLocation(ipadress)[3]) print(geodata.getGeoLocation(ipadress)[4])
IPアドレス8.8.8.8で実行した結果は下記のようになる。
United States Mountain View US 37.386 -122.0838
サンプルには含めていないものもあるが、それぞれの変数は下記のようになる。
変数 | 意味 | 例 |
---|---|---|
record.continent.name | 大陸名 | North America |
record.continent.code | 大陸コード | NA |
record.country.name | 国名 | United States |
record.country.iso_code | 国名コード | US |
record.subdivisions.most_specific.name | 州・県 | California |
record.subdivisions.most_specific.iso_code | 州・県コード | CA |
record.city.name | 都市名 | Mountain View |
record.location.latitude | 都市の緯度 | 37.386 |
record.location.longitude | 都市の経度 | -122.0838 |
record.location.time_zone | 都市のタイムゾーン | America/Los_Angeles |
日本語のデータベース
mmdbを下記のように読むと、日本語のデータベースを読み込んでくれる。
self.reader=geoip2.database.Reader('GeoLite2-City.mmdb',['ja'])
8.8.8.8を調べると下記のように出力される。ただ、場所によっては日本語が無いようなので、英語のままの方が良い気がする。
アメリカ合衆国 マウンテンビュー US 37.386 -122.0838
関連する記事
2016年12月17日
CentOS7にyumでkibana 5系をインストールする
前回[記事]、yumでkibana4.5をインストールする設定を行ったが、すでに5系がリリースされていたので、4.5を5系にアップデートしてみる。
5系はelasticsearchとkibanaのリポジトリが統合されたようなので、どちらか一つ設定しておけば良いようだ。
インストール手順
まず鍵をインストールする。
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
エディタでリポジトリの設定。kibana.repoみたいなファイルを作成して、
vi /etc/yum.repos.d/kibana.repo
下記を記載する。
古いのリポジトリを設定していたらenabled=0に変更しておく。
[kibana-5.x] name=Kibana repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
後はyumでインストールする。
yum install kibana
インストール直後はkibanaはローカルホストからしかアクセスできない設定になっているので、設定ファイルを編集する。
vi /etc/kibana/kibana.yml
とりあえず外部からブラウザでアクセスできるようにserver.host=0.0.0.0を追加する。
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values. # The default is 'localhost', which usually means remote machines will not be able to connect. # To allow connections from remote users, set this parameter to a non-loopback address. #server.host: "localhost" server.host: "0.0.0.0"
serviceの設定をして起動する。
systemctl daemon-reload systemctl enable kibana.service systemctl start kibana
あとはブラウザでアクセスするだけ。
関連する記事
参考
- Install Kibana with RPM[elastic]
CentOS7にyumでelasticsearch 5系をインストールする
kibana4系を使っていたら5系が出ていて、elasticsearchもアップデートされていたので、yumからアップデートする。
5系はelasticsearchとkibanaのリポジトリが統合されたようなので、どちらか一つ設定しておけば良いようだ。
インストール方法
まずは、GPGキーのインポート
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
その後は、リポジトリの設定ファイルを作る。
vi /etc/yum.repos.d/elasticsearch.repo
viでファイル開いて、以下を書き込む。
1系や2系のリポジトリを設定していたらenabled=0に変更しておく。
[elasticsearch-5.x] name=Elasticsearch repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
あとは、yumでインストールする。
yum install elasticsearch
ハマった事
アップデートは出来たが起動ができなかったのでログを見てみる。
less /var/log/elasticsearch/elasticsearch.log
すると、設定がおかしいというエラーが出ていた。
[2016-12-17 T22:05:19,899][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [http.cros.enabled] did you mean any of [http.cors.enabled, http.enabled]?
elasticsearchの設定ファイルを開いて、
vi /etc/elasticsearch/elasticsearch.yml
指摘があった箇所を直したところ、起動できるようになった。
#http.cros.enabled: true http.enabled: true
関連する記事
- CentOS7にElasticsearch1.7をインストールする記事]
参考
- Install Elasticsearch with RPM[elastic]
2016年05月05日
cpコマンドで強制上書きを行う方法
CentOS7でcpに-fオプションをつけても、何故か上書き確認がされてしまう。
cp -rf /home/hoge /home/fuga
ディレクトリを定期的に丸ごとコピーしたいのにと思ってたら、エイリアスで「cp -i」に置き換えられているとのこと。
最初にバックスラッシュをつけたら、確かにコピーができた。
\cp -rf /home/hoge /home/fuga
参考
- Linuxのcp コマンドで強制上書き[まだプログラマーですが何か?]
CentOS7にSphinx1.4.1をpython3でインストールする
ネットを見ていたら、やはりpython2.7で使っているケースが多かったが、インストールしたのがPython3.4なので、この環境でSphinxをインストールする。
結果論からいうと、特に困ったことは無かったけど。
Sphinxをインストール
/usr/local/python-3.4/bin/pip install sphinx
pythonコマンド以外パス通していなかったので、直接pip実行してインストール。
パスを通す
ln -s /usr/local/python-3.4/bin/sphinx-build /usr/local/bin/sphinx-build
sphinx-buildへのパスが通っていないので、そのまま実行するとmakeでコケる。
なのでパスを通す。
動作確認
sphinx-quickstartでプロジェクトを作成する。
# /usr/local/python-3.4/bin/sphinx-quickstart Welcome to the Sphinx 1.4.1 quickstart utility. Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets). Enter the root path for documentation. > Root path for the documentation [.]: # ↑ドキュメントのルートパス省略時は今の場所 You have two options for placing the build directory for Sphinx output. Either, you use a directory "_build" within the root path, or you separate "source" and "build" directories within the root path. > Separate source and build directories (y/n) [n]: # ↑ソースと、ビルド結果のフォルダを完全に分けるかどうか。 # デフォルトはソースのフォルダ内に_buildディレクトリができる。 Inside the root directory, two more directories will be created; "_templates" for custom HTML templates and "_static" for custom stylesheets and other static files. You can enter another prefix (such as ".") to replace the underscore. > Name prefix for templates and static dir [_]: # ↑Sphinxの作るシステムディレクトリの名前の先頭に付く接頭辞。デフォルトは'_' The project name will occur in several places in the built documentation. > Project name: Hogehoge Project > Author name(s): fuga # ↑プロジェクト名と著者名。入力必須。 Sphinx has the notion of a "version" and a "release" for the software. Each version can have multiple releases. For example, for Python the version is something like 2.5 or 3.0, while the release is something like 2.5.1 or 3.0a1. If you don't need this dual structure, just set both to the same value. > Project version: 1.0.0.0 > Project release [1.0.0.0]: # ↑プロジェクトのバージョン。versionは荒く、releaseは細かい。 # versionは必須だけど、releaseはデフォルトでversionと同じものが入る。 If the documents are to be written in a language other than English, you can select a language here by its language code. Sphinx will then translate text that it generates into that language. For a list of supported codes, see http://sphinx-doc.org/config.html#confval-language. > Project language [en]: ja # ↑プロジェクトのサポート文字コード。後でPDF作るためにjaと入力した。 The file name suffix for source files. Commonly, this is either ".txt" or ".rst". Only files with this suffix are considered documents. > Source file suffix [.rst]: # ↑ソースファイルのデフォルトの拡張子。デフォルトは.rst。 One document is special in that it is considered the top node of the "contents tree", that is, it is the root of the hierarchical structure of the documents. Normally, this is "index", but if your "index" document is a custom template, you can also set this to another filename. > Name of your master document (without suffix) [index]: # ↑ドキュメントのトップページ(マスター)のファイル名(拡張子なし)。デフォルトは'index' Sphinx can also add configuration for epub output: > Do you want to use the epub builder (y/n) [n]: y # ↑EPUB用の設定ファイルを追加するか?後で試すのでyesにする。 Please indicate if you want to use one of the following Sphinx extensions: > autodoc: automatically insert docstrings from modules (y/n) [n]: > doctest: automatically test code snippets in doctest blocks (y/n) [n]: > intersphinx: link between Sphinx documentation of different projects (y/n) [n]: > todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: > coverage: checks for documentation coverage (y/n) [n]: > imgmath: include math, rendered as PNG or SVG images (y/n) [n]: > mathjax: include math, rendered in the browser by MathJax (y/n) [n]: > ifconfig: conditional inclusion of content based on config values (y/n) [n]: > viewcode: include links to the source code of documented Python objects (y/n) [n]: > githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: # ↑各種拡張機能をインストールするかどうか。必要なら後で追加できる。 A Makefile and a Windows command file can be generated for you so that you only have to run e.g. `make html' instead of invoking sphinx-build directly. > Create Makefile? (y/n) [y]: > Create Windows command file? (y/n) [y]: # ↑ビルド用のMakefileとバッチファイルを作るかどうか。デフォルトは作成する。 Creating file ./conf.py. Creating file ./index.rst. Creating file ./Makefile. Creating file ./make.bat. Finished: An initial directory structure has been created. You should now populate your master file ./index.rst and create other documentation source files. Use the Makefile to build the docs, like so: make builder where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
HTMLを生成して正しく動くか確認する。
make html
_build\html\の下にhtmlが生成される。
PDFやePubはまた別記事にする。
関連する記事
参考
- sphinx-quickstartの詳細説明[Sphinx-Users.jp]
2016年05月04日
pipを最新版にする
以前ソースコードからコンパイルしてインストールしたpipが7.1.1で古かったのでアップデートする。
前回は/usr/local/python-3.4/にインストールしたので、その下にあるpipを叩いてアップデートを行う。
/usr/local/python-3.4/bin/pip install --upgrade pip
関連する記事
- CentOS7にPython3.4をインストールする[記事]