Skip to content

Instantly share code, notes, and snippets.

@showsky
Last active December 1, 2022 06:09
Show Gist options
  • Save showsky/faa45586419b3178791847fb1a4283fa to your computer and use it in GitHub Desktop.
Save showsky/faa45586419b3178791847fb1a4283fa to your computer and use it in GitHub Desktop.
Ubuntu Install ToDO List

Ubuntu Install Memo

Install Software

api update && apt install \
    git tig screen curl wget zsh fail2ban \
    nginx mysql-server \
    php-fpm php-cli \
    php-redis php-pdo php-dom php-mysqli php-intl \
    certbot python-certbot-nginx
mkdir /home/www-data
chown www-data:www-data /home/www-data
chmod 774 /home/www-data
chmod g+s /home/www-data

usermod -a -G www-data showsky

Config

  • oh-my-zsh [.zshrc]

    ...
    
    theme="candy"
    
    ...
    
    plugins=(git zsh-autosuggestions)
    
    ...
    
    
  • screen [.screenrc]

    startup_message off
    
    # if we accidentally hangup, don't be all attached when we come back.
    autodetach on
    
    # more scrollbacks!
    defscrollback 10000
    
    # disable use of the "alternate" terminal
    # thus allowing scrollbars to function as normal in
    # many terminal emulators! <3 it
    termcapinfo xterm* ti@:te@
    
    # have screen update terminal emulators titlebar
    termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
    defhstatus "screen ^E (^Et) | $USER@^EH"
    
    # but dont print i.e. "bell in window 0" status craps
    #hardstatus off
    
    shelltitle "$ |bash"
    
    hardstatus alwayslastline
    hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
    
    defflow off
    
    #rvm needs this
    shell -${SHELL}
    
  • vim [.vimrc]

    " 檔案編碼
    set encoding=utf-8
    set fileencodings=utf-8,cp950
     
    " 編輯喜好設定                                                                                                                                                                                                     
    syntax on        " 語法上色顯示
    set nocompatible " VIM 不使用和 VI 相容的模式
    " set ai           " 自動縮排
    set shiftwidth=4 " 設定縮排寬度 = 4 
    set tabstop=4    " tab 的字元數
    set softtabstop=4
    set expandtab   " 用 space 代替 tab
     
    set ruler        " 顯示右下角設定值
    set backspace=2  " 在 insert 也可用 backspace
    set ic           " 設定搜尋忽略大小寫
    set ru           " 第幾行第幾個字
    set hlsearch     " 設定高亮度顯示搜尋結果
    set incsearch    " 在關鍵字還沒完全輸入完畢前就顯示結果
    set smartindent  " 設定 smartindent
    set confirm      " 操作過程有衝突時,以明確的文字來詢問
    set history=100  " 保留 100 個使用過的指令
    set cursorline   " 顯示目前的游標位置
     
    set laststatus=2
    set statusline=%4*%<\%m%<[%f\%r%h%w]\ [%{&ff},%{&fileencoding},%Y]%=\[Position=%l,%v,%p%%]
     
    colorscheme torte
    
  • fail2ban [jail.local]

    [DEFAULT]
    destemail = showsky@gmail.com
    sendername = Fail2Ban
    mta = sendmail
    action = %(action_mwl)s
    
    [sshd]
    enabled = true
    port = ssh
    filter = sshd
    logpath = /var/log/auth.log
    maxretry = 3
    bantime = 600
    
    [mysqld-auth]
    enabled = true
    port = 3306
    filter = mysqld-auth
    logpath  = /var/log/mysql/error.log
    maxretry = 5
    

MySQL

> SELECT user, host, plugin FROM mysql.user;

+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | auth_socket           |
+------------------+-----------+-----------------------+
  • Create User

    # Create Account
    
    CREATE USER 'fitness'@'localhost' IDENTIFIED BY 'password';
    
    GRANT ALL PRIVILEGES ON fitness.* TO 'fitness'@'localhost';
    
    FLUSH PRIVILEGES;
    
    # Create Super Account
    
    CREATE USER 'showsky'@'localhost' IDENTIFIED BY 'password';
    
    GRANT ALL PRIVILEGES ON*.* TO 'fitness'@'localhost';
    
    

Git Config

```
git config --global user.name "Ting Cheng"
git config --global user.email showsky@gmail.com
git config --global core.editor vim
git config --global color.ui true
```

Date time

  • Ubuntu

    dpkg-reconfigure tzdata
    
  • PHP

    [Date]
    date.timezone = "Asia/Taipei"
    
  • MySQL

    [mysqld]
    default-time-zone = '+8:00'
    

Swap

  1. Create Swap file

    fallocate -l 1G /swapfile
    
  2. Modify file permission

    chmoe 600 /swapfile
    
  3. Format Swap file

    mkswap /swapfile
    
  4. mount swap

    swapon /swapfile
    
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    
  • Adjusting the Swappiness Property

    This is a value between 0 and 100 that represents a percentage

    0 = not use swap, 100 = keep more RAM

    cat /proc/sys/vm/swappiness
    
    60  //output
    
    sudo sysctl vm.swappiness=10 //reboot reset
    
    OR 
    
    vim /etc/sysctl.conf
    vm.swappiness=10
    
    
  • Adjusting the Cache Pressure Setting

    This setting configures how much the system will choose to cache inode and dentry information over other data.

    cat /proc/sys/vm/vfs_cache_pressure
    
    100 //output
    
    sudo sysctl vm.vfs_cache_pressure=50 //reboot reset
    
    OR
    
    vim /etc/sysctl.conf
    vm.vfs_cache_pressure=50
    
    

PHP-FPM

  • disable pathinfo

    #/etc/php/7.0/fpm/php.ini
    
    cgi.fix_pathinfo=0
    
  • improve PHP-FPM

    emergency_restart_threshold 10
    emergency_restart_interval 1m
    process_control_timeout 10s
    

Reference

  1. https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-18-04
  2. https://certbot.eff.org/
  3. https://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips-and-tricks/
  4. https://andyyou.github.io/2019/04/13/how-to-use-certbot/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment