记一套配置流程,仅供参考
环境
Window10
Hyper-V
Centos7.6 minimal 下载
安装过程
略
网络配置
连接默认交换机已经可以使用外网
也可以另外创建NAT网络(确定可行,如果有问题仔细检查一遍)
管理员权限运行powershell
创建虚拟交换机
New-VMSwitch –SwitchName "NET-VM" –SwitchType Internal –Verbose
查看网路适配器,找到"NAT-VM"的ifIndex
Get-NetAdapter
设置IP InterfaceIndex参数为ifIndex
New-NetIPAddress –IPAddress 192.168.78.1 -PrefixLength 24 -InterfaceIndex 37 –Verbose
创建NET网络(关键)
New-NetNat –Name NATNetwork –InternalIPInterfaceAddressPrefix 192.168.78.0/24 –Verbose
Centos静态ip配置
ip查看命令:ip addr
进入目录查看网卡配置文件
cd /etc/sysconfig/network-scripts/
ls
修改
vi ifcfg-eth0
BOOTPROTO=static
IPADDR=192.168.78.101
NETMASK=255.255.255.0
GATEWAY=192.168.78.1
ONBOOT=yes
重启网卡
systemctl restart network
域名解析
vi /etc/resolv.conf
nameserver 114.114.114.114
挂载数据盘
新建虚拟盘
查看分区情况
df -h
查看磁盘,应该有个sdb
fdisk -l
格式化磁盘,n新建分区,w写入,q退出,p当前分区,m帮助
fdisk /dev/sdb
格式化文件系统
mkfs.ext4 /dev/sdb1
挂载
mkdir /data
mount /dev/sdb1 /data
开机自动挂载,需写入fstab
vi /etc/fstab
加入
/dev/sdb1 /data ext4 defaults 0 0
磁盘可用uuid表示,例如
uuid=xxxxxxxxxx /data ext4 defaults 0 0
其它命令
卸载分区
umount /dev/sdb1
查uuid
blkid
内核重新读取分区表
partprobe /dev/sdb
补充挂载windows共享
首先确定共享一个windows文件夹
这里举个栗子
- lusrmgr.msc新建一个账户vhost,配置密码123456,隶属于Users
- gpedit.msc打开策略组
计算机配置=>Windows设置=>安全设置=>用户权限分配
“拒绝本地登录”,“拒绝通过远程桌面服务登录” 这两项中加入vhost账户
计算机配置=>Windows设置=>安全设置=>安全选项
配置项:“网络访问:本地账户的共享和安全模型” 为 “经典-对本地用户身份验证,不改变器本来身份”
刷新策略组(实际上不需要):gpupdate /force - 配置防火墙,一般没问题,除非你有意禁用掉了例如因为wannercry2.0,有问题注意检查:UDP 137, 138 TCP 139, 445(网上的方法动不动就关闭防火墙,认真的吗)
- 创建一个文件夹VShare,新建一个文本文件“新建文本文档.txt” (样例)
- 共享VShare给vhost,注意添加权限,下面操作Linux
- 安装软件包 yum install cifs-utils
- 创建挂载点 mkdir /share
- 挂载 mount -t cifs -o user=vhost,password=123456 //192.168.78.1/VShare /share
- ll /share 可以看到刚的 “新建文本文档.txt”
- 可以配置为开机自动挂载
vi /etc/fstab
加入 //192.168.78.1/VShare /share cifs user=vhost,password=123456 - 另外 可以用 samba
- 安装 yum install samba-client
- 可以查看共享的信息 smbclient -L //192.168.78.1 -U vhost
- 其它命令网上找
如果需要windows做端口映射
netsh interface portproxy help
修改需要管理员权限
例如:
添加
netsh interface portproxy add v4tov4 listenport=22 listenaddress=* connectport=22 connectaddress=192.168.78.101
查看
netsh interface portproxy show all
删除
netsh interface portproxy delete v4tov4 listenport=22
其它可能需要的安装命令
缺netstat
yum install net-tools.x86_64
缺sar
yum install sysstat
yum install gd
缺wget
yum install wget
缺sshd
yum install openssh-server
缺vim
yum install vim*
时间同步(IMPORTANT)
yum install ntpdate
NTP服务器(上海) :ntp.api.bz
ntpdate -u ntp.api.bz
关闭firewalld(也可以开端口,或者换iptables)
systemctl stop firewalld
systemctl disable firewalld
yum install iptables
yum install iptables-services
vi /etc/sysconfig/iptables
略
修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
查看
ls -l /etc/localtime
date
nginx安装
各种依赖
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载安装
wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
做成服务
cd /etc/systemd/system
vi nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
建立软连接(设置开机启动需要)
ln -s /usr/lib/systemd/system/nginx.service /etc/systemd/system/multi-user.target.wants/nginx.service
启动
systemctl start nginx.service
设置开机启动
systemctl enable nginx.service
管理
nginx.service
配置
cd /usr/local/nginx/conf
vi nginx.conf
server {
listen 80;
server_name sup.vhost.net;
location /{
proxy_pass http://127.0.0.1:9001;
proxy_redirect off;
proxy_set_header Host $host:$proxy_port;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
部分多余,方便抄写
另外需要修改windows hosts文件,路径C:\Windows\System32\drivers\etc
192.168.78.101 sup.vhost.net
Python安装
各种依赖
//yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
下载安装
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar zxvf Python-3.7.3.tgz
cd Python-3.7.3/
./configure --prefix=/usr/local/python-3.7.3
make && make install
软连接
ln -s /usr/local/python-3.7.3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python-3.7.3/bin/pip3.7 /usr/bin/pip3
virtaulenv
pip3 install virtualenv
使用案例
cd /opt
mkdir test
cd test
vi test.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
while True:
print('test')
time.sleep(10)
python3 -m virtualenv venv
(也许需要其它版本 python3 -m virtualenv -p /usr/bin/python2 venv)
pip也需要用 venv/bin/pip3
例如
venv/bin/pip3 list
venv/bin/pip3 install -r requirements.txt
Supervisor安装
安装EPEL
yum install epel-release
安装supervisor
yum install supervisor
管理配置
vim /etc/supervisord.conf
[inet_http_server] 修改 port user password
程序配置
可参看/etc/supervisord.conf中说明
cd /etc/supervisord.d
vi test.ini
[program:test]
command=/opt/test/venv/bin/python -u /opt/test/test.py
stdout_logfile=/var/log/supervisor/test/log
;stderr_logfile=/var/log/supervisor/test/err
redirect_stderr=true
autostart=true
autorestart=true
priority=1
numprocs=1
startretries=10
exitcodes=0
stopssignal=KILL
stopwaitsecs=10
mkdir /var/log/supervisor/test
管理
supervisord.service
管理程序
supervisorctl help
常用
supervisorctl status [gname]
supervisorctl stop [gname]
supervisorctl start [gname]
supervisorctl restart [gname]
supervisorctl update [gname]:加载新配置
supervisorctl reload : 重新启动配置中的所有程序(慎重)
报错
unix:///var/run/supervisor/supervisor.sock no such file
因为没开启supervisor
supervisord -c /etc/supervisord.conf
管理界面
配合刚nginx和python的配置案例
可打开sup.vhost.net
如果不出意外test的运行状态正常
数据盘
可以把上述的项目和日志放在数据盘
并在数据盘写启动脚本
在迁移之前需要注意删除检查点,让数据盘先合并成一个
linux管理
仅供参考,更多使用方法--help
查看端口使用
tcp端口
netstat -ntlp
某个端口
netstat -an | grep 80
简单统计
netstat -an | grep 80 | wc
进程查看
ps -ef | grep nginx
网速查看
sar -n DEV 1
磁盘占用大小
df -h
du -h -d 0
网友评论