2017年8月13日 星期日

Install Gitlab to own PC

Install Gitlab to own PC

1. Install and configure the necessary dependencies

sudo yum install curl policycoreutils openssh-server openssh-clients -y
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

2. Add the GitLab package server and install the package

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce -y

3. Configure and start GitLab

sudo gitlab-ctl reconfigure

4. Change hostname and port number

vim /etc/gitlab/gitlab.rb
===
external_url "http://localhost:9999" #change port to 9999
gitlab_rails['gitlab_shell_ssh_port'] = 9998 #change ssh port to xxxxx,if your ssh port changed

# set mail server(gmail)
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "my.email@gmail.com"
gitlab_rails['smtp_password'] = "my-gmail-password"
gitlab_rails['smtp_domain'] = "smtp.gmail.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'peer' # Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert', see http://api.rubyonrails.org/classes/ActionMailer/Base.html

===
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

Backup:
> /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
>  ls
1510848068_2017_11_17_9.4.4_gitlab_backup.tar

Auto Backup:
>vi /etc/crontab
=======
// Backup in  1st & 15th day month
0 0 1,15 * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
=======

Recovery:
Must same version gitlab
After set gitlab.rb
Stop gitlab servies
> gitlab-ctl stop unicorn
> gitlab-ctl stop sidekiq
> gitlab-ctl status

Paste the backup file to /var/opt/gitlab/backups/
> 1530366625_2018_06_30_10.1.4_gitlab_backup.tar

recovery (use timestamp of backup file)
> gitlab-rake gitlab:backup:restore BACKUP=1530366625_2018_06_30_10.1.4
> gitlab-ctl restart

Check gitlab:
> gitlab-rake gitlab:check SANITIZE=true

Update Gitlab:
1. Make a backup (Optional)
If you would like to make a backup before updating, the below command will backup data in /var/opt/gitlab/backups by default.

> sudo gitlab-rake gitlab:backup:create STRATEGY=copy

2. Update GitLab
Update to the latest version of GitLab.

> sudo yum install -y gitlab-ce


ref:
https://about.gitlab.com/installation/#centos-7

2017年8月12日 星期六

Mongo Repica Set 設定

首先設定讓所有PC接受SSH 認證

使用AP或dhcp server 鎖好每台電腦的IP

# 切換到root
su

# 接下來,修改hosts,讓主機們有不同的代號(使用x.x.x.160)
sudo vim /etc/hosts
===
192.168.1.160 mongodb-primary
192.168.1.161 mongodb-secondary
192.168.1.162 mongodb-arbiter
===

# 把修改好的hosts傳到每台機器
for i in {161..162};
do
sudo scp /etc/hosts root@192.168.1.$i:/etc/hosts
done;

# 新增mongodb 的repo
vim /etc/yum.repos.d/mongodb-org-3.4.repo
===
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
===
# 安裝mongodb
yum install -y mongodb-org

# 生成認證key碼
openssl rand -base64 741 > /var/lib/mongo/mongodb-keyfile
chmod 600 /var/lib/mongo/mongodb-keyfile
chown mongod.mongod /var/lib/mongo/mongodb-keyfile


# 把repo傳到每台機器,安裝mongo,key設定
for i in {161..162};
do
sudo scp /etc/yum.repos.d/mongodb-org-3.4.repo root@192.168.1.$i:/etc/yum.repos.d/mongodb-org-3.4.repo
ssh root@192.168.1.$i " yum install -y mongodb-org"
sudo scp /var/lib/mongo/mongodb-keyfile root@192.168.1.$i:/var/lib/mongo/mongodb-keyfile
ssh root@192.168.1.$i "
chmod 600 /var/lib/mongo/mongodb-keyfile;
chown mongod.mongod /var/lib/mongo/mongodb-keyfile;
";
done;

### CONFIG REPICA SET
mkdir /var/lib/mongo-cfg
chown -R mongod:mongod /var/lib/mongo-cfg

vim /etc/mongod.conf
====
# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

security: #security part edit by choon
  authorization: enabled
  clusterAuthMode: keyFile
  keyFile: /var/lib/mongo/mongodb-keyfile

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to All - edit by choon

replication:
  replSetName: config-server # - edit by choon

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid

#operationProfiling:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:
===

# 打開mongo
systemctl start mongod
# sudo mongod --config /etc/mongod.conf

# 打開其他台PC的mongo
for i in {163..164};
do
scp /etc/mongod.conf root@192.168.1.$i:/etc/mongod.conf
ssh root@192.168.1.$i "
systemctl start mongod
# mongod --config /etc/mongod.conf
"
done;

====

# 連結本地端
mongo 127.0.0.1
===
use admin
-------
db.createUser( {
    user: "root",
    pwd: "password#",
    roles: [ { role: "root", db: "admin" } ]
  });
------
use admin
# 登入
db.auth("root","password")
# intiate repica set
rs.initiate()
# 查看設定
rs.conf()
rs.add("mongodb-secondary")
rs.addArb("mongodb-arbiter")
rs.status()
exit
===


Ref:
https://docs.mongodb.com/manual/tutorial/deploy-replica-set/

2017年8月2日 星期三

PXE 結合 Kickstart 一鍵安裝CentOS

繼之前的PXE服務後(choons-world.blogspot.tw/2017/07/pxeos.html),這次結合CentOS Kickstart安裝Centos
讓使用者一健安裝好自定義的os

# 首先, 先建立一個ks檔案
vim /install/kickstart/firstKickStart.ks
====
#version=DEVEL
# System authorization information 使用加密協定sha512
auth --enableshadow --passalgo=sha512
# Use network installation
url --url="http://10.0.2.254/centos7"
# Use graphical install 用文字模式安裝
text
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information(hard pc:--device=eno1)
network  --bootproto=dhcp --device=enp0s3 --ipv6=auto --activate
network  --hostname=localhost.localdomain

# Root password(--plaintext abc1234) plaintext是明碼 iscrryted是sha512加密後的字串
rootpw --iscrypted $6$3cHk0s2ZwYgs5$B66RHGSUflDgFF1
# SELinux configuration
selinux --permissive
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Taipei --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# bootloader --append="rhgb quiet crashkernel=auto" --location=mbr
autopart --type=lvm

# Partition clearing information
clearpart --none --initlabel

# # Clear the Master Boot Record
# zerombr
# # Partition clearing information
# clearpart --all --initlabel --drives=sda
# # Disk partitioning information
# part /boot --asprimary --fstype="xfs" --size=5000
# part swap --asprimary --fstype="swap" --size=16384
# part / --asprimary --fstype="xfs" --grow


%packages
@^minimal
@core
chrony
kexec-tools

%end


######in packages #######
# @base
# @development
# @java-platform

%post
# add user and add to sudo list
# useradd -m -G wheel -s /bin/bash choon
# echo 'choon:choon123' | chpasswd
# mkdir /home/hadoop/.ssh/
# wget -q http://10.0.2.254/tftproot/ks/id_rsa.pub -O /home/choon/.ssh/authorized_keys
# wget -q http://10.0.2.254/tftproot/ks/id_rsa.pub -O /home/choon/.ssh/id_rsa.pub
# wget -q http:///10.0.2.254/tftproot/ks/id_rsa -O /home/choon/.ssh/id_rsa
# chmod 600 /home/choon/.ssh/id_rsa
# chown -R choon.choon /home/choon/.ssh/


# import GPG key for ssh
# mkdir /root/.ssh/
# wget -q http://10.0.2.254/tftproot/ks/id_rsa.pub -O /root/.ssh/authorized_keys
# wget -q http://10.0.2.254/tftproot/ks/id_rsa.pub -O /root/.ssh/id_rsa.pub
# wget -q http://10.0.2.254/tftproot/ks/id_rsa -O /root/.ssh/id_rsa
# chmod 600 /root/.ssh/id_rsa
######in packages #######


%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
# 限制密碼
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty
%end
========

vim /etc/httpd/conf.d/pxeboot.conf
=====加在後面=====
Alias /ks /install/kickstart

<Directory /install/kickstart>
        Options Indexes FollowSymLinks
        Require all granted
        Allow from 127.0.0.1 10.0.2.0/24 
</Directory>
=================

systemctl restart httpd

vim /install/tftpboot/pxelinux.cfg/default
====加在後面====
LABEL kickstart1
  MENU LABEL Boot from PXE Server for AUTO Install CentOS 7
  kernel ./kernel/centos7/images/pxeboot/vmlinuz
  append initrd=./kernel/centos7/images/pxeboot/initrd.img  ks=http://10.0.2.254/ks/firstKickStart.ks 
===============

ref:
http://linux.vbird.org/linux_enterprise/0120installation.php#pxe_installation

2017年7月29日 星期六

虛擬系統(VirtualBox) 安裝 Guest Additions (CentOS7為例)


# REDHAT家族系統 VirtualBox 最低記憶體768MB 空間至少8GB full install至少15GB

# 先安裝epel package
sudo yum -y install epel-release

#EPEL的全称叫 Extra Packages for Enterprise linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。

yum install dkms
yum groupinstall "Development Tools"
yum install kernel-devel

KERN_DIR=/usr/src/kernels/選最適合的kernel

之後用virtualbox載入Guest Additions CD image
如果有圖形介面,則autorun

沒圖形介面的話,則cd到mount CD的位置
然後執行 ./VBoxLinuxAdditions.run



ref :https://wiki.centos.org/HowTos/Virtualization/VirtualBox/CentOSguest
https://www.if-not-true-then-false.com/2010/install-virtualbox-guest-additions-on-fedora-centos-red-hat-rhel/

Centos7 XRDP 服務

使用rdp服務遠端控制centos7 GUI

# 安裝網絡工具 etc:ifconfig
yum install net-tools wget
# 獲得IP
ifconfig

# 安裝gui
yum -y groups install "GNOME Desktop"

# 先安裝epel package
yum install epel-release -y

# 安裝xrdp和tigervnc
yum -y install xrdp tigervnc-server
# 啟動xrdp
systemctl restart xrdp.service
# 查看xrdp狀態
netstat -antup | grep xrdp
# 預設啟動
systemctl enable xrdp.service

# 給firewall vnc的權限
firewall-cmd --permanent --zone=public --add-port=3389/tcp
firewall-cmd --reload

# chcon --type=bin_t /usr/sbin/xrdp
# chcon --type=bin_t /usr/sbin/xrdp-sesman

ref:
http://blog.jangmt.com/2015/09/centos-linux-7-xrdp-linux-rdp.html
http://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html

2017年7月27日 星期四

筆記-PXE環境,網絡安裝OS(以centos7為例)


# 登入ROOT
su -

# 關閉開機後預設打開selinux
vim /etc/sysconfig/selinux
====
SELINUX=disabled
====
# 目前關閉selinux(開機後恢復)
setenforce 0

# 安裝網絡工具 etc:ifconfig
yum install net-tools wget

# 安裝dhcp服務
# 主要用來分配IP,合指向pxe的server地址
yum install dhcp
mv /etc/dhcp/dhcpd.conf /etc/dhcpd.conf.bak
vim /etc/dhcp/dhcpd.conf
===
ddns-update-style interim;
ignore client-updates;

subnet 10.0.2.0 netmask 255.255.255.0 {

#        option routers                  192.168.1.1;
#       option subnet-mask              255.255.255.0;

        option domain-name-servers      10.0.2.254;

        range dynamic-bootp 10.0.2.11 10.0.2.100;
        default-lease-time 21600;
        max-lease-time 43200;

}
filename "pxelinux.0";
next-server 10.0.2.254;               #NFS服务器地址

===
#解釋一下其中几行,“subnet”和“netmask”根据你自己的网络环境来配置;“option routers”和“option domain-name-servers”这两个是路由器和DNS地址,可以不用配置,我配置了是因为我所在单位的其它计算机有可能会从这里获得IP,而不是从路由器获得,为了不影响他们正常上网才配置的;“range dynamic-bootp”这个是IP地址分配池,不要跟路由器的分配池重叠了

systemctl start dhcpd #必須在設定檔規定的網域才能打開,然後本機自己設固定ip
systemctl enable dhcpd

yum install tftp-server xinetd

#TFTP 其實是由 xinetd 這個 super daemon 所管理的,因此設定好 TFTP 之後, 你要啟動的是 xinetd 才對喔!
vim /etc/xinetd.d/tftp
# 鳥哥是將所有的資料統一放置於 /install/ 目錄下的!那這個 TFTP 的根目錄我們就將他放置於 /install/tftpboot 底下囉!
# =============
#  server_args             = -s /install/tftpboot  <== 重點在這裡!
# disable                     = no <==必須改
# =============

mkdir -p /install/tftpboot

# 給予ftp使用者權限(必要)
chcon --reference /var/lib/tftpboot /install/tftpboot
#[root@centos ~]# chcon --reference /var /install
#[root@centos ~]# ll -dZ /install/tftpboot

systemctl start xinetd
systemctl enable xinetd
systemctl enable tftp

# 給予tftp權限,這也是必要的
firewall-cmd --permanent --add-service=tftp
# 重開防火牆
firewall-cmd --reload

yum install syslinux  <==底下的檔案是由這軟體所提供!
cp /usr/share/syslinux/menu.c32  /usr/share/syslinux/vesamenu.c32 /usr/share/syslinux/pxelinux.0 /install/tftpboot/
mkdir /install/tftpboot/pxelinux.cfg
ll /install/tftpboot/
====
-rw-r--r--. 1 root root  60928 2013-04-02 18:10 menu.c32      <==提供類選單模式的功能
-rw-r--r--. 1 root root  26828 2013-04-02 18:10 pxelinux.0    <==就是開機管理程式!
drwxr-xr-x. 2 root root   4096 2013-04-02 18:11 pxelinux.cfg  <==開機的選單設定在這裡!
-rw-r--r--. 1 root root 162860 2013-04-02 18:41 vesamenu.c32  <==圖形化介面選單
====

mkdir /install/iso
cd /install/iso
wget http://ftp.ksu.edu.tw/pub/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso

# 將iso暫時掛載在 /mnt 底下來抓資料用:(我們需要安裝 Linux 系統,所以得要從原版光碟裡面將核心檔案撈出來~)
mount -o loop /install/iso/CentOS-7-x86_64-Minimal-1611.iso /mnt
mkdir -p /install/tftpboot/kernel/centos7
cp -fr /mnt/* /install/tftpboot/kernel/centos7
#cp /mnt/isolinux/vmlinuz /install/tftpboot/kernel/centos7/
#cp /mnt/isolinux/initrd.img /install/tftpboot/kernel/centos7/
cp /mnt/isolinux/isolinux.cfg /install/tftpboot/pxelinux.cfg/demo
umount /mnt

#centos7 不能直接使用kernel安裝,因此需要一個service放iso檔
yum install httpd
systemctl start httpd
systemctl enable httpd

vim /etc/httpd/conf.d/pxeboot.conf
===
Alias /centos7 /install/tftpboot/kernel/centos7

<Directory /install/tftpboot/kernel/centos7>
        Options Indexes FollowSymLinks
        Require all granted
        Allow from 127.0.0.1 10.0.2.0/24
</Directory>

===

systemctl restart httpd

# 給予http權限,這也是必要的
firewall-cmd --permanent --add-service=http
# 重開防火牆
firewall-cmd --reload


vim /install/tftpboot/pxelinux.cfg/default
===
UI vesamenu.c32        <== 使用 vesamenu.c32 這個類圖形的介面程式
TIMEOUT 300            <== 單位 0.1 秒,所以這個設定可等待 30 秒來進入預設開機
DISPLAY ./boot.msg     <== 提供一些額外的資訊,讓使用者更瞭解選單意義!
MENU TITLE Welcome to CHOON's PXE Server System
                       <== 上面這行只是提供一個大標題而已!
LABEL local            <== 第一個選單的項目
  MENU LABEL Boot from local drive
  MENU DEFAULT         <== 此選單為預設項目 (等待逾時就進入此開機)
  localboot 0          <== 本機磁碟開機的特定項目!

LABEL network1
  MENU LABEL Boot from PXE Server for Install CentOS 7
  kernel ./kernel/centos7/images/pxeboot/vmlinuz            <== 核心所在的檔名
  append initrd=./kernel/centos7/images/pxeboot/initrd.img  method=http://10.0.2.254/centos7 devfs=nomount <== 就是核心外帶參數啊!和iso裡檔案鏈接
# 上述設定中,大寫的文件部分要特別注意!那是使用 vesamenu.c32 的關鍵字!
# 至於後面的部分,那就是每個設定項目的內容囉!
===

vim /install/tftpboot/boot.msg
===
Welcome to CHOON's PXE Server System.

The 1st menu can let you system goto hard disk menu.
The 2nd menu can goto interactive installation step.
===

# 假如需要ftp的服務可以使用以下方式開通,帳號密碼是linux user
ftp: 使用自己的帳號登入
yum install vsftpd
systemctl enable vsftpd
systemctl start vsftpd

firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload

#參考來源
#http://linux.vbird.org/linux_enterprise/0120installation.php#pxe_dhcp
#http://tototo.blog.51cto.com/4567634/878509

2017年7月17日 星期一

筆記- Anaconda 安裝及使用

安裝Anaconda
前往官網 https://www.continuum.io/downloads 下載sh

bash Anaconda3-4.4.0-MacOSX-x86_64.sh #安裝設定

#新建環境
conda create --name crawlerPPT
#新增複製環境
conda create --name crawlerFB --clone crawlerPPT
#刪除環境
conda remove --name crawlerFB --all

#進入環境
source activate crawlerPPT
#退出環境
source deactivate crawlerPPT

#查看目前的環境
conda info --envs

#查看目前的環境
conda info --envs

#查看目前环境已安装的套件
conda list

#查看指定环境的套件
conda list -n python34

# 查找package信息
conda search numpy

# 安装套件
conda install numpy #在目前環境
conda install -n crawlerPPT numpy #cralerPPT環境

Centos GUI Webserver 設定

新灌的一台Centos7可以做以下的設定 語系設定: - sudo localectl set-locale LC_CTYPE=zh_TW.UTF-8 修改ssh port - http://linux.vbird.org/linux_server/0310telne...