Hobo Chen

Linux Memo

Linux all in ONE.

Bootstrap Ubuntu

1
2
3
4
5
6
7
8
sudo apt update && sudo apt upgrade -y
sudo apt install sysstat net-tools htop iftop wget tmux curl zsh \
vim git build-essential \
python3 openjdk-11-jdk clang ghc texlive-full \
gnome-tweak-tool lm-sensors
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# to store local time in bios, to resolve compatibility issue when dual boot windows
timedatectl set-local-rtc 1

System Tune

Tune Max Open Files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 系统
echo 'fs.file-max = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# 用户
sudo tee -a /etc/security/limits.conf << EOF
* hard nofile 65535
* soft nofile 65535
root hard nofile 65535
root soft nofile 65535
EOF

# Systemd
sudo sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=65535' /etc/systemd/*.conf
sudo systemctl daemon-reexec

hd-idle

Github Page.

1
2
3
4
5

# /etc/default/hd-idle

START_HD_IDLE=true
HD_IDLE_OPTS="-i 120 -d -l /var/log/hd-idle.log"

Add Swap and Mount

Add Swap:

1
2
3
4
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Check if works:

1
free -h

System Maintainance Manual

Add New Disk

1
sudo fdisk -l

to partition:

1
sudo fdisk /dev/sdb

Then type:

1
2
3
4
g # create a new GPT disk lable
n # new partition, i only add one partition is this disk,
# so i press enter for two times then
w # write the changes

format:

1
sudo mkfs -t ext4 /dev/sdb1 # use ext4 file system

mount:

1
2
mkdir ~/flush
sudo mount /dev/sdb1 ~/flush

Then check the new disk.

1
df -h

auto mount:

1
sudo vim /etc/fstab

Add this line in the end of file.

1
/dev/sdb1	/home/hobochen/flush ext4 defaults 0 0

install

1
sudo apt install zfsutils-linux

some notes:

  1. Use ECC mem.
  2. Persistence in the L2ARC is not needed.
  3. watch: https://www.youtube.com/watch?v=ptY6-K78McY
  4. learn some filesystem
  5. TODO

Installing Software Manual

Install glog

I want to install Google Log(C++) in my Ubuntu, but I met the problem:
/usr/bin/ld: //usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32 against .rodata.str1.1' can not be used when making a shared object; recompile with -fPIC.

The cause is that the gflags is not compiled as shared libraries when installing.
Here is a solution.

Jump to gflags directory, and run ccmake .. Change the BUILD_SHARED_LIBS to ON.

If you found that ccmake is not found.

1
sudo apt install cmake-curses-gui

Then, jump back to glog directory, run:

1
make -j`nproc` && sudo make install

Gitlab

install

1
2
3
4
sudo apt update
sudo apt install -y curl openssh-server ca-certificates
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt install gitlab-ce

Conf file is: /etc/gitlab/gitlab.rb

If machine has a real FQDN:

1
external_url 'http://gitlab-hz.192217.space'

memory tune

1
2
3
4
5
puma['per_worker_max_memory_mb'] = 512
puma['worker_processes'] = 4
sidekiq['concurrency'] = 16
prometheus['enable'] = true
postgresql['shared_buffers'] = "512MB" # **recommend value is 1/4 of total RAM, up to 14GB.**

to use external smtp service

1
2
3
4
5
6
7
8
9
10
gitlab_rails['gitlab_email_from'] = 'hobochen96@qq.com'
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_password'] = "say_you_love_me"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_user_name'] = "hobochen96"

sudo gitlab-ctl reconfigure to make changes effective.

to back up

meta:

1
2
/etc/gitlab/gitlab-secrets.json
/etc/gitlab/gitlab.rb

data:

1
sudo gitlab-rake gitlab:backup:create

to restore

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo cp _file /var/opt/gitlab/backups/
sudo chown git.git /var/opt/gitlab/backups/_file

sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq

# Verify
sudo gitlab-ctl status

# This command will overwrite the contents of your GitLab database!
sudo gitlab-rake gitlab:backup:restore BACKUP=1493107454_2018_04_25_10.6.4-ce

# Restore the meta

sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true

Ref:

  1. https://docs.gitlab.com/ee/raketasks/backup_restore.html