tossing linux server

https://wyue.name/2018/04/15/1/
There is a server in the school, and I have been struggling again recently. So I tinkered, installed docker, nginx on the server, and set up a network disk service nextcloud. The pits encountered are recorded below, and there are solutions.

Note that all operations are done on centos6.9, kernel version 2.6.32-696.3.2.el6.x86_64.
Command to view kernel version and release version number:

cat /etc/issue (此命令可用于docker内系统版本号查询)
uname -a
lsb_release -a

yum to change the source of Alibaba Cloud

This step is not necessary, but the speed is so cool after changing it
. 1. Backup

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  1. Download the new CentOS-Base.repo to /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  1. Close the unnecessary repo (this step is not necessary)
vim xxx.repo

Change to enabled=0

  1. renew
yum clean all
yum makecache

docker

The docker official website already supports only centos7 kernel version 3.10 and above. So I can only install the unofficial version

Install

with the following command:

yum install docker-io
service docker start

Facts have proved that it can also be used. It's just that sometimes you need a higher version of docker and you're blind. . . Fortunately, this situation is not often encountered
. Check the log.

vim /var/log/docker

use

  1. The command to download an image is:
docker pull ubuntu
  1. The command to start a container from an image is:
docker run -v localdir:containerport -p localport:containerport -it  ubuntu:wy
 ```
3. 查看所有container:

docker ps -a


4. 启动一个关闭了的container:

docker start id

5. 交互连接一个启动了的contaner

docker attach id

6. 后台运行一个attach中的container 按ctrl p q

7. 查看所有 image

docker images

8. 关闭一个container

docker stop id

9. 删除container

docker rm id
or
docker rm $(docker ps -a -q)
delete all containers


10. 删除 image

docker rmi image_id


11. 保存修改过的docker container

docker commit id ubuntu:wy

12 push docker 到自己的仓库里

docker tag ubuntu:wy xfdywy:ubuntu
docker images
docker push xfdywy:ubuntu


13. docker 查看container log

docker logs -f id

## 遇到的坑
docker in docker 坑太大,放弃




# nginx
这个是个非常给力的反向代理和web服务器。这里既然说是和,就是说他有两个功能,这里重点放在前者,反向代理。
web服务器就有点类似apache,大概是个同层次的概念吧。
反向代理意思就是,部署在服务器端,nginx 作为服务器上的代理人,当用户请求的时候,先经过nginx,再由nginx跟真正的服务器上的资源交流。

先说说为什么要搞nginx,因为服务器对外网就开放了一个端口,比如是80吧,那么如果我要有很多服务,比如我架了个blog在81端口,又架了个网盘在82 端口,又架了个别的什么在83端口,就很麻烦了,因为只有一个端口可以外网访问。有了nginx,我们都先请求到nginx,例如都请求到 服务器ip:80 , 然后再由nginx来判断应该把这个请求发送到那个真正的端口上。判断的标准就是用户使用什么url来访问,例如blog.test.com 就解析到81端口,pan.test.com就解析到82端口。由于80端口是开放的,所以我们设置dns服务器,让这三个url都解析到服务器ip:80 之后的工作就可以交给nginx了。

## 安装
nginx的安装也很简单

vim /etc/yum.repos.d/nginx.repo

添加以下内容

[nginx]
name = nginx repo
baseurl = http://nginx.org/packages/centos/ r e l e a s e v e r / basearch/
gpgcheck=0
enabled=1

之后

yum install nginx -y

启动服务

``` stylus
service nginx start




<div class="se-preview-section-delimiter"></div>

View status

service nginx status




<div class="se-preview-section-delimiter"></div>

view port

lsof -i:80

netstat -anp|grep 80 




<div class="se-preview-section-delimiter"></div>

Some file addresses:





<div class="se-preview-section-delimiter"></div>

#Nginx服务器的配置文件
/etc/nginx/nginx.conf 





<div class="se-preview-section-delimiter"></div>

#Nginx虚拟机文件夹,定义的虚拟机放在此目录下
/etc/nginx/conf.d 

/etc/nginx/conf.d/default.conf





<div class="se-preview-section-delimiter"></div>

# Nginx log
/var/log/nginx





<div class="se-preview-section-delimiter"></div>

configure

The following is my own configuration. Through this configuration, it can be realized that when a user accesses with aaa.com, he actually accesses http://xx.xx.xx.xx:60001 , and when he accesses with bbb.com, The actual visit is http://xx.xx.xx.xx:10080. You
only need to set aaa.com and bbb.com to resolve to your server ip:80 when dns resolution is performed.


server {
    listen       80 default_server;
    listen       [::]:80  default_server;
    server_name  aaa.com;

    root         /var/www/html/;

    include /etc/nginx/default.d/*.conf;

        location / {
            proxy_pass http://xx.xx.xx.xx:60001;
            proxy_redirect default;
            }

error_page 404 /404.html;
    location = /40x.html {
        }

error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        }
}

server {

    listen 8080 ;
    server_name bbb.com;
    location / {
    proxy_pass http://xx.xx.xx.xx:10080;
    }
}





<div class="se-preview-section-delimiter"></div>

pit encountered

if it appears

nginx:connect() to 127.0.0.1:5601 failed (13: Permission denied) while connecting to upstream




<div class="se-preview-section-delimiter"></div>

please check





<div class="se-preview-section-delimiter"></div>

# getenforce
Enforcing




<div class="se-preview-section-delimiter"></div>

If it is the above result, it is generally a problem of selinux permissions. There are many pits in selinux. Generally, if the configuration is well configured, if there is still an error, you can consider it nearby. Usually it's a question of access rights. There are two solutions, one is to close selinux directly. One is to set the file permissions. Refer to selinux test

http://cn.linux.vbird.org/linux_basic/0440processcontrol_5.php

first approach

setenforce 0
sed -i 's/enforcing$/disabled/g' /etc/selinux/config




<div class="se-preview-section-delimiter"></div>

The second approach





<div class="se-preview-section-delimiter"></div>

#chcon -R -t httpd_sys_content_t /your/file/paht

2

2
2

2
2
2

1

1

1

chcon -R -t httpd_sys_content_t /your/file/paht

“`

2

2
2

2
2
2

1

1

1

1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324690061&siteId=291194637