> For the complete documentation index, see [llms.txt](https://skills.books.c-k.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://skills.books.c-k.dev/set-up-workspace/setup-basic-environment.md).

# Setup basic environment

### Config Interface

```bash
sudo vi /etc/network/interface
```

Update the config like this

```bash
iface eth0 inet static
    address 172.16.2.1
    netmask 255.255.255.0
    gateway 172.16.2.254
    dns-nameservers 1.1.1.1 8.8.8.8
```

Restart services and flush the ip binded to interface before

```bash
sudo ip addr flush dev eth0
sudo systemctl restart networking
```

#### How to bring interface up/down

1. Using `ip`

   Usage:

   ```bash
    # ip link set dev <interface> up
    # ip link set dev <interface> down
   ```

   Example:

   ```bash
    # ip link set dev eth0 up
    # ip link set dev eth0 down
   ```
2. Using `ifconfig`

   Usage:

   ```bash
    # /sbin/ifconfig <interface> up
    # /sbin/ifconfig <interface> down
   ```

   Example:

   ```bash
    # /sbin/ifconfig eth0 up
    # /sbin/ifconfig eth0 down
   ```

### Update apt-get repo list and set timezone

```bash
sudo apt-get upgrade && sudo apt-get update
tzselect
```

### Update HWE

Mainly for Ubuntu 16.04

> You may use `lsb_release -a` to check the OS version first

```bash
$ sudo apt-get update && sudo apt-get upgrade

$ sudo apt-get install --install-recommends linux-generic-hwe-16.04 xserver-xorg-hwe-16.04
```

### Install docker and docker compose

#### Install Docker

```bash
$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

$ sudo apt-get update

$ sudo apt-get install docker-ce
```

[Reference](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository)

#### Install Docker Compose

```bash
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

$ sudo chmod +x /usr/local/bin/docker-compose
```

– [Reference](https://docs.docker.com/compose/install/#install-compose)

### Install Space VIM

```bash
# Linux
$ sudo apt-get install -y build-essential
# For both Linux and mac
$ curl -sLf https://spacevim.org/install.sh | bash
# After the installation, run `vim`, it will automatically down the plugin. 
$ vim
```

– [Quick start guide | SpaceVim](https://spacevim.org/quick-start-guide/)

**Trouble-shot**

[SpaceVim中vimproc的vimproc\_linux64.so未找到](https://www.cnblogs.com/zhuxiaoxi/p/8466846.html)

```bash
# For Linux, execute in vim 
:VimProcInstall
# For mac
$ cd ~/.cache/vimfiles/repos/github.com/Shougo/vimproc.vim && sudo make
# OR
$ cd ~/.vim/bundle/vimproc.vim && git pull & sudo make
```

### Login to the docker hub

This part will be conducted by Danny `sudo docker login`

### Install htop

`$ sudo apt-get install htop`

### Set ulimit

`echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`

### Set max virtual memory

set the parameters `vm.max_map_count`in /etc/sysctl.conf `echo vm.max_map_count=262144 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`

OR

run command (will be reset after reboot): `sudo sysctl -w vm.max_map_count=262144`

– [Reference 1](https://github.com/docker-library/elasticsearch/issues/111) / [Reference 2](https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html)

### Setup the log rotation for docker

Configure the default logging driver This can be done by adding the following values in `/etc/docker/daemon.json`. Create this file if it doesn’t exist.

```javascript
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "10"
  }
}
```

Execute the following commands to reload the updated daemon.json. The new configuration will apply to all newly created containers after restart.

```bash
$ sudo systemctl restart docker
```
