博客迁移随笔

| 分类:linux | 评论: 0 | 浏览:422

由于之前购买的阿里云学生机到期,所以博客的东西要迁到新服务器上边去。新服务器是在腾讯云购买的。

docker安装

清除旧版本的docker

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

安装依赖包

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

修改安装源

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装docker

$ sudo yum install docker-ce

启动docker

$ service docker start

Docker安装Nginx、php、MySQL

下载

先搜索一下合适的nginx、mysql、php包

$ docker search nginx

image-20181119203452915

php和mysql的同理,找到合适的使用以下命令下载

$ docker pull nginx,bitnami/php-fpm:7.1,mysql:5.6

安装

docker run -dit -p 80:80 --name d-nginx -v /docker/nginx/conf:/etc/nginx/conf.d -v /www:/www -v /docker/nginx/log:/var/log/nginx nginx /bin/bash    

上面我为了方便查看日志和解析信息,就把宿主机的目录映射到容器里面了

启动完之后使用docker ps查看是否启动成功。

启动成功后需要进入容器开启nginx服务

$ docker exec -it d-nginx /bin/bash
$ service nginx start

因为我的php容器并没有监听9000端口,所以如果要在nginx容器中连接php容器的话,我们就需要知道PHP容器的ip

ip可以在宿主机中使用以下命令查到

$ docker inspect d-php7 | grep "IPAddress"
"SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",

其中172.17.0.2就是php容器的ip地址。

然后我们只要在/etc/nginx/conf.d/default.conf文件中修改配置。

location ~ \.php$ {
            root /www;
            fastcgi_pass   172.17.0.2:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }
docker run -dit --name d-php7 bitnami/php-fpm:7.1 /bin/bash    

启动状态同上

不同的是登录进去的启动命令不同

$ docker exec -it d-php7 /bin/bash
$ php-fpm
$ docker run -dit --name d-php7 -p 3306:3306 mysql:5.6 /bin/bash    

启动状态同上

$ docker exec -it d-mysql /bin/bash  // 进入mysql容器
$ service mysql start                  // 启动mysql
$ mysql -p                              // 登录mysql
$ mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
$ mysql> SELECT User, Password, Host FROM user;  // 查询已有的权限列表:
+------+----------+--------------+
| User | Password | Host         |
+------+----------+--------------+
| root |          | localhost    |
| root |          | ce3cc62ea770 |
| root |          | 127.0.0.1    |
| root |          | ::1          |
|      |          | localhost    |
|      |          | ce3cc62ea770 |
+------+----------+--------------+
6 rows in set (0.01 sec)
$ GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
$ mysql> FLUSH PRIVILEGES; // 刷新权限
$ docker exec -it d-php7 /bin/bash     //进入容器
$ apt-get update                    //更新apt-get
$ apt-get install memcached php-memcached //安装mencache和php扩展

安装完成后在php.ini中添加extension=memcached.so

重启php-fpm

$ php -m  //查看是否有mencached,有则表示安装成功
$ docker exec -it d-php7 /bin/bash     //进入容器
$ apt-get update                    //更新apt-get
$ apt-get apt-get install redis-server php-redis //安装redis和php扩展

安装完成后在php.ini中添加extension=redis.so

重启php-fpm

$ php -m  //查看是否有redis,有则表示安装成功

疑难杂症

yum使用不了

Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:yum
    内存: 85 M RSS (480 MB VSZ)
    已启动: Mon Nov 12 11:48:54 2018 - 1:37:32之前
    状态  :睡眠中,进程ID:11799

解决方法

rm -f /var/run/yum.pid

SSH登录

使用SSH登录腾讯服务器时出现以下错误

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:dsdasdasdasdasdasdasda1DOwSMcokWFscCCqT/i2bA.
Please contact your system administrator.
Add correct host key in /Users/M/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/M/.ssh/known_hosts:37
ECDSA host key for 111.2.29.5 has changed and you have requested strict checking.
Host key verification failed.

这是因为之前使用ssh登录过,但是由于我重装了系统而导致ssh的token失效。

ssh-keygen -R 111.2.29.5

重新连接

The authenticity of host '111.2.29.5 (111.2.29.5)' can't be established.
ECDSA key fingerprint is dsdasdasdasdasdasdasda1DOwSMcokWFscCCqT/i2bA.
Are you sure you want to continue connecting (yes/no)
Responses