Win10子系统搭建Yum源

第1章 使用SSH登录Ubuntu

1.1 编辑SSHD配置文件

root@leon-PC:~# cat /etc/ssh/sshd_config
Port 2525
ListenAddress 127.0.0.1
PermitRootLogin yes
PermitEmptyPasswords no
PasswordAuthentication yes

1.2 开启ssh服务

root@leon-PC:~# /etc/init.d/ssh start

1.2.1 无法启动问题解决

【问题现象】:

Missing privilege separation directory: /var/run/sshd

【解决方法】:

创建sshd目录即可:

mkdir -p /var/run/sshd

1.3 查看ssh服务是否启动

root@leon-PC:~# ps -ef | grep ssh
leon       3     2  0 22:17 tty1     00:00:00 /bin/bash -c sudo /bin/mkdir -p /var/run/sshd;sudo /usr/sbin/nginx;sudo /usr/sbin/sshd -D
root         9     3  0 22:17 tty1     00:00:00 sudo /usr/sbin/sshd -D
root        14     9  0 22:17 tty1     00:00:00 /usr/sbin/sshd -D
root        15    14  0 22:17          00:00:00 sshd: root@pts/0   
root       143    88  0 22:28 pts/0    00:00:00 grep --color=auto ssh
注意:由于ubuntu子系统使用的是本机的网卡,所以端口可能被占用,且liunx上的netstat无法查看端口信息。

第2章 部署nginx服务

2.1 安装nginx

root@leon-PC:~# apt-get install -y nginx

2.2 编辑nginx配置文件

root@leon-PC:~# cat /etc/nginx/sites-enabled/default | egrep -v "#|^$"
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    root /mnt/d/yum;
    index index.html index.htm;
    autoindex on;
    server_name localhost;
    location / {
        try_files $uri $uri/ =404;
    }
}

2.3 启动nginx服务

root@leon-PC:~# nginx

2.4 查看nginx服务状态

root@leon-PC:~# ps -ef | grep nginx
leon       3     2  0 22:17 tty1     00:00:00 /bin/bash -c sudo /bin/mkdir -p /var/run/sshd;sudo /usr/sbin/nginx;sudo /usr/sbin/sshd -D
root         8     1  0 22:17          00:00:00 nginx: master pr
www-data    10     8  0 22:17          00:00:00 nginx: worker pr
www-data    11     8  0 22:17          00:00:00 nginx: worker pr
www-data    12     8  0 22:17          00:00:00 nginx: worker pr
www-data    13     8  0 22:17          00:00:00 nginx: worker pr
root       202    88  0 22:49 pts/0    00:00:00 grep --color=auto nginx

第3章 部署yum仓库

3.1 安装createrepo

root@leon-PC:~# apt-get install -y createrepo

3.2 同步yum源

3.2.1 同步CentOS 6.x的源

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ /mnt/d/yum/centos/6/os/x86_64/
/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/ /mnt/d/yum/centos/6/extras/x86_64/
/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ /mnt/d/yum/centos/6/updates/x86_64/
/usr/bin/rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /mnt/d/yum/epel/6/x86_64/

3.2.2 同步CentOS 7.x的源

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /mnt/d/yum/centos/7/os/x86_64/
/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /mnt/d/yum/centos/7/extras/x86_64/
/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ /mnt/d/yum/centos/7/updates/x86_64/
/usr/bin/rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /mnt/d/yum/epel/7/x86_64/

3.2.3 同步OpenStack源

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/7/cloud/x86_64/ /mnt/d/yum/centos/7/cloud/x86_64/

3.2.4 同步docker源(不可同步)

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/docker-ce/linux/centos/7/x86_64/ /mnt/d/yum/docker-ce/linux/centos/7/x86_64/

3.2.5 同步zabbix源

/usr/bin/rsync -av rsync://repo.zabbix.com/mirror/zabbix/3.4//rhel/7/x86_64/ /mnt/d/yum/zabbix/zabbix/3.4/rhel/7/x86_64
/usr/bin/rsync -av rsync://repo.zabbix.com/mirror/zabbix/3.4//rhel/6/x86_64/ /mnt/d/yum/zabbix/zabbix/3.4/rhel/6/x86_64
/usr/bin/rsync -av rsync://repo.zabbix.com/mirror/zabbix/3.0//rhel/7/x86_64/ /mnt/d/yum/zabbix/zabbix/3.0/rhel/7/x86_64
/usr/bin/rsync -av rsync://repo.zabbix.com/mirror/zabbix/3.0//rhel/6/x86_64/ /mnt/d/yum/zabbix/zabbix/3.0/rhel/6/x86_64

3.2.6 更多yum源参考

http://mirrors.ustc.edu.cn/

https://mirrors.tuna.tsinghua.edu.cn/status/

3.3 制作索引

3.3.1 创建索引

createrepo -pdo /yum/ /yum/

3.3.2 更新索引

createrepo -v --update /mnt/d/yum/
createrepo -v --update /mnt/d/yum/centos/6/extras/x86_64/
createrepo -v --update /mnt/d/yum/centos/7/extras/x86_64/
createrepo -v --update /mnt/d/yum/centos/6/os/x86_64/
createrepo -v --update /mnt/d/yum/centos/7/os/x86_64/
createrepo -v --update /mnt/d/yum/centos/6/updates/x86_64/
createrepo -v --update /mnt/d/yum/centos/7/updates/x86_64/
createrepo -v --update /mnt/d/yum/epel/6/x86_64/
createrepo -v --update /mnt/d/yum/epel/7/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/non-supported/rhel/6/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/non-supported/rhel/7/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/zabbix/3.0/rhel/6/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/zabbix/3.0/rhel/7/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/zabbix/3.4/rhel/6/x86_64/
createrepo -v --update /mnt/d/yum/zabbix/zabbix/3.4/rhel/7/x86_64/
createrepo -v --update /mnt/d/yum/docker-ce/linux/centos/7/x86_64/edge/
createrepo -v --update /mnt/d/yum/docker-ce/linux/centos/7/x86_64/stable/
createrepo -v --update /mnt/d/yum/docker-ce/linux/centos/7/x86_64/test/
createrepo -v --update /mnt/d/yum/centos/7/cloud/x86_64/openstack-newton/
createrepo -v --update /mnt/d/yum/centos/7/cloud/x86_64/openstack-ocata/
createrepo -v --update /mnt/d/yum/centos/7/cloud/x86_64/openstack-pike/

第4章 授权sudo

4.1 授权SSH

root@leon-PC:~# visudo -f /etc/sudoers.d/sshd
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/sshd -D
%sudo ALL=(ALL) NOPASSWD: /usr/bin/pkill ssh
%sudo ALL=(ALL) NOPASSWD: /bin/mkdir -p /var/run/sshd

4.2 授权Nginx

root@leon-PC:~# visudo -f /etc/sudoers.d/nginx
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/nginx
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/nginx -s stop
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/nginx reload

第5章 制作后台进程脚本

由于Windows10的Ubuntu子系统需要开启bash进程才可以提供服务,而Windows10本身并没有提供后台运行bash的程序,所以此处我们自己编写Windows的批处理文件和VBS脚本文件。

5.1 在Windows上编写开启文件

提示:将所有文件放置到统一级目录下。

5.1.1 编写开启SSH和Nginx的批处理文件

【文件名】:startsshd.bat

@echo off
REM 开启SSH服务和nginx服务

cd C:\Windows\System32
bash.exe -c "sudo /bin/mkdir -p /var/run/sshd;sudo /usr/sbin/nginx;sudo /usr/sbin/sshd -D"

5.1.2 编写后台开启运行bash的VB脚本

【文件名】:startsshd.vbs

dirPath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
 shellPath = dirPath & "\" &"startsshd.bat"
 ' wscript.echo shellPath
 set ws=wscript.createobject("wscript.shell")
 ws.run shellPath & " /start",0

5.2 编写关闭文件

5.2.1 编写关闭SSH和Nginx的批处理文件

【文件名】:stopsshd.bat

@echo off
REM 关闭SSH服务和nginx服务

cd C:\Windows\System32
bash.exe -c "sudo /usr/sbin/nginx -s stop;sudo /usr/bin/pkill ssh"

5.2.2 编写后台关闭运行bash的VB脚本

【文件名】:stopsshd.vbs

dirPath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
 shellPath = dirPath & "\" &"stopsshd.bat"
 ' wscript.echo shellPath
 set ws=wscript.createobject("wscript.shell")
 ws.run shellPath & " /stop",0

5.3 编写主批处理文件

【文件名】:本地yum源.bat

@echo off
:dosmenu
REM 选择菜单

echo [1] 开启yum源           [ 2] 关闭yum源
echo [3] 退出

set /P CHS= 请选择 

if /I "%CHS%"=="1" (
goto a
)
if /I "%CHS%"=="2" (
goto b
)
if /I "%CHS%"=="3" (
goto e
)

:a
REM 开启nginx
start D:\小程序\ubuntu\startsshd.vbs
pause
cls
goto e
:b
REM 更新yum源
start D:\小程序\ubuntu\stopsshd.vbs
pause
cls
goto e
:e
REM 退出
exit

第6章 测试结果

6.1 Web界面访问yum源

可以通过127.0.0.1或10.0.0.1(VMnet8的IP地址)或以太网卡IP访问yum源:

图片[1]|Win10子系统搭建Yum源|leon的博客

6.2 虚拟机访问

在虚拟机中配置10.0.0.1为本地yum源:

echo "10.0.0.1  mirrors.aliyun.com" >> /etc/hosts
温馨提示:本文最后更新于2022-12-20 20:57:51,已超过494天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/749.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享