Git Server 安裝

OS: Ubuntu 12.04 Desktop x64

安裝Gitlab + MySQL

  1. 系統更新
apt-get update
apt-get upgrade -y
apt-get dist-upgrade
  1. 安裝基本需求
update-alternatives --set editor /usr/bin/vim.basic
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate
  1. 安裝python
sudo apt-get install -y python
python --version
python2 --version
# 確認 python版本,如果版本是3.x以上,則需額外安裝2.x版
# sudo apt-get install -y python2.7
# python --version # Python 2.7.3

# python2 --version # 命令執行會採用 python2, 所以需要確認 python2 的版本
# python2 不存在的話, 需要把 python 2.7 版 的 ln 過去.
# sudo ln -s /usr/bin/python /usr/bin/python2

apt-get install -y python-docutils
  1. 安裝Git
# 檢查Git目前可apt安裝的版本
apt-cache showpkg git-core

# 如果版本大於1.7.10,則可以直接使用~否則建議手動安裝新版本
# 直接安裝 => apt-get install -y git-core
# 如果原本就安裝舊有版本,移除 => apt-get remove git-core

# 手動安裝Git
apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.9.0.tar.gz | tar xz
cd git-1.9.0/
make prefix=/usr/local all
make prefix=/usr/local install
  1. 安裝postfix,以便後續提供發信服務
# 選擇Internet Site並輸入Domain Name
apt-get install -y postfix
  1. 安裝Ruby
# 如果裝有1.8版,先行移除
# apt-get remove ruby1.8

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz | tar xz
cd ruby-2.0.0-p481/
./configure --disable-install-rdoc
make -j  `cat /proc/cpuinfo | grep 'cpu cores' | awk '{if ($4=1) print $4; else print $4-1}'`
make install
gem install bundler --no-ri --no-rdoc
  1. 新增Gitlab系統帳號
adduser --disabled-login --gecos 'GitLab' git
  1. 安裝GitLab Shell
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell

#查看最新版本為何
sudo -u git -H git tag 

sudo -u git -H git checkout v1.9.6
sudo -u git -H cp config.yml.example config.yml

#修改gitlab_url,改成要使用的domain
sudo -u git -H editor config.yml

sudo -u git -H ./bin/install
  1. 安裝MySQL Database
apt-get install -y mysql-server mysql-client libmysqlclient-dev
mysql -u root -p
> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'GITLAB_PASSWORD';
> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
>GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

# 使用gitlab帳號測試MySQL
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
  1. 安裝GitLab
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab

# 檢查版本,找stable的
sudo -u git -H git branch -a

sudo -u git -H git checkout 7-0-stable
  1. 設定GitLab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# 所有 localhost 改成要使用的domain. 
# /usr/bin/git 改成 /usr/local/bin/git
sudo -u git -H editor config/gitlab.yml

#調整檔案權限
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
chmod -R u+rwX  tmp/pids/
chmod -R u+rwX  tmp/sockets/
sudo -u git -H mkdir public/uploads
chmod -R u+rwX  public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
chmod -R u+rwX  public/uploads
sudo -u git -H mkdir public/uploads

#如果硬體記憶體規格超過2G,可將worker_processes改成3
#sudo -u git -H editor config/unicorn.rb

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
  1. GitLab DB設計
sudo -u git cp config/database.yml.mysql config/database.yml

# 將production區塊的secure password值改成MySQL gitlab帳號設定的帳號、密碼
sudo -u git -H editor config/database.yml

sudo -u git -H chmod o-rwx config/database.yml
  1. 安裝Gems
cd /home/git/gitlab
sudo -u git -H bundle install --deployment --without development test postgres aws
  1. 初始化 Database
# 問啥就輸入yes以便建立Database
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# 取得系統預設帳號、密碼 (所有新安裝都一樣,務必要更改)
Administrator account created:
    login.........admin@local.host
    password......5iveL!fe
  1. 設定開機自動啟動
cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
update-rc.d gitlab defaults 21
  1. 設定Logtotate
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  1. 檢查GitLab應用程式設定狀態
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  1. 啟動GitLab
service gitlab start

19.安裝、設定apache2

apt-get install apache2
cd /tmp
wget https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/apache/gitlab.conf

# 修改ServerName => 使用的Domain
# 修改ProxyPassServerse => (http://127.0.0.1:8080) 及 (http://使用的domain)
# 修改Log => /var/log/httpd/logs/ 改成 /var/log/apache2/
vim gitlab.conf

mv gitlab.conf /etc/apache2/sites-enabled/

# 將整個檔案註解,最前面加上'#'
vim /etc/apache2/sites-enabled/000-default

a2enmod  rewrite proxy proxy_http
service apache2 restart
  1. 用網頁連線到http://使用的domain以上面取得的帳號密碼進行測試
Posted in Git, Ubuntu | Leave a comment

Git : non-fast-forward

當進行 gir push 發生 “non-fast-forward” 錯誤時 (如下面這個範例)

root@ubuntu:/mnt/tdg_logs/blacklist/Git/master# git push -u 20140821 master
Enter passphrase for key '/root/.ssh/id_rsa': 
To git@cowman.no-ip.org:udn/udn_php-domain_name_query.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@cowman.no-ip.org:udn/udn_php-domain_name_query.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

會有幾個可能性, 可以透過 git status 先查看是不是有需要手動 merge 的部分
假設有出現 Unmerged paths 的資訊就是需要手動處理一下

root@ubuntu:/mnt/tdg_logs/blacklist/Git/master# git status
# On branch master
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#   both added:         JobDaemon.php
#   both added:         ReadME
#   both added:         daily.sh
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#   20140801/
#   20140815.zip
#   20140821.zip
#   JobDaemon.php.bak
no changes added to commit (use "git add" and/or "git commit -a")

這時候就要針對 JobDaemon.php、ReadME、daily.sh 進行編輯
在檔案中可以看到

<<<<<<<<<< HEAD 
要新推上去的檔案內容
==========
原始branch的檔案內容
>>>>>>>>>>>

目前是先保留新推上去的檔案內容為主~將<<<、===、原始的內容、>>>刪除後重新 git add、git commit 後重新push即可

另外一個可能性是要進行 git pull 要推上去的remote 要推到的branch名稱

 
root@ubuntu:/mnt/tdg_logs/blacklist/Git# git pull 20140825 master
Enter passphrase for key '/root/.ssh/id_rsa': 
warning: no common commits
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 18 (delta 7), reused 0 (delta 0)
Unpacking objects: 100% (18/18), done.
From cowman.no-ip.org:udn/udn_php-domain_name_query
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
root@ubuntu:/mnt/tdg_logs/blacklist/Git# git push 20140825 master
Enter passphrase for key '/root/.ssh/id_rsa': 
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 305 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To git@cowman.no-ip.org:udn/udn_php-domain_name_query.git
   07152a6..ccd7420  master -> master
 
Posted in Git | Leave a comment

Vim 7.4 Backspace失效

差一點因為backspace失效就要把好不容易裝起來的Vim 7.4移除掉改裝yum的rpm了…….

原來只要輸入 “set backspace=2” 就可以了
所以可以將這一行放到 ~/.vimrc 中就可以了

Posted in Linux | Leave a comment

Ubuntu Domain Name 設定

Ubuntu 的 domain name 設定不像以往 Centos直接修改 /etc/resolv.conf 即可,
因為重開機, 理面的值會不見
仔細看了一下, 在開頭的地方寫著:

 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

所以我一直都再做白工……
原來 Ubuntu 的 domain name 設定也是在 /etc/network/interface 裡面

dns-nameservers 8.8.8.8 8.8.4.4 168.95.1.1
Posted in Ubuntu | 1 Comment

Resize Virtual Disk – VMware ESXi 4.1 & CentOS 5.5 x86

  1. 使用vSphere Client登入調整硬體的設定,將硬碟空間增大 (由20G -> 80G)
    20140813

  2. 將VM Guest重開機

  3. 以ssh登入VM Guest

  4. 輸入fdisk -l取得目前磁碟資訊

[root@localhost ~]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM
  1. 根據4回傳的資訊,輸入fdisk /dev/sda
[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

[備註]
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

  1. 輸入 p 取得目前的資訊
Command (m for help): p

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM
  1. 輸入 n 創建新的partition,接著按兩下Enter,以使用最小及最大的數值 (使用完整的free空間)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-10443, default 2611): 
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-10443, default 10443): 
Using default value 10443 
  1. 輸入 t 更改系統ID,選擇第3個partition,直接輸入8e
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
  1. 輸入 w 將設定寫入硬碟
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 裝置或系統資源忙碌中.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
  1. 將 VM Guest 重新開機

  2. 輸入 fdisk -l 可以看到剛剛新增的sda3
    </pre lang=”bash”>[root@localhost ~]# fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2610 20860402+ 8e Linux LVM
/dev/sda3 2611 10443 62918572+ 8e Linux LVM

  1. 使用 pvcreate 創建 volume
[root@localhost ~]# pvcreate /dev/sda3 
  dev_is_mpath: failed to get device for 8:3
  Writing physical volume data to disk "/dev/sda3"
  Physical volume "/dev/sda3" successfully created
  1. 使用 vgextend 將 sda3 加入 VolGroup00
[root@localhost ~]# vgextend VolGroup00 /dev/sda3 
  Volume group "VolGroup00" successfully extended
  1. 使用 vgdisplay 查詢 VolGroup00 未使用的空間為 60G
[root@localhost ~]# vgdisplay VolGroup00 | grep "Free"
  Free  PE / Size       1920 / 60.00 GB
  1. 使用 lvextend 增加空間 (從14可以得知為60G)
[root@localhost ~]# lvextend -L+60G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 77.88 GB
  Logical volume LogVol00 successfully resized
  1. 使用 resize2fs 修改分割區大小
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 20414464 (4k) blocks.

The filesystem on /dev/VolGroup00/LogVol00 is now 20414464 blocks long.
  1. 輸入 df -h 驗證有沒有成功
[root@localhost ~]# df -h
檔案系統              容量  已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
                       76G   14G   58G  20% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 506M     0  506M   0% /dev/shm

參考資訊: Extending a logical volume in a virtual machine running Red Hat or Cent OS (1006371)

Posted in CentOS, VMware | Leave a comment

Sublime Text 2 修改Tab設定

預設的Tab = 4個Spaces 寬度,這邊將它調整為2個Spaces寬度

Preferences -> Settings – More -> Syntax Specific -User
加入以下內容
{
“tab_size”: 2,
“translate_tabs_to_spaces”: true
}

Posted in Sublime Text 2 | Leave a comment

Sublime Text 2 install PHP-Beautifier

環境:Windows 7 x64

  1. 安裝 PHP
    1.1 http://windows.php.net/download/,選擇Installer最新版本下載安裝
    1.2 將PHP安裝路徑加至Windows系統環境變數Path內

  2. 安裝php pear
    2.1 下載http://pear.php.net/go-pear.phar至PHP目錄下
    2.2 使用命令提示字元(以系統管理者啟動),切換至PHP目錄,輸入php go-pear.phar進行安裝
    2.3 PHP目錄下會產生Pear_ENV.reg檔案,將它加入至系統內

  3. PHP安裝PHP_Beautifier
    3.1 在PHP目錄下,輸入pear install PHP_Beautifier-0.1.15進行安裝
    3.2 修改PHP目錄下的php_beautifier,將error_reporting(E^ALL)修改為error_reporting(0),大約在第55行
    3.3 修改PHP目錄下的php_beautifier.bat,將所有的改為/
    3.4 修改PHPpearPHPBeautifierFilter目錄下的Pear.filter.php及phpBB.filter.php,將require_once (‘PEAR/Config.php’);註解

  4. Sublime Text 2安裝PHP_beautifier
    4.1 Sublime Text 2安裝Package Control,進入Console模式(ctrl+`),輸入import urllib2,os; pf=’Package Control.sublime-package’; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),’wb’).write(urllib2.urlopen(‘http://sublime.wbond.net/’+pf.replace(‘ ‘,’%20’)).read()); print ‘Please restart Sublime Text to finish installation’
    4.2 Perference -> Package Control (Ctrl+Shift+p),輸入install,輸入php beautifier進行安裝
    4.3 Perference -> Browse Packages,進入Pcakages套件目錄,切換至Phpbeautifier目錄,編輯php_beautifier.py,將26行的cmd = “php_beautifier”修改為”cmd = “PHP目錄/php_beautifier.bat”” <== 注意這邊的符號要打成/

Posted in PHP, Sublime Text 2 | Leave a comment

取得網路時間 (非更新系統時間)

Source: http://superuser.com/questions/635020/how-to-know-current-time-from-internet-from-command-line-in-linux

方法1

$ nc time.nist.gov 13
# Both commands query the timer server on TCP port 13 of the National Institute of Standards and Technology and output the received data on stdout.

nc 指令說明
This is nc from the netcat-openbsd package. An alternative nc is available in the netcat-traditional package.
usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]

方法2

$ curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g'
# 取得google首頁上的時間標計
Posted in Linux | Leave a comment

Post 檔案至Web CGI

  1. 第一種方式,linux curl command
curl -vv --cookie "Session=798434368" --data-binary @RoxioMediaManager_test4_AAC-LC_v4_Stereo_CBR_64kbps_44100Hz_ok.aac http://192.168.251.156/CGI/MobileAudio
  1. 第二種方式,PHP cUrl
"@".$local_directory.$_GET['file'],
        //利用get取得檔案名稱
        "upload"=>"Upload"
    );

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);

    $response = curl_exec($ch);

    curl_close($ch);

    var_dump('$response:');
    var_dump($response);
}

mobileAudio();
Posted in PHP | Leave a comment

PHP 下拉檔案選單

n";
    foreach (new DirectoryIterator('/var/www/b30_bak') as $file) {
    //指定web server上的路徑位置
        $filetype = pathinfo($file, PATHINFO_EXTENSION);
        if (in_array(strtolower($filetype), $filetypes)) {
        //如果符合副檔名設定才秀出來
            echo 'n";
        }
    }
    echo '
'; ?>
Posted in PHP | Leave a comment