Fun centos7 and docker

Most are currently centos5,6 linux servers use; however 7 in the near future will become mainstream, then I will provide you a detailed description of some common technical centos7.

Grasp the technology, you can easily play centos7.

note:

centos7 and centos6.5 different:

1. different network management

2. different service management

3. different firewall management

4. Different file systems, centos7-xfs; centos6.5-ext4

5. Other

A Installing System

1. Create a new virtual machine:

1) New Virtual Machine centos7.2:

wps714E.tmp[11]

wps714F.tmp[8]

2) Edit virtual machine:

wps7160.tmp[8]

wps7161.tmp[8]

2. Download and install the system centos7.2

1) Download:

http://mirrors.aliyun.com/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-DVD-1511.iso

2) Installation centos7.2:

(1) Enter the installation:

wps7162.tmp[8]

wps7163.tmp[8]

(2) Set the language of the installation process:

wps7164.tmp[8]

(3) setting the keyboard layout:

wps7165.tmp[8]

wps7176.tmp[8]

wps7177.tmp[8]

wps7178.tmp[8]

(4) Software Selection:

wps7179.tmp[8]

wps717A.tmp[8]

(5) disposed mounting position:

wps717B.tmp[8]

wps717C.tmp[8]

(6) Network Configuration:

wps718C.tmp[8]

wps718D.tmp[8]

(7) to start the installation:

wps718E.tmp[8]

(8) set the root password:

wps718F.tmp[8]

wps7190.tmp[8]

Wait for the installation to complete.

wps7191.tmp[8]

II. System Configuration centos7

1. Add user:

wps7192.tmp[8]

wps71A3.tmp[8]

Adding su control: linuxfan allow users to use the su command.

wps71A4.tmp[8]

verification:

wps71A5.tmp[8]

2. Turn off the firewall and selinux:

Check firewall status, and set the boot does not start: syntax systemctl start | restart | stop | reload service name

wps71A6.tmp[8]

View selinux state and set to disabled:

wps71A7.tmp[8]

3. Set the network and host names:

1) set up a permanent host name: the host name permanently modify the syntax: hostnamectl set-hostname name

wps71A8.tmp[8]

2) modify the display name of the network: network-scripts | NetworkManager (nmcli)

wps71B9.tmp[8]

wps71BA.tmp[8]

Verification after reboot:

wps71BB.tmp[8]

3) modify the file to set ip address:

wps71BC.tmp[8]

wps71BD.tmp[8]

:wq

Restart the service and verify:

wps71BE.tmp[8]

4) Use nmcli command sets the network: nmcli help | man nmcli -> EXAMPLE

Red Hat Enterprise Linux a new feature 7 and CentOS 7 is the default network services provided by NetworkManager, which is a dynamic network control and configuration daemon, it remains linked to normal when the network devices and connections are available, but also provides a typical ifcfg type of profile. The following may be used to connect NetworkManager: Ethernet, VLANs, bridging, Bonds, Teams, Wi-Fi, mobile broadband (such as 3G), and IP-over-InfiniBand (IPoIB). NetworkManager can be controlled by a command-line tool nmcli.

wps71BF.tmp[8]

4. Service Management: Service Name type syntax systemctl control

1) check the service status:

View all services:

wps71CF.tmp[8]

See all the service name and status:

wps71D0.tmp[8]

2) Stop Service: stop stop, disable boot does not start

wps71D1.tmp[8]

3) Start Service: start start, enable is set to boot

wps71D2.tmp[8]

The source and update the system configuration yum: yum using a substantially uniform and centos6

1) Test communication network:

wps71D3.tmp[8]

2) update the system:

wps71D4.tmp[8]

wps71D5.tmp[8]

3) Add yum source:

Use xshell connection:

wps71E6.tmp[8]

[Root @ www ~] # yum -y install yum-plugin-priorities ## mounted priority widget

[Root @ www ~] # sed -i -e "s /] $ /] \ npriority = 1 / g" /etc/yum.repos.d/CentOS-Base.repo ## disposed substantially yum source priority 1

[Root @ www ~] # yum -y install epel-release ## mounted epel source

[Root @ www ~] # sed -i -e "s /] $ /] \ npriority = 5 / g" /etc/yum.repos.d/epel.repo ## Set the priority 5

[root@www ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo ##禁用epel源

[the root WWW @ ~] # yum the install -Y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm source ## is mounted rpmforge

[Root @ www ~] # sed -i -e "s /] $ /] \ npriority = 10 / g" /etc/yum.repos.d/rpmforge.repo ## 10 Set the priority

[root@www ~]# sed -i -e "s/enabled = 1/enabled = 0/g" /etc/yum.repos.d/rpmforge.repo ##禁用yum源

使用方法:yum --enablerepo=rpmforge install [Package]

6. Configure vim:

[root@www ~]# yum -y install vim-enhanced

[Root @ www ~] # echo alias vi = 'vim' >> / etc / profile ## disposed aliases

[Root @ www ~] # source / etc / profile ## loaded

[Root @ www ~] # alias ## verification

[Root @ www ~] # vi ~ linuxfan / .vimrc ## is provided to the user linuxfan vim

set wrap ## does not wrap

highlight Comment ctermfg = low luminance display LightCyan ##

displaying the matched set showmatch ##

syntax on ## open grammar tips

set list

set number # show line numbers

set incsearch

set hlsearch

set history=50

Format set fileformats = unix, dos ## settings file

set fileencodings = cp936, gb18030, gbk, gb2312, utf-8, ucs-bom, latin-1 ## to avoid distortion

set ts = 4 ## of the tab length to a length of 4 spaces

:wq

Verify the effect of:

[root@www ~]# su - linuxfan

6 Yue 5 23:46:03 CST 2016pts / day 0: single sign-on

[linuxfan@www ~]$ vim .vimrc

1 set wrap$

2 set showmatch$

3 syntax on$

4 set list $

5 set number $

7. located sudo:

1) adding the user linuxfan sudo, all other operations except off outside:

[root@www ~]# visudo

Cmnd_Alias SHUTDOWN = /sbin/halt, /sbin/shutdown, /sbin/poweroff, /sbin/reboot, /sbin/init

linuxfan ALL=(ALL) ALL,!SHUTDOWN

Defaults logfile=/var/log/sudo.log

:wq

2) Verification:

[linuxfan@www ~]$ sudo cat /etc/passwd

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.

#2) Think before you type.

#3) With great power comes great responsibility.

[Sudo] password for linuxfan: enter your password

root:x:0:0:root:/root:/bin/bash

[linuxfan@www ~]$ sudo ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

   valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:de:3d:a0 brd ff:ff:ff:ff:ff:ff

inet 192.168.1.150/24 brd 192.168.1.255 scope global eth0

   valid_lft forever preferred_lft forever

[linuxfan@www ~]$

[linuxfan@www ~]$ sudo reboot

Sorry, you have no right to execute linuxfan / sbin / reboot on www.linuxfan.cn as root.

[linuxfan@www ~]$ sudo -l

Match linuxfan on this host default entries:

requiretty, !visiblepw, always_set_home, env_reset,

env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR

LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG

LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE

LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",

env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER

LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS

_XKB_CHARSET XAUTHORITY",

secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

Linuxfan user can run the following command on the host:

(ALL) ALL

(ALL) ALL, (ALL) !/sbin/halt, !/sbin/shutdown,

!/sbin/poweroff, !/sbin/reboot, !/sbin/init

[linuxfan@www ~]$

[Root @ www ~] # cat /var/log/sudo.log ## View Log

Jun 6 00:06:54 : linuxfan : TTY=pts/0 ; PWD=/home/linuxfan ; USER=root ;

COMMAND=list

8. Configuration sshd:

[Root @ www ~] # sed -i -e '49s / ^ # // g' / etc / ssh / sshd_config ## enable 49 rows arranged

[Root @ www ~] # sed -i -e '49s / yes / no / g' / etc / ssh / sshd_config ## prohibits using ssh root login

[Root @ www ~] # sed -i '/ ^ GSS / s / yes / no / g' / etc / ssh / sshd_config ## disable GSSAPI authentication to speed up the login speed

[Root @ www ~] # systemctl restart sshd ## to restart the service

[Root @ www ~] # systemctl enable sshd ## is set to boot

[Root @ www ~] # systemctl status sshd ## View Status

● sshd.service - OpenSSH server daemon

Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)

Active: active (running) since 一 2016-06-06 00:16:26 CST; 1min 3s ago

9. crack the root password:

1) Select System grub menu key and installation E

wps71E7.tmp[8]

2) Locate the linux16 row, kernel parameters ro to rw init = / sysroot / bin / sh and then press ctrl + x single-user mode.

wps71E8.tmp[8]

3) complete the change password using the following command in single-user mode:

chroot / sysroot ## access system

LANG = C ## to C language environment temporarily set

echo pwd @ 123 | passwd --stdin root ## to modify the root password to pwd @ 123

touch /.autorelabel ## to update the information system

exit ## to exit the system

reboot reboot ##

wps71E9.tmp[8]

III. Installation docker

[root@www ~]# yum -y install docker

[root@www ~]# rpm -qa |grep docker

docker-forward-journald-1.9.1-40.el7.centos.x86_64

docker-common-1.9.1-40.el7.centos.x86_64

docker-selinux-1.9.1-40.el7.centos.x86_64

docker-1.9.1-40.el7.centos.x86_64

[root@www ~]# rpm -ql docker

[root@www ~]# rpm -ql docker-forward-journald

[root@www ~]# rpm -ql docker-common

The basic four-.docker

[root@www ~]# systemctl start docker

[root@www ~]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@www ~]# systemctl status docker

● docker.service - Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)

Active: active (running) since 一 2016-06-06 00:24:14 CST; 21s ago

 Docs: http://docs.docker.com

Main PID: 40454 (sh)

CGroup: /system.slice/docker.service

       ├─40454 /bin/sh -c /usr/bin/docker-current daemon...

       ├─40456 /usr/bin/docker-current daemon --selinux-...

       └─40457 /usr/bin/forward-journald -tag docker

[Root @ www ~] # docker pull centos ## automatically download the official p_w_picpath centos mirror the last edition

Using default tag: latest

Trying to pull repository docker.io/library/centos ... latest: Pulling from library/centos

1544084fad81: Pull complete

df0fc3863fbc: Pull complete

a3d54b467fad: Pull complete

a65193109361: Pull complete

Digest: sha256:1a62cd7c773dd5c6cf08e2e28596f6fcc99bd97e38c9b324163e0da90ed27562

Status: Downloaded newer p_w_picpath for docker.io/centos:latest

[Root @ www ~] # docker run centos / bin / echo "welcome to the docker world" ## in the container Run

Usage of loopback devices is strongly discouraged for production use. Either use --storage-opt dm.thinpooldev or use --storage-opt dm.no_warn_on_loop_devices=true to suppress this warning.

welcome to the docker world

[Root @ www ~] # vi / etc / sysconfig / docker-storage ## stores the parameter modification

DOCKER_STORAGE_OPTIONS="--storage-opt dm.no_warn_on_loop_devices=true"

:wq

[root@www ~]# systemctl restart docker ##重启docker

[Root @ www ~] # docker run -i -t centos / bin / bash ## Login container console console

[root@0faf7bf4e1b4 /]# uname -a

Linux 0faf7bf4e1b4 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@0faf7bf4e1b4 /]# yum -y install iproute

[root@0faf7bf4e1b4 /]# ip a; exit

[Root @ www ~] # docker run -i -t centos / bin / bash ## log container, press ctrl + p, ctrl + q retaining container session

[root@4b20678656bb /]# [root@www ~]#

[root@www ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

4b20678656bb centos "/bin/bash" 38secondsago Up 38seconds sick_brattain

[Root @ www ~] # docker attach 4b20678656bb ## connected to the container, and then ctrl + p, ctrl + q exit

[root@4b20678656bb /]# [root@www ~]#

[root@www ~]#

[Root @ www ~] # docker kill 4b20678656bb ## killed container

4b20678656bb

[Root @ www ~] # docker ps ## verification

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@www ~]#

V. Use docker deploy apache-httpd

[Root @ www ~] # docker p_w_picpaths ## docker View Mirror

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

docker.io/centos latest a65193109361 3 days ago 196.7 MB

[root@www ~]# docker ps -a |head -2

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

5a36bf5d4064 centos "/bin/bash -c 'yum -y" 2 minutes ago Exited (0) 38 seconds ago clever_mcnulty

[Root @ www ~] # docker commit 5a36bf5d4064 my_p_w_picpath / centos_httpd ## Add Mirror

0cfbe60b45cec5311e9da53abbac29bac34d77f0eaa47806bdfaccde0cb8a1c1

[root@www ~]# docker p_w_picpaths

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

my_p_w_picpath/centos_httpd latest 0cfbe60b45ce 42 seconds ago 310.9 MB

docker.io/centos latest a65193109361 3 days ago 196.7 MB

[root@www ~]#

[Root @ www ~] # docker run my_p_w_picpath / centos_httpd ls / usr / sbin / httpd ## view mirror container

/usr/sbin/httpd

[Root @ www ~] # ls / usr / sbin / httpd ## viewed in a host

ls: can not access the / usr / sbin / httpd: No such file or directory

[root@www ~]# docker run -it -p 8081:80 my_p_w_picpath/centos_httpd /bin/bash

[root@18f49a674173 /]# /usr/sbin/httpd &

[1] 13

[root@18f49a674173 /]# AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

[1]+ Done /usr/sbin/httpd

[Root @ 18f49a674173 /] # echo "httpd on Docker Container"> /var/www/html/index.html ## New Home

[Root @ 18f49a674173 /] # [root @ www ~] # ## ctrl + p, ctrl + q and returns the process to retain the mirror host

[root@www ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

18f49a674173 my_p_w_picpath/centos_httpd "/bin/bash" 4 minutes ago Up 4 minutes 0.0.0.0:8081->80/tcp adoring_heisenberg

access:

wps71F9.tmp[9]

Reproduced in: https: //blog.51cto.com/14380057/2406785

Guess you like

Origin blog.csdn.net/weixin_33832340/article/details/91697245