`
Leif_冬
  • 浏览: 45251 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Ubuntu Server 配置

 
阅读更多

Ubuntu Server 配置

 

1. 升级 Kernel
Ubuntu 在登录后会出现界面异常卡顿的现象,鼠标移动都会很困难。
升级 Kernel: 4.15 版本以上的 kernel 对 Caffelake 版的 cpu 集显有 bug fix.
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15-rc8/linux-headers4.15.0-041500rc8_4.15.0-041500rc8.201801142030_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15-rc8/linux-headers4.15.0-041500rc8-generic_4.15.0-041500rc8.201801142030_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15-rc8/linux-image-4.15.0-
041500rc8-generic_4.15.0-041500rc8.201801142030_amd64.deb
sudo dpkg -i *.deb
sudo update-grub
sudo reboot

2. Docker
 2.1 Ubuntu 安装 Docker CE
 2.1.1 卸载旧版本
版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:
sudo apt-get remove docker docker-engine docker.io
 2.1.2 使用 APT 安装 Docker
➢ 添加使用 HTTPS 传输的软件包以及 CA 证书
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
➢ 添加软件源的 GPG 密钥
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo aptkey
add -
➢ 向 source.list 中添加 Docker 软件源
$ sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $
(lsb_release -cs) stable"
➢ 更新 apt 软件包缓存,并安装 docker-ce:
$ sudo apt-get update
$ sudo apt-get install docker-ce
 2.2 启动 Docker CE
$ sudo systemctl enable docker
$ sudo systemctl start docker
 2.3 测试 Docker 是否安装正确
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 (amd64)
 3. The Docker daemon created a new container from that image which runs the
 executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
 to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
For more examples and ideas, visit:
 https://docs.docker.com/get-started/
若能正常输出以上信息,则说明安装成功 。
 2.4 建立 docker 用户组
建立 docker 组:
$ sudo groupadd docker
将当前用户加入 docker 组:
$ sudo usermod -aG docker $USER
 2.5 获取镜像
 2.5.1 镜像加速器
 国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。请在
/etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
{
 "registry-mirrors": [
 "https://registry.docker-cn.com"
 ]
}
 重新启动服务
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
 检查加速器是否生效
在命令行执行 docker info,如果从结果中看到了如下内容,说明配置成功。
Registry Mirrors:
 https://registry.docker-cn.com/
 2.5.2 从 Docker Hub 上获取镜像
命令格式为:
docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
具体的选项可以通过 docker pull --help 命令看到,这里我们说一下镜像名称的格式。
• Docker 镜像仓库地址:地址的格式一般是 <域名/IP>[:端口号]。默认地址是 Docker Hub。
• 仓库名:如之前所说,这里的仓库名是两段式名称,即 <用户名>/<软件名>。对于 Docker
Hub,如果不给出用户名,则默认为 library,也就是官方镜像。
比如:
$ docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
bf5d46315322: Pull complete
9f13e0ac480c: Pull complete
e8988b5b3097: Pull complete
40af181810e7: Pull complete
e6f7c7e5c03e: Pull complete
Digest: sha256:147913621d9cdea08853f6ba9116c2e27a3ceffecf3b492983ae97c3d643fbbe
Status: Downloaded newer image for ubuntu:16.04
 2.5.3 运行
有了镜像后,我们就能够以这个镜像为基础启动并运行一个容器。以上面的 ubuntu:16.04 为例,如
果我们打算启动里面的 bash 并且进行交互式操作的话,可以执行下面的命令。
$ docker run -it --rm ubuntu:16.04 bash
root@e7009c6ce357:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.4 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
docker run 就是运行容器的命令,具体格式我们会在 容器 一节进行详细讲解,我们这里简要的说明
一下上面用到的参数。
• -it:这是两个参数,一个是 -i:交互式操作,一个是 -t 终端。我们这里打算进入 bash 执
行一些命令并查看返回结果,因此我们需要交互式终端。
• --rm:这个参数是说容器退出后随之将其删除。默认情况下,为了排障需求,退出的容器并不
会立即删除,除非手动 docker rm。我们这里只是随便执行个命令,看看结果,不需要排障和
保留结果,因此使用 --rm 可以避免浪费空间。
• ubuntu:16.04:这是指用 ubuntu:16.04 镜像为基础来启动容器。
• bash:放在镜像名后的是命令,这里我们希望有个交互式 Shell,因此用的是 bash。
进入容器后,我们可以在 Shell 下操作,执行任何所需的命令。这里,我们执行了 cat /etc/osrelease,这是
Linux 常用的查看当前系统版本的命令,从返回的结果可以看到容器内是 Ubuntu
16.04.4 LTS 系统。
最后我们通过 exit 退出了这个容器
 2.6 列出镜像
要想列出已经下载下来的镜像,可以使用 docker image ls 命令。
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu arash 225994adbc85 6 days ago 1.25GB
nginx v1 4c5fd99c66fb 6 days ago 109MB
nginx latest 62f816a209e6 2 weeks ago 109MB
ubuntu 16.04 4a689991aa24 5 weeks ago 116MB
hello-world latest 4ab4c602aa5e 2 months ago 1.84kB
列表包含了 仓库名、标签、镜像 ID、创建时间 以及 所占用的空间。
 2.7 删除本地镜像
如果要删除本地的镜像,可以使用 docker image rm 命令,其格式为:
$ docker image rm [选项] <镜像 1> [<镜像 2> ...]
我们在删除镜像的过程可能会碰到冲突无法删除的情况,比如下面的情况:
$ docker image rm 4c5
Error response from daemon: conflict: unable to delete 4c5fd99c66fb (must be forced) - image is
being used by stopped container 08f99bd8c1b4
出现这种情况我们可以使用下面的命令:
$ docker container stop 08f99bd8c1b4
$ docker rm 08f99bd8c1b4
$ docker image rm 4c5
 2.8 使用 Dockerfile 定制镜像
 2.8.1 创建 Dockerfile
Dockerfile 是一个文本文件,其内包含了一条条的指令,每一条指令构建一层,因此每一条指令的内容.
在一个空白目录中,建立一个文本文件,并命名为 Dockerfile,其内容为:
FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
• FROM 指定基础镜像
• RUN 执行命令
 2.8.2 构建镜像
在 Dockerfile 文件所在目录执行:
$ docker build -t nginx:v3 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM nginx
 ---> e43d811ce2f4
Step 2 : RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
 ---> Running in 9cdc27646c7b
 ---> 44aa4490ce2c
Removing intermediate container 9cdc27646c7b
Successfully built 44aa4490ce2c
从命令的输出结果中,我们可以清晰的看到镜像的构建过程。在 Step 2 中,如同我们之前所说的那
样,RUN 指令启动了一个容器 9cdc27646c7b,执行了所要求的命令,并最后提交了这一层
44aa4490ce2c,随后删除了所用到的这个容器 9cdc27646c7b。
这里我们使用了 docker build 命令进行镜像构建。其格式为:
docker build [选项] <上下文路径/URL/->
 2.9 采用 Dockerfile 的方式构建 Arash 镜像
在一个空白目录中,建立一个 Dockerfile 文本文件,其内容为:
FROM ubuntu:16.04
MAINTAINER Bob <bob_x_liu@wistron.com>
# disable select time zone
ENV DEBIAN_FRONTEND=noninteractive
#backup and modify source list
RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup
RUN rm /etc/apt/sources.list
COPY sources.list /etc/apt/
#install common
RUN apt-get update -y\
&& apt-get install -y apt-utils \
&& apt-get install -y vim \
&& apt-get install -y wget schedtool pngcrush \
&& apt-get install -y unrar meld ghex gtk-recordmydesktop gitk
\
 && apt-get install -y openjdk-8-jdk
#install android env
RUN buildDeps='bison g++-multilib git gperf libxml2-utils'\
 && dpkg --add-architecture i386 \
&& apt-get update -y \
&& apt-get install -y $buildDeps \
&& apt-get install -y libx11-dev:i386 libreadline6-dev:i386
libgl1-mesa-dev g++-multilib \
&& apt-get install -y git flex bison gperf build-essential
libncurses5-dev:i386 \
&& apt-get install -y tofrodos python-markdown libxml2-utils
xsltproc zlib1g-dev:i386 \
&& apt-get install -y dpkg-dev libsdl1.2-dev libesd0-dev \
&& apt-get install -y git-core gnupg flex bison gperf buildessential
\
&& apt-get install -y zip curl zlib1g-dev gcc-multilib g++-
multilib \
&& apt-get install -y libc6-dev-i386 \
&& apt-get install -y lib32ncurses5-dev x11proto-core-dev
libx11-dev \
&& apt-get install -y libgl1-mesa-dev libxml2-utils xsltproc
unzip m4 \
&& apt-get install -y lib32z-dev ccache \
&& apt-get install -y libssl-dev \
&& apt-get install -y bc
#set work path ,if the /home/arash directory not exist,it will
create
WORKDIR /home/arash
ENV USER root
使用命令 docker build -t Ubuntu:arash . 构建 arash 镜像。 sources.list 为宿
主机的软件源,它和 Dockerfile 在同一目录下。
Arash docker 创建完成后使用下面的命令创建 container,创建 container 方便每次启动时
直接启动 container 就 Ok.
$ docker run -v /home/hhsw/hdd/Projects/Arash:/home/arash -i -t
--name arash ubuntu:arash bash
➢ -v: 把 docker 里面的/home/arash 目录挂载到宿主机的需要 build image 的目录下
面。/home/hdd/Projects/Arash 为 Arash source code 所在目录。
➢ --name: 命名 container 的名字。
➢ Ubuntu:arash: docker 名字与 TAG。
➢ bash: 以 termianl 交互方式开启。
 2.9.1 查看开启的 Container
➢ $ docker container ls
 2.9.2 启动 container
以上面创建的 arash container 为例。
➢ $ docker container start arash
 2.9.3 停止 container
以上面创建的 arash 为例
➢ 用 docker container ls 查看
$ docker container ls --format "table
{{.ID}}\t{{.Command}}\t{{.Image}}\t{{.Names}}"
CONTAINER ID COMMAND IMAGE NAMES
3762267ed83e "bash" ubuntu:arash arash
➢ 停止 container
docker container stop 3762267ed83e
 2.9.4 下面以 build Arash image 为例使用 Docker
➢ 开启 container
docker container start arash
➢ 以 terminal 交互方式进入 docker
docker exec -i -t arash bash
➢ 使用下面命令 build image
cd LA.UM.6.2/LINUX/android
 source build/envsetup.sh
 lunch arashi-userdebug
 make –j32

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics