メール, Linux

CentOS7 Sisimai+Sisitoインストール

 

 

作業メモです、インストールは出来るだろうけれど、参考にするのはおすすめしないです。

 

# yum -y install epel-release
# yum -y install jq

 

# yum install -y git bzip2 gcc openssl-devel readline-devel zlib-devel
# yum install -y mysql-devel

 

# yum remove mariadb-libs
# rm -rf /var/lib/mysql/
# yum install -y http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# yum list --enablerepo=mysql56-community | grep mysql
# yum install -y --enablerepo=mysql56-community mysql-community-client.x86_64 mysql-community-devel.x86_64 mysql-community-server.x86_64
# mysql --version

 

systemctl restart mysqld
systemctl enable mysqld
systemctl status mysqld

 

# cat /var/log/mysqld.log | grep root

2019-06-25T07:05:39.815710Z 1 [Note] A temporary password is generated for root@localhost: #?qa%+JRf9%h

 

# mysql -u root -p
Enter password:<#?qa%+JRf9%h>

 

mysql> set password for root@localhost=password('hogeMoge55$!');

mysql> CREATE DATABASE sisito;

mysql> exit
Bye

 

$ groupadd rails
$ useradd rails -g rails -d /home/rails -s /bin/bash

 

# visudo

%wheel  ALL=(ALL)       NOPASSWD: ALL

 

# usermod -aG wheel rails
# sudo su - rails

 

# git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
# mkdir -p ~/.rbenv/plugins
# cd ~/.rbenv/plugins
# git clone git://github.com/sstephenson/ruby-build.git

 

echo '# rbenv' >> ~/.bash_profile
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

 

反映

# exec $SHELL --login

 

# rbenv --version
rbenv 1.1.2-2-g4e92322

 

$ git clone https://github.com/rbenv/rbenv-vars.git $HOME/.rbenv/plugins/rbenv-vars

 

$ rbenv install --list

 

Sisimaiは2.1以上で動く、
他の参考記事が2.3.0のバージョンが多いのでそちらを

$ rbenv install 2.3.0


※数分待つ

Downloading ruby-2.3.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
Installing ruby-2.3.0...
Installed ruby-2.3.0 to /home/rails/.rbenv/versions/2.3.0

 

$ rbenv rehash
$ rbenv global 2.3.0

 

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

 

$ gem install bundle
Fetching: bundler-2.0.2.gem (100%)

 

$ gem install sisimai

Fetching: oj-3.7.12.gem (100%)
Building native extensions.  This could take a while...
Successfully installed oj-3.7.12
Fetching: sisimai-4.25.0.gem (100%)
Successfully installed sisimai-4.25.0
Parsing documentation for oj-3.7.12
Installing ri documentation for oj-3.7.12
Parsing documentation for sisimai-4.25.0
Installing ri documentation for sisimai-4.25.0
Done installing documentation for oj, sisimai after 6 seconds
2 gems installed

 

$ git clone https://github.com/sisimai/rb-Sisimai.git
$ cd ./rb-Sisimai
$ make depend install-from-local


sisimai 4.25.0p1 built to pkg/sisimai-4.25.0p1.gem.
sisimai (4.25.0p1) installed.
if [ test -d "/usr/local/jr" ]; then \
        PATH="/usr/local/jr/bin:$PATH" /usr/local/jr/bin/rake install; \
fi
/bin/sh: line 0: [: -d: binary operator expected

 

$ git clone https://github.com/winebarrel/sisito.git
$ cd sisito
$ bundle install

 

$ gem environment


RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/rails/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: /home/rails/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /home/rails/.rbenv/versions/2.3.0/bin/ruby
  - EXECUTABLE DIRECTORY: /home/rails/.rbenv/versions/2.3.0/bin
  - SPEC CACHE DIRECTORY: /home/rails/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/rails/.rbenv/versions/2.3.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/rails/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
     - /home/rails/.gem/ruby/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/rails/.rbenv/versions/2.3.0/bin
     - /home/rails/.rbenv/libexec
     - /home/rails/.rbenv/plugins/ruby-build/bin
     - /home/rails/.rbenv/plugins/rb-Sisimai/bin
     - /home/rails/.rbenv/plugins/rbenv-vars/bin
     - /home/rails/.rbenv/shims
     - /home/rails/.rbenv/bin
     - /usr/local/bin
     - /bin
     - /usr/bin
     - /usr/local/sbin
     - /usr/sbin
     - /home/rails/.local/bin
     - /home/rails/bin
     - /home/rails/.local/bin
     - /home/rails/bin

 

$ vi config/database.yml

・・・

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: sisito
  pool: 5
  username: root
  password: hogeMoge55$!
  host: localhost
  variables:
    sql_mode: TRADITIONAL # required

 

 

$ sudo yum install -y nodejs --enablerepo=epel
$ sudo yum install -y mysql mysql-connector-odbc mysql-libs

 

エラーが起きる

$ bundle exec rails db:create db:migrate

LoadError: libmysqlclient.so.18: cannot open shared object file: 
No such file or directory - /home/rails/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2/mysql2.so

 

再インストールしてみる

[rails@133-130-89-146 sisito]$ gem uninstall mysql2
Successfully uninstalled mysql2-0.3.21


[rails@133-130-89-146 sisito]$ gem install mysql2
Fetching: mysql2-0.5.2.gem (100%)
Building native extensions.  This could take a while...

 

$ bundle install
$ bundle exec rails db:create db:migrate
$ bundle exec rails server

※1分待つ

  Rendered layouts/_navigation_links.html.erb (1.7ms)
  Rendered layouts/_navigation.html.erb (2.8ms)
  Rendered layouts/_messages.html.erb (0.4ms)
Completed 200 OK in 5927ms (Views: 5162.7ms | ActiveRecord: 297.2ms)

 

# yum install -y postfix
# yum install -y cyrus-sasl

systemctl restart postfix
systemctl enable postfix
systemctl status postfix
systemctl restart saslauthd
systemctl enable saslauthd
systemctl status saslauthd

 

# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
# chmod -R 700 /etc/skel/Maildir/

 

# useradd catch-error-mail
# saslpasswd2 -u yuutest1.work catch-error-mail

 

# sasldblistusers2
catch-error-mail@yuutest1.work: userPassword

 

# chgrp postfix /etc/sasldb2
# chmod 640 /etc/sasldb2

 

# vi /etc/sasl2/smtpd.conf


pwcheck_method: saslauthd
mech_list: plain login

↓変更

#pwcheck_method: saslauthd
#mech_list: plain login
pwcheck_method: auxprop
mech_list: plain login

 

# vi /etc/postfix/main.cf


#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mx1.yuutest1.work


#mydomain = domain.tld
mydomain = yuutest1.work


#myorigin = $myhostname
#myorigin = $mydomain
myorigin = $mydomain


#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
inet_interfaces = all


#inet_protocols = all
inet_protocols = ipv4



#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain
mydestination = $myhostname, $mydomain


#home_mailbox = Mailbox
#home_mailbox = Maildir/
home_mailbox = Mailbox



※最終行に追加

relay_domains = $mydestination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 0
mailbox_size_limit = 0

BOUNCEDIR=/home/catch-error-mail/bounce/


## バウンスメール対策
# 1. 200秒毎にキューをチェック
queue_run_delay        = 5s
# 2. 1600秒毎に再送して、2回目は2倍の3200秒、3回目は4倍の6400秒後に再送
minimal_backoff_time   = 5s
# 3. 待機が7200秒(2時間)に達したキューは破棄しエラーメールを返す
maximal_backoff_time   = 5s
maximal_queue_lifetime = 5s
bounce_queue_lifetime  = 5s

 

# vi /etc/postfix/master.cf


#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       n       -       -       smtpd
#smtp      inet  n       -       n       -       1       postscreen
#smtpd     pass  -       -       n       -       -       smtpd
#dnsblog   unix  -       -       n       -       0       dnsblog
#tlsproxy  unix  -       -       n       -       0       tlsproxy
submission inet n       -       n       -       -       smtpd # ←●有効化
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes  # ←●有効化
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject # ←●有効化
#  -o milter_macro_daemon_name=ORIGINATING

 

systemctl restart postfix
systemctl enable postfix
systemctl status postfix
systemctl restart saslauthd
systemctl enable saslauthd
systemctl status saslauthd

 

メーラから【catch-error-mail@yuutest1.work】宛にメールして、

 

パーミッション設定

$ sudo chmod 777 -R /home/catch-error-mail/

 

 

$ vi test.rb


#! /usr/bin/env ruby
require 'sisimai'
v = Sisimai.make('/home/catch-error-mail/Mailbox')       # or path to Maildir/

# Beginning with v4.23.0, both make() and dump() method of Sisimai class can
# read bounce messages from variable instead of a path to mailbox
f = File.open('/home/catch-error-mail/Mailbox', 'r');    # or path to Maildir/
v = Sisimai.make(f.read)

# If you want to get bounce records which reason is "delivered", set "delivered"
# option to make() method like the following:
v = Sisimai.make('/home/catch-error-mail/Mailbox', delivered: true)

if v.is_a? Array
  v.each do |e|
    puts e.class                # Sisimai::Data
    puts e.recipient.class      # Sisimai::Address
    puts e.timestamp.class      # Sisimai::Time

    puts e.addresser.address    # shironeko@example.org # From
    puts e.recipient.address    # kijitora@example.jp   # To
    puts e.recipient.host       # example.jp
    puts e.deliverystatus       # 5.1.1
    puts e.replycode            # 550
    puts e.reason               # userunknown

    h = e.damn                  # Convert to HASH
    j = e.dump('json')          # Convert to JSON string
    puts e.dump('json')         # JSON formatted bounce data
  end
end

 

 

$ ruby -r 'sisimai' -e 'puts Sisimai.dump($*.shift)' "/home/rails/rb-Sisimai/set-of-emails/maildir/bsd/rhost-tencentqq-01.eml" | jq .

[
  {
    "catch": "",
    "token": "144a0d5545a113c8f352de38d6329920694b715a",
    "lhost": "mail.example.net",
    "rhost": "mx3.qq.com",
    "alias": "nekochan@qq.example.cn",
    "listid": "",
    "reason": "toomanyconn",
    "action": "failed",
    "subject": "Nyaan",
    "messageid": "20180429233445.1BFAC0EE7C9F@mail.example.net",
    "replycode": "550",
    "smtpagent": "Email::Postfix",
    "softbounce": 1,
    "smtpcommand": "DATA",
    "destination": "qq.example.cn",
    "senderdomain": "example.com",
    "feedbacktype": "",
    "diagnosticcode": "host mx3.qq.com[103.7.30.40] said: 550 Ip frequency limited [V2VkIEFwciAgMyAxNjozNjo1OSBKU1QgMjAxOQo=/RkNGMjlFQTVEQ0E Blocked IP 192.0.2.22]. http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=20022&&no=1000725 (in reply to end of DATA command)",
    "diagnostictype": "SMTP",
    "deliverystatus": "5.0.0",
    "timezoneoffset": "+0900",
    "addresser": "kijitora-nyaan@example.com",
    "recipient": "nekochan@qq.example.cn",
    "timestamp": 1541514885
  }
]

 

ディレクトリもループで読み込む

$ ruby -r 'sisimai' -e 'puts Sisimai.dump($*.shift)' "/home/rails/rb-Sisimai/set-of-emails/maildir/bsd/" | jq .

 

 

$ vi /home/rails/rb-Sisimai/test.rb


#! /usr/bin/env ruby
require 'sisimai'
v = Sisimai.make('/home/rails/rb-Sisimai/set-of-emails/maildir/bsd/rhost-kddi-02.eml')       # or path to Maildir/

# Beginning with v4.23.0, both make() and dump() method of Sisimai class can
# read bounce messages from variable instead of a path to mailbox
f = File.open('/home/rails/rb-Sisimai/set-of-emails/maildir/bsd/rhost-kddi-02.eml', 'r');    # or path to Maildir/
v = Sisimai.make(f.read)

# If you want to get bounce records which reason is "delivered", set "delivered"
# option to make() method like the following:
v = Sisimai.make('/home/rails/rb-Sisimai/set-of-emails/maildir/bsd/rhost-kddi-02.eml', delivered: true)

if v.is_a? Array
  v.each do |e|
    puts e.class                # Sisimai::Data
    puts e.recipient.class      # Sisimai::Address
    puts e.timestamp.class      # Sisimai::Time

    puts e.addresser.address    # shironeko@example.org # From
    puts e.recipient.address    # kijitora@example.jp   # To
    puts e.recipient.host       # example.jp
    puts e.deliverystatus       # 5.1.1
    puts e.replycode            # 550
    puts e.reason               # userunknown

    h = e.damn                  # Convert to HASH
    j = e.dump('json')          # Convert to JSON string
    puts e.dump('json')         # JSON formatted bounce data
  end
end

 

$ ruby test.rb

Sisimai::Data
Sisimai::Address
Sisimai::Time
kijitora@libsisimai.org
otsu-sakaba-hunter-neko-nyaaaaaaan@au.com
au.com
5.1.1
550
userunknown
{"catch":"","token":"1f154719d814ce60518f8113b1d00b2cb3edc6ca","lhost":"p225-ix4.kyoto.example.ne.jp","rhost":"msmx.au.com","alias":"","listid":"","reason":"userunknown","action":"failed","subject":"ニャーン","messageid":"C571433A-2457-47FA-B3E0-8F90AF58B3D9@libsisimai.org","replycode":"550","smtpagent":"Email::Sendmail","softbounce":0,"smtpcommand":"DATA","destination":"au.com","senderdomain":"libsisimai.org","feedbacktype":"","diagnosticcode":"550 <otsu-sakaba-hunter-neko-nyaaaaaaan@au.com>: User unknown","diagnostictype":"SMTP","deliverystatus":"5.1.1","timezoneoffset":"+0900","addresser":"kijitora@libsisimai.org","recipient":"otsu-sakaba-hunter-neko-nyaaaaaaan@au.com","timestamp":1526886600}

 

 

 

 

 

 

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)