2015/10/26

redmine with apache on centos7


from:http://www.redmine.org/projects/redmine/wiki/install_Redmine_25x_on_Centos_65_complete
yum -y install nano zip unzip libyaml-devel zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel gcc ruby-devel gcc-c++ make postgresql-devel ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA
 

 
 

from:http://blog.maxkit.com.tw/2014/11/centos-6-redmine.html
在/etc/httpd/conf.d/加上redmine.conf,並編輯redmine.conf加入以下的設定。
vi /etc/httpd/conf.d/redmine.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
    PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.53
    PassengerDefaultRuby /usr/bin/ruby
</IfModule>

RailsBaseURI /redmine
<Directory /var/www/redmine/public>
    # This relaxes Apache security settings.
    AllowOverride all
    Options -MultiViews
</Directory>
在DocumentRoot的路徑下加上redmine的symbolic link
ln -s /var/www/redmine/public /var/www/html/redmine
這個設定過程很重要,因為 redmine 官方只提供了以 virtual host 的方式跟 apache 整合,但我們希望用 http://localhost/redmine/ 的網址方式,連結 redmine,努力兩天後,得到上面的解決方案。

之後就是selinux的問題了,tail /var/log/audit/audit.log |audit2allow -M redmine1.pp
PS:因為執行過長,找到解決方法
http://tech.farend.jp/blog/2015/04/21/redmine-selinux/

インストール

“SELinuxを無効にする”の項は無視し、SELinuxをPermissiveモード(監視はするがアクセス制御はしない)にします。







1
setenforce 0
以降、最新版インストールガイド に従い、Redmineを構築します。

SELinuxの有効化と権限の付与

Redmineを構築し終えたら、以下のコマンドを実行します。







1
2
chcon -R -t httpd_sys_content_t /var/www/redmine/
setsebool -P httpd_unified on
Redmineのルートフォルダに対して「httpd_tというラベル付けがされたファイルから読み出される権限」を適用し、httpdによるファイルへの書き込み許可を設定しています。
最後に、SELinuxをEnforcingモードに戻します。







1
setenforce 1
以上です。
還有一個方式,沒有測試能否執行(還是要執行下面指令,為了結合LDAP驗證)
http://qiita.com/duloxetine/items/9a7285fd709e30ad9a62
# grep PassengerAgent /var/log/audit/audit.log | audit2allow -M passengeragent
# semodule -i passengeragent.pp
# grep ruby /var/log/audit/audit.log | audit2allow -M ruby
# semodule -i ruby.pp
# grep utils.rb:108 /var/log/audit/audit.log | audit2allow -M utils
# semodule -i utils.pp
因為LDAP帶來的資料有中文(或者輸入資料有中文問題),需要使用utf-8編碼,但是會遇到index太長的問題
原因:http://samyubw.blog.51cto.com/978243/223773
 得出的結論是:對於創建innodb的組合索引,如果各個列中的長度不超過767,則不再計算所有列的總長度,如果有超過767的,則給出報警,索引最後 創建成功,但是對於超過767字節的列取前綴索引;對於innodb的單列索引,超過767的,給出warning,最終索引創建成功,取前綴索引(取前 255字節)
解決方式:http://se-suganuma.blogspot.tw/2014/02/ruby-redmine-unicorninstallalminium.html
# vi /etc/my.cnf
# for Redmine
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix
# /etc/rc.d/init.d/mysqld restart
# vi config/initializers/adapt_utf8mb.rb
ActiveSupport.on_load :active_record do
  module ActiveRecord::ConnectionAdapters
    class AbstractMysqlAdapter
      def create_table_with_innodb_row_format(table_name, options = {})
        table_options = options.reverse_merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')
        create_table_without_innodb_row_format(table_name, table_options) do |td|
          yield td if block_given?
        end
      end
      alias_method_chain :create_table, :innodb_row_format
    end
  end
end
Try Again
# RAILS_ENV=production bundle exec rake db:migrate
無事完了。


加上GIT
http://redmine-git-hosting.io/get_started/
其中建立使用者git ,redmine改成apache
# Install dependencies (On Debian/Ubuntu)
root# apt-get install build-essential libssh2-1 libssh2-1-dev cmake libgpg-error-dev

# Install dependencies (On Fedora/CentoS/RedHat)
root# yum groupinstall "Development Tools"
root# yum install libssh2 libssh2-devel cmake libgpg-error-devel
# Switch user
root# su - redmine

# First git clone Bootstrap Kit
redmine$ cd REDMINE_ROOT/plugins
redmine$ git clone https://github.com/jbox-web/redmine_bootstrap_kit.git
redmine$ cd redmine_bootstrap_kit/
redmine$ git checkout 0.2.3

# Then Redmine Git Hosting plugin
redmine$ cd REDMINE_ROOT/plugins
redmine$ git clone https://github.com/jbox-web/redmine_git_hosting.git
redmine$ cd redmine_git_hosting/
redmine$ git checkout 1.1.4

# Install gems and migrate database
redmine$ cd REDMINE_ROOT
redmine$ bundle install --without development test
redmine$ bundle exec rake redmine:plugins:migrate RAILS_ENV=production NAME=redmine_git_hosting
.........
(從該來源網站按步驟)實施就可以正常安裝
第一次建立時,請下:
git init --bare
將git server初始化
至於管制方式,關鍵字:ssh ldap

或者vi /etc/password
將git由bin/bash變成bin/git-shell,原因:
出于安全的考虑,我们最好限制用户只能进行git push/pull,但无法登陆。这可以使用git-shell来完成。

會出現錯誤訊息: hint: ~/git-shell-commands should exist and have read and execute access

錯誤訊息參考:
http://nick.txtcc.com/index.php/linux/1116
  •  cp -Rf /usr/local/share/git-XXXX/contrib/git-shell-commands .
  •  # 再來改變權限
  •  chown -R git: git-shell-commands/
  •  chmod +x git-shell-commands/help
  •  chmod +x git-shell-commands/list


PS:selinux 再補充
https://mbrownnyc.wordpress.com/technology-solutions/rhodecode-and-redmine/part-4-redmine-on-apache/
其中PassengerTempDir:
The passenger_temp_dir option (Nginx) and the PassengerTempDir option (Apache) have been replaced by two config options. On Nginx they are passenger_instance_registry_dir and passenger_data_buffer_dir. On Apache they are PassengerInstanceRegistryDir and PassengerDataBufferDir. On Apache, PassengerUploadBufferDir has been replaced by PassengerDataBufferDir.
測試結果:殘念.....XD  not working..

redmine建立好,設定好,還是一直告知你empty:
http://redmine-git-hosting.io/troubleshooting/

My repository seems empty but I’m sure it is not!


A git clone of the repository gives me files!
root$ su - redmine
redmine$ cd REDMINE_ROOT
redmine$ bundle exec rake redmine_git_hosting:fetch_changesets RAILS_ENV=production




2015/10/21

cacti with SELinux


From:
http://docs.cacti.net/manual:087:1_installation.1_install_unix.8_selinux

SELinux Settings

SELinux setting greatly depend on which exact setup you are running. E.g. when installing Cacti into /var/www/html/cacti (which is the default installation location), the web server httpd usually has the required permissions to execute as required. But when e.g. installing into a private directory, e.g. ~/mycacti, you will have to provide specific SELinux settings.

Global SELinux Settings

This is an excerpt from my personal settings when installing into private directory. Any or all of them may be obsolete, when using the default location. Use -P option to make the change permanent

/usr/sbin/setsebool -P httpd_read_user_content=1
/usr/sbin/setsebool -P httpd_tty_comm=1
/usr/sbin/setsebool -P httpd_can_network_connect=1
/usr/sbin/setsebool -P httpd_builtin_scripting=1
/usr/sbin/setsebool -P httpd_enable_homedirs=1
/usr/sbin/setsebool -P httpd_enable_cgi=1

SELinux Settings for Plugins

BOOST

In case you are using BOOST server network setup, it was reported that
/usr/sbin/setsebool -P httpd_can_network_connect=1
 
 
 chcon -R -t httpd_sys_content_t /usr/share/cacti/
<==這句最重要 
 

mantis on CentOS 7 with AD


FROM:
http://eggchang.pixnet.net/blog/post/42099440-%E5%9C%A8-centos-7-%E4%B8%8A%E9%9D%A2%E5%AE%89%E8%A3%9D-mantis-%28microsoft-ad-%E8%AA%8D%E8%AD%89%29
http://eggchang.pixnet.net/blog/post/36649739-mantis-%2B-dokuwiki-%2B-subversion-%2B-active-directory---part-1


# 安裝 Mariadb (替代 MySQL 的 Database)
yum -y install mariadb mariadb-server mariadb-libs
# 安裝 Apache Web Server
yum -y install httpd mod_dav_svn
# 安裝 PHP
yum -y install php php-bcmath php-cli php-common php-enchant php-gd php-intl php-ldap php-mbstring php-mysql php-pdo php-pear php-process php-pspell php-recode php-soap php-xml php-xmlrpc rrdtool-php uuid-php php-pecl-memcache​ php-devel
# 安裝中文字型 (讓統計圖表可以正常顯示中文)
mkdir /usr/share/fonts/truetype
wget http://www.study-area.org/apt/firefly-font/fireflysung-1.3.0.tar.gz
tar xvzf fireflysung-1.3.0.tar.gz
cp fireflysung-1.3.0/fireflysung.ttf /usr/share/fonts/truetype/arial.ttf



# 提高 File Upload 檔案大小的上限到20MB
# vi /etc/php.ini
# 修改 upload_max_filesize = 20M
# 修改 max_file_uploads = 20
# 修改 post_max_size = 20M
# 修改 max_execution_time = 60
# 修改 memory_limit = 512M
# 修改 date.timezone 參數, 改為 date.timezone = 'Asia/Taipei'

=====================================
# 設定 SELinux
chcon -R -t httpd_sys_rw_content_t /var/www/html/mantis
setsebool -P httpd_can_sendmail on
setsebool -P httpd_can_network_connect on
chcon -R --reference /var/www/html/mantis /usr/share/fonts

PS:解決
SYSTEM WARNING: 'opendir(/var/www/html/mantis/plugins/): failed to open dir: Permission denied' in
=====================================
#mv admin admin-old
PS:web提示安全性問題

 使用ADsiedit來找AD資訊,後來改用ldp.exe查資料
ldp.exe-->connect -->BIND-->Account /Password-->Copy DN
將DN資訊修改到下面去
# 設定透過 AD/LDAP 認證與帳號
$g_login_method = LDAP;
$g_ldap_server = 'ldap://192.168.1.8/'; # Microsoft AD Domain Controller
#$g_ldap_port = 3268; # for AD Global Catalog Server (GC)
$g_ldap_root_dn = 'OU=XXXXXX,DC=axman,DC=com,DC=tw'; # 看 Users 是放在哪個位置
$g_ldap_bind_dn = 'Domain\UserNAME'; # 用來連接並查詢 AD 的帳號, 給一般 User 即可
$g_ldap_bind_passwd = 'PASSWORD';
$g_use_ldap_email = ON; # 用 AD 帳號的 Mail 作為 Mantis 裡面的 Mail
$g_ldap_uid_field = 'sAMAccountName';
$g_ldap_realname_field = 'cn'; # 以 AD 帳號的 CN 屬性做為顯示名稱
$g_use_ldap_realname = ON; # 用 AD 帳號的顯示名稱 (CN) 顯示在 Mantis 上
$g_ldap_organization = '';
$g_ldap_protocol_version = 3;
$g_allow_signup = OFF; # 設定不可申請帳號 (用AD/LDAP帳號登入就自動建立帳號, 因此不須申請)
$g_send_reset_password = OFF; # 設定不可以重設 Password (因為 Password 是 AD/LDAP 在控制, Mantis 不能修改)


# 設定傳送郵件的方式與寄件人

$g_administrator_email  = 'Mantis@axman.com.tw';
$g_webmaster_email      = 'mis@axman.com.tw';
$g_from_email      = 'Mantis@axman.com.tw'; # Mantis 以誰的名義寄信 (From)
$g_return_path_email    = 'Mantis@axman.com.tw';
$g_phpMailer_method = 2;
$g_smtp_host = '192.168.1.248'; # SMTP 的位置
$g_smtp_username = ''; # 若 SMTP 需要登入, 則於此設定登入 SMTP 的帳號
$g_smtp_password = ''; # 若 SMTP 需要登入, 則於此設定登入 SMTP 的密碼
$g_enable_email_notification = ON;
$g_log_destination = 'file:/var/www/html/mantis/log/mail.log'; # 寄信後留個紀錄
$g_log_level = LOG_EMAIL_RECIPIENT;

    # 檔案上傳設定

$g_allow_file_upload = ON; # 允許上傳檔案
$g_max_file_size = 20000000; # 設定上傳檔案的大小限制 (最大20M), 除此之外, 前面章節的 php.ini 亦需有相對應的設定
$g_file_upload_max_num = 10; # 最多可同時上傳10個檔案
$g_file_upload_method = DATABASE; # 上傳檔案放置的位置為資料庫. 若想放在 File System, 則設為 DISK
$g_absolute_path_default_upload_folder = '/var/www/html/mantis/attachment'; # 上傳檔案的目錄, $g_file_upload_method = DISK 時需要設定
$g_preview_attachments_inline_max_size = 5120000; # 超過 512KB 的圖形檔不允許預覽

# 打開 Time Tracking 功能 (負責解決 Issue 的人可以輸入處理 Issue 所耗的工時)

$g_time_tracking_with_billing = ON;
$g_time_tracking_enabled = ON;
$g_time_tracking_stopwatch = ON;
$g_time_tracking_view_threshold = DEVELOPER;
$g_time_tracking_edit_threshold = DEVELOPER;
$g_time_tracking_reporting_threshold = MANAGER;
$g_time_tracking_without_note = OFF;

# 其他設定

#$g_path = 'http://webproject.axman.com.tw/mantis/'; # 網址
$g_max_failed_login_count = 5; # 登入失敗最多五次, 超過鎖帳 (Mantis 的帳號)
$g_show_version = OFF; # 不要顯示 Mantis 版本 (網路安全考慮)
$g_default_language = 'english'; # 新建立的使用者預設語系 (若要改為中文則設定為 'chinese_traditional')
$g_window_title = ' <顯示在瀏覽器上方的文字>'; # 瀏覽器標題顯示的文字
$g_show_realname = ON; # 顯示使用者的顯示名稱 (預設是顯示登入帳號, 通常是一串難記的號碼)
$g_short_date_format = 'Y/m/d'; # 短日期格式
$g_normal_date_format = 'Y/m/d H:i'; # 一般日期格式
$g_complete_date_format = 'Y/m/d H:i'; # 長日期格式
$g_default_language     = 'chinese_traditional';  ##預設繁體中文

注意一點:
只要用 Windows Domain 的帳號與密碼登入, Mantis 會自動建立新的使用者, 並賦予 Reporter 的權限, 因此不需要 Administrator 再手動建立. 惟若有專案的需要比較高的機密, 則該專案應該設定為 "非公開", 並明確指定哪些帳號才有權限, 以避免任意的 Domain User 登入後都可以看到所有專案的內容



關於SElinux的檢查


From:
http://www.thedumbterminal.co.uk/posts/2010/07/how_to_troubleshoot_selinux_problems.html

PS:用tail或者cat都可以

cat /var/log/audit/audit.log /var/log/messages | audit2allow
semodule -i mysemanage.pp
 
SELinux errors are logged to syslog by default in Cenntos they are logged to the following file locations:
  • /var/log/audit/audit.log
  • /var/log/messages
其中audit2allow在setroubleshoot套件中

 chcon
 傳統的 chmod 指令是用來設定檔案或目錄的權限的,而同樣的 chcon 指令則是用來設定 SELinux 對檔案或目錄的 content 標籤的

From:http://dywang.csie.cyut.edu.tw/moodle23/dywang/rhcsaNote/node77.html

  • 產生 SELinux 允許的政策模組。
    [root@ip180 ~]# audit2allow -a -M mycertwatch
    ******************** IMPORTANT ***********************
    To make this policy package active, execute:
    
    semodule -i mycertwatch.pp
    
  • 查看產生的模組。
    [root@ip180 ~]# ll mycertwatch*
    -rw-r--r--. 1 root root 885 Jul  1 09:39 mycertwatch.pp
    -rw-r--r--. 1 root root 211 Jul  1 09:39 mycertwatch.te
    
  • 加入新產生的 SELinux 政策模組。
    [root@ip180 ~]# semodule -i mycertwatch.pp
    
  • 查詢 SELinux 模組
    [root@ip180 ~]# semodule -l | grep mycert
    mycertwatch 1.0
    
  • 上述的政策允許某一拒絕,執行時可能還會出現新的拒絕。依同樣的方式再做一次,直到可以為止。
    [root@ip180 ~]# audit2allow -a -M mycertwatch2
    ******************** IMPORTANT ***********************
    To make this policy package active, execute:
    
    semodule -i mycertwatch2.pp
    
    [root@ip180 ~]# semodule -i mycertwatch2.pp
    
     





  •  
     

    MySQL各類引擎對比



    FROM:
    http://blog.roga.tw/2008/11/mysql-%E8%B3%87%E6%96%99%E5%BA%AB%E5%84%B2%E5%AD%98%E5%BC%95%E6%93%8E%E7%9A%84%E9%81%B8%E7%94%A8/
    http://ssorc.tw/663
    http://twpug.net/docs/mysql-5.1/pluggable-storage.html
    簡而言之:
    項目 MyISAM InnoDB Memory
    空間限制 64TB 記憶體
    transaction x x
    大量 Insert 速度
    設置外來鍵 x x
    鎖定層級 資料表 資料列 資料表
    二元樹索引 不知
    雜湊索引 x
    全文搜尋索引 x x
    資料壓縮 x x
    資料快取 x
    索引快取
    記憶體佔用
    磁碟佔用 x

    MyISAM 來說,最大的好處是成本低,而且可以 create views
    InnoDB 也是有缺點像是不支援 FULLTEXT 的索引,且記憶體佔用多、磁碟空間耗用大
    下述儲存引擎是最常用的:
    · MyISAM:預設的MySQL插件式儲存引擎,它是在Web、數據倉儲和其他應用環境下最常使用的儲存引擎之一。注意,通過更改STORAGE_ENGINE配置變數,能夠方便地更改MySQL伺服器的預設儲存引擎。
    · InnoDB:用於事務處理應用程式,具有眾多特性,包括ACID事務支援。
    · BDB:可替代InnoDB的事務引擎,支援COMMIT、ROLLBACK和其他事務特性。
    · Memory:將所有數據保存在RAM中,在需要快速搜尋引用和其他類似數據的環境下,可提供極快的訪問。
    · Merge:允許MySQL DBA或開發人員將一系列等同的MyISAM資料表以邏輯方式組合在一起,並作為1個對象引用它們。對於諸如數據倉儲等VLDB環境十分適合。
    · Archive:為大量很少引用的歷史、歸檔、或安全審計訊息的儲存和檢索提供了完美的解決方案。
    · Federated:能夠將多個分離的MySQL伺服器連結起來,從多個物理伺服器建立一個邏輯資料庫。十分適合於分佈式環境或數據集市環境。
    · Cluster/NDB:MySQL的叢集式資料庫引擎,尤其適合於具有高性能搜尋要求的應用程式,這類搜尋需求還要求具有最高的正常工作時間和可用性。
    · Other:其他儲存引擎包括CSV(引用由逗號隔開的用作資料庫資料表的檔案),Blackhole(用於臨時禁止對資料庫的應用程式輸入),以及Example引擎(可為快速建立定製的插件式儲存引擎提供幫助)。
    請記住,對於整個伺服器或方案,您並不一定要使用相同的儲存引擎,您可以為方案中的每個資料表使用不同的儲存引擎,這點很重要。

    2015/10/16

    BootStrap 的重點


    TALBE、datepick

    注意:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    這個千萬不要宣告4.01只要保留
    <!DOCTYPE HTML>就好
    不然版面都會一堆亂七八糟的問題
     
    必要宣告:
     <link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" href="data:text/css;charset=utf-8," data-href="css/bootstrap-theme.min.css"
     id="bs-theme-stylesheet">
    
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/prettify.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.min.css">
    <link rel="stylesheet" href="css/bootstrap-editable.css">
    
    
    
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    
    <script type="text/javascript" src="js/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/locale/bootstrap-table-zh-TW.min.js"></script>
    <script src="js/extensions/export/bootstrap-table-export.js"></script>
    <script src="js/extensions/editable/bootstrap-table-editable.js"></script>
    
    <script type="text/javascript" src="js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/locales/bootstrap-datetimepicker.zh-TW.js" charset="UTF-8"></script>
     
     

    JPA+complex key+custom Query

      來源: https://www.cnblogs.com/520playboy/p/6512592.html   整個來說,就是有複合主鍵 然後要使用  public interface XxXXxx DAO extends CrudRepository<Tc...