分类目录归档:Windows

Ansible 管理 Windows Server

如何用 Ansible 管理 Windows Server?Ansible 官方文档指出,需要以下两条先决条件:
PowerShell version 3.0 or NEW
.NET Framework 4.0 or NEW

一般情况下,Windows Server 2012 (含)以上的版本,PowerShell 和 .NET Framework 是满足以上两个条件的,那么 Windows Server 2008 如何被 Ansible 管理呢?当然如果网络条件允许的情况下,可以通过 官方脚本 自动升级,否则需要下载 离线安装包

一、作业环境

Operating System IP Remark
Windows Server 2008 R2 172.50.1.172 Ansible Client

二、开始吧

1.升级 PowerShell 和 .NET Framework

  • 参考本文前言超链接
  • 重新启动 Windows Server 2008 R2 之后,检查升级是否成功
get-host

图1

图1

2.开启 winrm 服务

# 1.查看powershell执行策略
get-executionpolicy

# 2.更改powershell执行策略为remotesigned【输入y确认】
set-executionpolicy remotesigned

# 3.配置winrm service并启动服务
winrm quickconfig

# 4.修改winrm配置,启用远程连接认证【这里是PowerShell的命令,如果用cmd的话,@前面的' 和 末尾的' 要去掉的】【如图2所示】
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

# 5.查看winrm service启动监听状态【如果有应答,说明服务配置并启动成功了】【如图3所示】
winrm enumerate winrm/config/listener

图2

图2

图3

图3

3.设置防火墙

允许 5985 端口入站通过

同网段机器,不过防火墙,端口一般都是通的,如果跨机房,需要允许 5985 通过

四、小贴士

  • 升级PowerShell到4.0要先升级.Net Franmwork;
  • 开启 winrm 服务在 CMD 下、PowerShell 下 语法是不一样的 ,本文是在 PowerShell 下进行的,有截图为证;

Windows Server 跨机房大文件传输解决方案

以下是需求背景介绍,各位看官可直接忽略,直奔主题。

北京冬奥会系统保障期间,安全工程师对各应用程式进行病毒扫描,将上海机房行情落地程式 superman.exe 识别成 Trojan Horse 并对其进行隔离,导致当日行情实时数据丢失,毫不知情地运作了 3 个交易日,已经对历史 K 线造成了影响。
而历史数据通常是非常多且大,各股票市场数据加起来约 200G 以上,需要从广东机房的行情主站 copy 数据到上海机房,在没有专线的情况下如何解决呢?于是乎,鄙人想到了 openssh 方案。

一、Enviroment

Operating SystemPrivate IPPublic IPLocationMark
Windows Server 2008 R2172.50.10.220180.77.23.41广东拥有完整数据的服务器
Windows Server 2012 R215.28.131.110180.68.24.42上海丢失数据的服务器

二、Install Open-SSH

1.建议将 安裝包 放置 C:\Program Files\OpenSSH\
2.然后用 Administrator 权限打开 PowerShell,来到 C:\Program Files\OpenSSH\ 路径下,输入以下命令进行安装、启动

powershell -ExecutionPolicy Bypass -File .\install-sshd.ps1
net start sshd
net start ssh-agent

3. 配置环境变量(继续在 PowerShell 中执行)

$env:Path="$env:Path;C:\Program Files\OpenSSH\"

以上操作,两台服务器都需进行

三、Configure

1.修改 sshd default port (在上海 15.28.131.110 上进行)

# 用文本编辑器打开 C:\ProgramData\ssh\sshd_config
# 将 Port=22 修改成 Port=9527 # 这里的 9527 是互联网端口,需要放行策略

2. 重启 sshd 服务

net stop sshd
net start sshd

四、Sync Data

开始同步数据,在广东 172.50.10.220 上,用 administrator 权限打开 PowerShell, 执行以下命令

scp.exe -r -P 9527 D:\data administrator@180.68.24.42:D:\data

五、More

更多参考文章
http://woshub.com/connect-to-windows-via-ssh/

windows安裝pip報錯問題

安裝pip時報錯現象如下

D:\>python get-pip.py
C:\Python38\lib\site-packages\setuptools\distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(
Looking in indexes: http://pypi.douban.com/simple
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
ERROR: Could not find a version that satisfies the requirement pip
ERROR: No matching distribution found for pip
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.

D:\>curl https://bootstrap.pypa.io/get-pip.py | python3。
'python3。' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

D:\>
D:\>curl https://bootstrap.pypa.io/get-pip.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1882k  100 1882k    0     0   171k      0  0:00:11  0:00:11 --:--:--  152k
C:\Python38\lib\site-packages\setuptools\distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(
Looking in indexes: http://pypi.douban.com/simple
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
ERROR: Could not find a version that satisfies the requirement pip
ERROR: No matching distribution found for pip
WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.

解決辦法

  • 在系统目录C:\Users\用户\AppData\Roaming新建pip文件夹
  • 在pip文件夹下新建pip.ini文件,并写入如下配置:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com

注意

  • 安裝Windows版python.exe時,一定要以管理員模式打開並安裝,否則pip要人肉安裝,比如我
  • curl get-pip.py 時,可以在任意盤符目錄,但當前用戶一定能可以訪問到該目錄
  • 這個報錯是 pip 版本 >=7 時,使用鏡像源時,會提示源地址不受信任或不安全,需要ssl安全認證