Rootop 服务器运维与web架构

2023-08-11
发表者 Venus
vmware ESXi web登录提示incorrect user name or password已关闭评论

vmware ESXi web登录提示incorrect user name or password

esxi虚拟化web登录时提示错误:
Cannot complete login due to an incorrect user name or password.
此处弹这个提示是因为在控制台修改了密码,用新密码可以登录esxi控制台,说明密码是正确的。
只是web端没有生效。

解决方法就是重启management agent服务:

进入esxi控制台,依次找到

再登录就可以了。

2023-08-09
发表者 Venus
使用ovftool导出虚拟机模版已关闭评论

使用ovftool导出虚拟机模版

使用浏览器导出时会报错:无法下载,网络问题。不管是chrome还是edge都这样。
更换ovftool工具导出。

ovf -> Open Virtualization Format
下载链接:https://customerconnect.vmware.com/cn/downloads/details?downloadGroup=OVFTOOL430&productId=742

命令提示符里进入安装目录:

C:\Program Files\VMware\VMware OVF Tool>.\ovftool.exe vi://root@10.1.2.3/centos7 c:\
Accept SSL fingerprint (5E:43:82:E1:65:5D:22:5C:89:6F:67:A6:2B:6C:92:9C:44:91:F8:5D) for host 10.1.2.3 as source type.
Fingerprint will be added to the known host file
Write 'yes' or 'no'
yes
Enter login information for source vi://10.1.2.3/
Username: root
Password: *********
Opening VI source: vi://root@10.1.2.3:443/centos7
Opening OVF target: c:\
Writing OVF package: c:\centos7\centos7.ovf
Transfer Completed
Completed successfully

10.1.2.3 为虚拟化机器的ip
centos7为虚拟机名
就会导出到c盘下,并以虚拟机名新建一个文件夹。

2023-08-03
发表者 Venus
使用python或者php启动一个小型web服务已关闭评论

使用python或者php启动一个小型web服务

适合作为一个临时web服务器,下载站,文件中专,或者测端口连通性。

# python2版本 把当前目录作为网站根目录

$ python -m SimpleHTTPServer 8888

# python3版本 把当前目录作为网站根目录

$ python -m http.server 8888

# php

$ php -S 0.0.0.0:8888 -t ./

-t 参数指定目录作为网站目录,不加的话也是当前目录作为网站根目录。
放入一个php文件,可以直接访问。

2023-08-03
发表者 Venus
配置php-fpm服务走http代理已关闭评论

配置php-fpm服务走http代理

配置了http代理,端口10809。
# shell中设置http代理,输出2个环境变量。

$  export http_proxy=http://127.0.0.1:10809
$  export https_proxy=http://127.0.0.1:10809

$ curl https://www.rootop.org/ip2.php
ip地址为:192.227.146.237<br>

# 执行php脚本,默认也会走代理。
$ php c.php
HTTP/1.1 200 Connection established

HTTP/2 200
date: Thu, 03 Aug 2023 05:30:31 GMT
content-type: text/html; charset=UTF-8
strict-transport-security: max-age=604800; includeSubdomains; preload
x-frame-options: SAMEORIGIN

ip地址为:192.227.146.237<br>

默认情况下系统设置http_proxy和https_proxy环境变量后,shell里的命令操作基本都会走代理
比如 wget 、curl、php、git等

但是像php-fpm服务,就不会读取变量作为代理主动往外请求了。
也就是说通过浏览器访问php就不会走代理。
需要配置www.conf加入:

env[HTTP_PROXY] = http://127.0.0.1:10809
env[HTTPS_PROXY] = http://127.0.0.1:10809

重启php-fpm后才可以通过代理访问。
或者是在php里的curl中配置代理

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_PROXY, "http://127.0.0.1:10809");
curl_setopt($curl, CURLOPT_URL, 'https://www.rootop.org/ip2.php');
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
curl_close($curl);
print_r($data);

这种代理场景适合不让上外网的服务器,但是还要请求三方接口的情况。

2023-08-01
发表者 Venus
Amazon linux 2023没有/etc/rc.local文件已关闭评论

Amazon linux 2023没有/etc/rc.local文件

系统为 Amazon linux 2023

[root@rootop ~]# cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
SUPPORT_END="2028-03-01"

系统里已经没有 /etc/rc.local 文件,没法实现开机启动nginx,但是系统里提供了一个systemd服务叫 rc-local.service

[root@rootop ~]# cat /usr/lib/systemd/system/rc-local.service 

[Unit]
Description=/etc/rc.d/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

# 注意下面这2行默认是没有的,需要加上,否则不能使用 systemctl enable 实现开机运行,执行时会提示没有 installation config 
[Install]
WantedBy=multi-user.target

通过配置文件可以看到是执行了/etc/rc.d/rc.local脚本,这个脚本默认也没有,需要自己创建,并加上执行权限。

[root@rootop ~]# cat /etc/rc.d/rc.local 
#!/bin/bash
/home/software/openresty/nginx/sbin/nginx

[root@rootop ~]# chmod 777 /etc/rc.d/rc.local 

[root@rootop ~]# systemctl start rc-local
[root@rootop ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1632/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1507/sshd: /usr/sbi 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1632/nginx: master  
tcp6       0      0 :::22                   :::*                    LISTEN      1507/sshd: /usr/sbi 

[root@rootop ~]# systemctl enable rc-local
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /usr/lib/systemd/system/rc-local.service.

重启系统测试效果。