linode vps关闭删除前状态备份181226

2018/12/26 23:30    linode 关闭删除前一些状态备份,算是愐怀吧

uptime

[root@n feng]# uptime
 15:35:19 up 240 days, 20 min,  1 user,  load average: 0.00, 0.00, 0.00

free -m

[root@n feng]# free -m
             total       used       free     shared    buffers     cached
Mem:           979        598        380        118         44        309
-/+ buffers/cache:        244        735
Swap:          255        123        132

top -m

top - 15:37:34 up 240 days, 22 min,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  77 total,   1 running,  39 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1003304k total,   610928k used,   392376k free,    45784k buffers
Swap:   262140k total,   126644k used,   135496k free,   316108k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
22454 nobody    20   0  477m 123m 109m S  0.0 12.6   4:51.90 php-fpm
24518 nobody    20   0  476m  98m  86m S  0.0 10.1   1:06.22 php-fpm
21476 nobody    20   0  476m  98m  86m S  0.0 10.0   0:44.83 php-fpm
24531 nobody    20   0  476m  97m  85m S  0.0 10.0   1:06.05 php-fpm
24530 nobody    20   0  476m  97m  86m S  0.0  9.9   1:06.23 php-fpm
 2828 mysql     20   0  783m  48m 3948 S  0.0  5.0 754:20.54 mysqld
19132 root      20   0  102m 6180 5128 S  0.0  0.6   0:00.03 sshd
25817 nginx     20   0 54016 5236 2660 S  0.0  0.5  30:55.19 nginx
 8991 root      20   0  238m 4864  416 S  0.0  0.5  10:16.11 rsyslogd
19134 feng      20   0  103m 4852 2416 S  0.0  0.5   0:00.41 sshd
11101 root      20   0  455m 3596 2404 S  0.0  0.4   5:00.05 php-fpm
19155 root      20   0  105m 2764 2264 S  0.0  0.3   0:00.14 bash
19154 root      20   0  144m 2760 2352 S  0.0  0.3   0:00.01 su
13703 root      20   0 49476 2512 1700 S  0.0  0.3   0:00.01 nginx
26466 root      20   0 26440 2512  600 S  0.0  0.3  12:55.89 ss-server
19135 feng      20   0  105m 2496 2112 S  0.0  0.2   0:00.00 bash
19971 root      20   0 15076 2008 1728 R  0.0  0.2   0:00.00 top
 8758 root      20   0 66320 1432 1344 S  0.0  0.1   6:59.90 sshd
 2567 root      16  -4 27780  592  480 S  0.0  0.1  13:20.38 auditd
 2886 root      20   0  114m  548  464 S  0.0  0.1   0:40.77 crond
 1897 root      16  -4 10784  324  320 S  0.0  0.0   0:00.12 udevd
    1 root      20   0 19292   96    0 S  0.0  0.0   1:36.95 init
 2907 root      20   0  4140   52   48 S  0.0  0.0   0:00.00 agetty
 2908 root      20   0  4140   52   48 S  0.0  0.0   0:00.00 agetty
 2693 root      20   0  105m   48   48 S  0.0  0.0   0:00.01 mysqld_safe
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    4 root       0 -20     0    0    0 I  0.0  0.0   0:00.00 kworker/0:0H
    6 root       0 -20     0    0    0 I  0.0  0.0   0:00.00 mm_percpu_wq
    7 root      20   0     0    0    0 S  0.0  0.0   3:54.26 ksoftirqd/0
    8 root      20   0     0    0    0 I  0.0  0.0  21:00.86 rcu_sched
    9 root      20   0     0    0    0 I  0.0  0.0   0:00.00 rcu_bh
   10 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuhp/0

top -p

top - 15:38:37 up 240 days, 23 min,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  77 total,   1 running,  39 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1003304k total,   611348k used,   391956k free,    45812k buffers
Swap:   262140k total,   126644k used,   135496k free,   316112k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
19972 root      20   0 15076 1988 1700 R  0.3  0.2   0:00.01 top
    1 root      20   0 19292   96    0 S  0.0  0.0   1:36.95 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    4 root       0 -20     0    0    0 I  0.0  0.0   0:00.00 kworker/0:0H
    6 root       0 -20     0    0    0 I  0.0  0.0   0:00.00 mm_percpu_wq
    8 root      20   0     0    0    0 I  0.0  0.0  21:00.86 rcu_sched
    9 root      20   0     0    0    0 I  0.0  0.0   0:00.00 rcu_bh
   10 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuhp/0
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kdevtmpfs
   13 root       0 -20     0    0    0 I  0.0  0.0   0:00.00 netns
   14 root      20   0     0    0    0 S  0.0  0.0   2:32.35 kauditd
   28 root      20   0     0    0    0 I  0.0  0.0  38:15.30 kworker/0:1

ifconfig

[root@n feng]# ifconfig
eth0      Link encap:Ethernet  HWaddr F2:3C:91:84:5F:56
          inet addr:106.185.34.99  Bcast:106.185.34.255  Mask:255.255.255.0
          inet6 addr: 2400:8900::f03c:91ff:fe84:5f56/64 Scope:Global
          inet6 addr: fe80::f03c:91ff:fe84:5f56/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:236135630 errors:0 dropped:0 overruns:0 frame:0
          TX packets:178602310 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:38497969194 (35.8 GiB)  TX bytes:382481811071 (356.2 GiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:54474136 errors:0 dropped:0 overruns:0 frame:0
          TX packets:54474136 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:113921748796 (106.0 GiB)  TX bytes:113921748796 (106.0 GiB)

MySQL/phpMyAdmin 状态

数据库服务器

    服务器: My Local MySQL server (Localhost via UNIX socket)
    软件: MySQL
    软件版本: 5.1.73-log - Source distribution
    协议版本: 10
    用户: root@localhost
    服务器字符集: UTF-8 Unicode (utf8)

网站服务器

    nginx/1.14.0
    数据库客户端版本: libmysql - 5.1.73
    PHP 扩展: mysqli 文档
    显示 PHP 信息

phpMyAdmin

    版本信息: 3.5.0
    文档
    维基 (Wiki) (外链,英文)
    官方主页 (外链,英文)
    贡献
    获取支持
    更新列表
自启动以来的网络流量: 732.1 GB

此 MySQL 服务器已运行 240 天 0 小时,11 分 17 秒。启动时间为 2018 年 04 月 30 日 15:20 。

此 MySQL 服务器正以主服务器运行于复制进程中。 要获得更多关于此服务器的复制状态,请查看复制状态信息。
复制状态
主服务器状态
变量 	值
File 	mysql-bin.000127
Position 	622011141
Binlog_Do_DB 	
Binlog_Ignore_DB 	

流量  	ø 每小时
已接收 	44.8 GB 	8 MB
已发送 	687.2 GB 	122.2 MB
总计 	732.1 GB 	130.1 MB
连接 	ø 每小时 	%
最大并发连接数 	17 	--- 	---
已失败 	9 	<0.01 	<0.01%
已取消 	39 	0.01 	<0.01%
总计 	3,714 k 	644.73 	100.00%
进程 	ID 	用户 	主机 	数据库 	命令 	时间 	状态 	SQL 查询 显示完整查询
杀死 	3713760 	root 	localhost 	mysql 	Sleep 	3 	--- 	---
杀死 	3713761 	root 	localhost 	无 	Sleep 	1 	--- 	---
杀死 	3713762 	root 	localhost 	mysql 	Query 	0 	--- 	SHOW PROCESSLIST
杀死 	3713763 	root 	localhost 	无 	Sleep 	2 	--- 	---
杀死 	3713764 	root 	localhost 	无 	Sleep 	2 	--- 	---
 自启动以来的内部查询: 118,225,577 文档
ø 每小时: 20,524
ø 每分钟: 342
ø 每秒: 6
说明 	查询数量 	ø 每小时 	%
select 	96,653 k 	16.8 k 	81.75%
set option 	7,441 k 	1,291.8 	6.29%
update 	6,285 k 	1,091.1 	5.32%
change db 	3,711 k 	644.2 	3.14%
show fields 	3,144 k 	545.8 	2.66%
insert 	926 k 	160.7 	0.78%
delete 	49,614 	8.6 	0.04%
delete multi 	3,054 	0.5 	<0.01%
show table status 	2,864 	0.5 	<0.01%
show create table 	2,373 	0.4 	<0.01%
show triggers 	2,308 	0.4 	<0.01%
begin 	1,477 	0.3 	<0.01%
commit 	1,477 	0.3 	<0.01%
show tables 	401 	0.1 	<0.01%
show variables 	327 	0.1 	<0.01%
alter table 	251 	<0.1 	<0.01%
create table 	239 	<0.1 	<0.01%
show databases 	173 	<0.1 	<0.01%
show master status 	138 	<0.1 	<0.01%
show slave status 	136 	<0.1 	<0.01%
show keys 	128 	<0.1 	<0.01%
show binlogs 	98 	<0.1 	<0.01%
replace 	49 	<0.1 	<0.01%
show create db 	46 	<0.1 	<0.01%
rename table 	31 	<0.1 	<0.01%
show grants 	23 	<0.1 	<0.01%
show plugins 	16 	<0.1 	<0.01%
show function status 	12 	<0.1 	<0.01%
show procedure status 	12 	<0.1 	<0.01%
flush 	11 	<0.1 	<0.01%
show warnings 	9 	<0.1 	<0.01%
show status 	9 	<0.1 	<0.01%
show processlist 	7 	<0.1 	<0.01%
create db 	7 	<0.1 	<0.01%
grant 	7 	<0.1 	<0.01%
drop table 	6 	<0.1 	<0.01%
show storage engines 	6 	<0.1 	<0.01%
insert select 	4 	<0.1 	<0.01%
create user 	4 	<0.1 	<0.01%
drop db 	3 	<0.1 	<0.01%
show slave hosts 	3 	<0.1 	<0.01%
show binlog events 	2 	<0.1 	<0.01%
optimize 	1 	<0.1 	<0.01%
kill 	1 	<0.1 	<0.01%
drop user 	1 	<0.1 	<0.01%
alter db 	1 	<0.1 	<0.01%

aa

CentOS 7的web环境等

原则:尽量使用yum repo安装

CentOS 官方对第三方repo的说明  https://wiki.centos.org/zh/AdditionalResources/Repositories

nginx

使用nginx 官方提供的repo,配置文件 /etc/yum.repos.d/nginx.repo 文件内容如下

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

更多参看 http://nginx.org/en/linux_packages.html

php(fastcgi版)

因为要配合nginx,所以要选择fastcgi版的php-fpm, 这里选择remi源,这也是centos 官方推荐的php源之一。如下命令配置repo,将会配置好几个repo文件,但只有remi-safe.repo 是默认激活的,其他repo中的包有可能与系统文件冲突,所以在需要使用时在临时激活。

rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm

如下命令安装php-fpm

yum --enablerepo=remi-php73 install php-fpm

remi维护了多个php版本,选用目前最新的7.3,通过--enablerepo临时激活该源。注意包名带 "-fpm" 否则是apache的模块版。注意一下安装进程,没有自动安装httpd。

按需要安装其他php扩展,下面是常用扩展的参考

yum --enablerepo=remi-php73 install php-gd php-gmp php-igbinary \
  php-mbstring php-mcrypt php-memcached php-mysqli php-odbc \
  php-pdo php-xml php-zip php-zlib php-bcmath php-imagick

配置php-fpm。主要是文件  /etc/php-fpm.d/www.conf ,默认fastcgi进程数是动态管理的,根据机器内存、负载等控制进程数,下面是微小站点的配置,其中user/group 不改默认apache也行。(或许默认的apache与后面提到的session文件目录默认权限是相符的,待确定 TODO )

user = nobody
group = nobody
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 5

修改php默认的session文件存储目录权限,按前面php-fpm用户设置为

chown nobody:nobody /var/lib/php/session

在nginx启用php

nginx主配置文件为 /etc/nginx/nginx.conf,站点配置文件在 /etc/nginx/conf.d/*.conf ,默认参看主配置文件结尾处 include /etc/nginx/conf.d/*.conf 一行。

推荐习惯:把web站点文件放在 /var/www/html/ 目录下,每个站点一个子目录,下面以默认站点文件的配置为例,其他站点参考即可。更多参考nignx官方文档,尤其是其中core模块 ngx_http_core_module

为默认站点 default.conf 创建目录 mkdir -p /var/www/html/default ,备份一下自带的的站点文件 cp /etc/nginx/conf.d/default.conf{,__original} ,参考下面示例修改 /etc/nginx/conf.d/default.conf 文件。有更多站点,用default.conf 作模板修改。选项说明:

  • 其中 listen 80 default; 一行表示这是默认站点,其他站点就不能加了。
  • 原来在location / {...} 中的root 指令; 推荐直接放到server{...}节点中,目的是,在php 配置fastcgi_param中使用$document_root 变量,而不是像默认配置文件里的再写一遍绝对路径,其中也可以省略掉root指令了。
  • try_files $uri $uri/ /index.php; 一行是wordpress的伪静态rewrite规则;
  • rewrite ^/feed /license.txt; 是把url重写到指定文件上
  • 如果配置ssl/https,可以使用Let’s Encrypt免费证书,步骤及设置参数可参看这里
server {
    listen 80 default;
    server_name blog.path8.net;
    #server_name blog.path8.net www.path8.net; #多域名
    root /var/www/html/default;
    #autoindex on;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location /robots.txt {
        log_not_found off;
        access_log off;
    }

    location / {
    #    root   /usr/share/nginx/html;
        index  index.html index.htm;
        #try_files $uri $uri/ /index.php;
        #rewrite ^/feed /license.txt;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #    root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

修改完成后,nginx -t 测试配置文件,无误后启动(start)nginx及php-fpm,并设置自动启动(enable)

nginx -t
systemctl start nginx
systemctl status nginx
systemctl enable nginx
systemctl start php-fpm
systemctl status php-fpm
systemctl enable php-fpm

如果静态文件正常,php请求报错 File not found ,并且nginx error日志中有如下错误 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream 可去检查web文件权限与php-fpm用户是否匹配,还有是不是开着SELinux且没配置好规则。

数据库MySQL/MariaDB安装

遵循CentOS7的改变,使用Mariadb替换MySQL,使用上差别不大,基本上完全沿用MySQL,除了改个名字。yum安装服务端及客户端

yum install mariadb mariadb-server

先不急着启动服务,修改一下配置文件,参考下面,放到[mysqld]节点后,大概第10行。这是适合微小型服务器的配置参数,可以按实际调整。的话添加下面几行。

#add by fengyqf start 161105
skip-name-resolve

innodb_log_buffer_size=32M
innodb_buffer_pool_size=64M
innodb_log_file_size=16M
innodb_additional_mem_pool_size=16M

server-id=301
log-bin=mysql-bin
log-error=mysql-bin.err
expire_logs_days=30
open_files_limit=10240
#add by fengyqf end

其中server-id起的4行,是配置复制功能用的,不要MySQL复制功能的话不要加,它们会生成一系列二进制文件,多占用磁盘。复制是自动同步把数据到其他服务上,还要其他配置才行,只这几行不够的。保存好启动服务。

systemctl start mariadb
systemctl status mariadb
systemctl enable mariad

如果在修改配置前启动过服务,启动会失败,删除日志文件再启动即可 rm /var/lib/mysql/ib_logfile*

new section

amazon lightsail使用记录及主要配置项(CentOS 7实例)

从朋友处得知amazon的lightsail,有东京机房而且网络质量还不错,价格还公道(512M最低配3.5刀),于是想换掉已经使用了7年的linode,正在用的早已绝版的东京1也4年了,网络抽风的频率有点高。试用过一段时间的东京2,网络质量确实有待改善。好几年前试用过aws的1年免费,啥都没干而浪费掉了,那时还跟linode一样是20刀1月。

英文国际版 https://aws.amazon.com/lightsail/

中国优化版 https://amazonaws-china.com/cn/lightsail/

网上有人说lightsail中文页面价格比英文高,可能是以前吧,现在并不是,所以跟随aws的提示进优化过的中文版,而且英文版可能还要科学上网(否则页面加载不完整)。

直接购买,目前最低配的首月免费,位置选择东京,平台选Linux/Unix,蓝图选仅操作系统-CentOS ,实例计划选最低的3.5刀版本,创建即可。关于系统版本,不选用预装应用(如Wordpress, Nginx等)的版本,是希望拿到干净的系统,按自己的需要定制。其实这点全看个人喜好了。

VPS实例初始化很快,搞一个静态IP地址,关联上去,免费的。

用户登录

默认不允许用户名/密码的登录方式,使用密钥对登录,按照提示进行即可。自带的用户名是centos,也可以先使用Web版SSH连接到服务器。关于用户方案推荐如下:

  • 先用web版ssh登录,添加一个新用户,设置密码,默认用户centos不去动它,似乎lightsail管理后台要用。useradd {yourname}; passwd {yourname}
  • 如果你使用linux/cygwin/maxosx,推荐把你的ssh公钥添加上去,以便直接ssh公钥登录,这比密码更安全,注意要 chmod 600 /home/{yourname}/.ssh/authorized_keys
  • 按后台提示创建适合putty用的密钥对,保存好不要泄漏。
  • 开启密码登录(只使用ssh密钥可略过):修改/etc/ssh/sshd_config 找到其中 PasswordAuthentication no 一行,删除或改成 PasswordAuthentication yes
  • (接上条)增强ssh,不允许root用户直接登录、只允许指定用户(默认用户centos及前面新建用户)登录,/etc/ssh/sshd_config 结尾追加如下两行
    AllowUsers {yourname} centos
    PermitRootLogin no

    记得systemctl restart sshd 重启sshd

防火墙/iptables

lightsail后台防火墙默认只开了几个端口,而iptables则完全开放(添加一条规则“所有TCP+UDP” 即可),推荐防火墙全开,而开启linux的iptables。如果不能掌握iptables基础使用,还是使用后台防火墙吧。

yum install iptables-services
systemctl start iptables
systemctl enable iptables

这样 iptables -L就显示默认规则了,按需要开启端口

iptables -I INPUT 5 -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT

[tip] lightsai防火墙没有开启ping或icmp的选项,但当允许了“所有TCP+UDP” 后,就可以ping了。

SELinux

lightsail的CentOS 7默认是开启SELinux的,玩不来还是关了的好. 临时关闭setenforce 0,修改配置文件/etc/selinux/config永久关闭。