• linux下自有服务


    一.远程管理Linux服务器

    1.windows下远程连接工具

    xshell secureCRT putty

    2.windows下文件传输工具

    Filezilla winSCP

    二.远程连接服务端和客户端

    1.了解客户端,服务端

    IP+Port访问服务

    2.了解端口号的设定

    1~255 一般是知名端口号

    256~1023 一般是有Unix占用来提供特定的服务

    1024~5000 客户端的临时端口,随机产生

    大于5000 为互联网上的其他服务器

    3.了解ssh的作用

    用于linux下远程连接登录管理服务器的协议

    linux下开始sshd服务端(openssh-server)

    客户端:linux:openssh-clients

    ​ windows:xshell

    4.SSH服务器的启动/停止

    ssh服务的启动/停止/重启/查询状态
    service sshd start/stop/restart/status

    netstat 查看网络连接情况
    -n 不显示名称,
    -l 查看监听状态
    -t tcp协议
    -p 查看进程名字

    [root@yunwei1 back]# netstat -nltp|grep ssh
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4367/sshd
    tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 4809/sshd
    tcp 0 0 :::22 :::* LISTEN 4367/sshd
    tcp 0 0 ::1:6011 :::* LISTEN 4809/sshd
    [root@yunwei1 back]#

    lsof 根据端口查看连接情况
    [root@yunwei1 back]# lsof -i:22
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    sshd 4367 root 3u IPv4 30312 0t0 TCP *:ssh (LISTEN)
    sshd 4367 root 4u IPv6 30314 0t0 TCP *:ssh (LISTEN)
    sshd 4809 root 3r IPv4 40957 0t0 TCP 192.168.244.133:ssh->192.168.244.1:57474 (ESTABLISHED)
    [root@yunwei1 back]#

    5.修改ssh服务的默认端口

    /etc/ssh/sshd_config 配置文件
    搜索Port关键字,修改默认的端口号22即可,注意去掉前面的注释,

    6.基于ssh服务的命令

    (一).linux下客户端工具ssh

    语法:
    ssh 远程服务器的IP地址
    ssh -l inst01 192.168.244.132 使用inst01账号登录服务器
    ssh inst01@192.168.244.132 -p 22 使用inst01账号并且指定端口登录服务器

    案例如下
    [root@yunwei1 tmp]# ssh 192.168.244.132 -p 22
    root@192.168.244.132's password:
    Last login: Thu Mar 14 11:22:17 2019 from 192.168.244.133
    [root@yunwei2 ~]# exit
    logout
    Connection to 192.168.244.132 closed.
    [root@yunwei1 tmp]# ssh 192.168.244.132 -l inst01
    inst01@192.168.244.132's password:
    [inst01@yunwei2 ~]$ exit
    logout
    Connection to 192.168.244.132 closed.
    [root@yunwei1 tmp]#

    [root@yunwei1 spool]# ssh inst01@192.168.244.132
    inst01@192.168.244.132's password:
    Last login: Thu Mar 14 11:50:32 2019 from 192.168.244.133
    [inst01@yunwei2 ~]$

    (二).linux下远程拷贝命令scp

    scp 选项 要拷贝的文件 文件拷贝到哪里去
    -r 递归拷贝目录

    案例如下
    [inst01@yunwei2 ~]$ scp /etc/hosts root@192.168.244.132:/tmp
    The authenticity of host '192.168.244.132 (192.168.244.132)' can't be established.
    RSA key fingerprint is f0:8b:ac:c0:d1:bd:df:7e:59:92:96:72:e2:14:b6:71.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.244.132' (RSA) to the list of known hosts.
    root@192.168.244.132's password:
    hosts 100% 208 0.2KB/s 00:00
    [inst01@yunwei2 ~]$
    [root@yunwei1 tmp]# scp -r dir1 192.168.244.132:/tmp
    root@192.168.244.132's password:
    [root@yunwei1 tmp]#
    [root@yunwei2 tmp]# ll
    total 8
    drwxr-xr-x 2 root root 4096 Mar 14 20:04 dir1
    -rw-r--r-- 1 root root 208 Mar 14 20:01 hosts

    三.时间同步

    ntpdate 时间服务器ip或域名

    [root@yunwei2 tmp]# date -s "20181020 11:20:30"
    Sat Oct 20 11:20:30 CST 2018
    [root@yunwei2 tmp]# ntpdate cn.ntp.org.cn
    14 Mar 20:09:57 ntpdate[4098]: step time server 114.118.7.161 offset 12559646.887257 sec
    [root@yunwei2 tmp]# date +"%F %T"
    2019-03-14 20:10:45
    [root@yunwei2 tmp]#

    四.计划任务服务

    1.计划任务的作用

    让系统在将来某个时间执行一次或周期性地执行某个任务

    2.编写简单的周期性计划

     (一).系统计划任务相关文件

    /etc/cron.d/
    /etc/cron.d/0hourly 系统每小时第一分钟需要执行的任务
    /etc/cron.deny 用户拒绝列表(在该文件中的用户不能使用cron服务)
    /etc/crontab 该文件的作用相当于/etc/cron.d/下面的某一个文件,可以定义系统计划任务
    /etc/cron.monthly/ 存放系统每个月需要执行的脚本
    /etc/cron.weekly/ 存放系统每周需要执行的脚本
    /etc/cron.daily/ 存放系统每天需要执行的脚本
    /etc/cron.hourly/ 存放系统每小时需要执行的脚本
    /var/spool/cron 这个目录用来存放各个用户自己设定的定时任务,普通用户没有权限直接访问

    (二).计划任务的编写

    * * * * * 用户名 command
    分 时 日 月 周

    范围
    分:0~59
    时:0~23
    日:1~31
    月:1~12
    周:0~7(0和7都表示星期日)

    符号
    * 表示范围里的每一个数
    /n 每隔n隔单位(分/时/日/月/周)执行一次
    - 从几到几一个时间段
    , 表示分隔,间隔

    注意:
    run-parts:
    crond用这个工具来执行某个目录下所有的可执行脚本,定时任务中的每小时/每天/每周/每月任务就是通过这个工具来触发
    的.

    (三).创建.查看.删除计划任务


    1.用户编辑自己的计划任务
    crontab -l 查看当前用户的计划任务
    crontab -e 编辑当前用户的计划任务
    crontan -r 删除当前用户的计划任务

    2.管理员编写其他用户的任务
    crontab -e -u inst01 编辑指定用户的定时任务(使用环境变量EDITOR指定的默认编辑器)
    crontab -l -u inst01 列出指定用户所有的定时任务
    crontab -r -u inst01 删除指定用户所有的定时任务

  • 相关阅读:
    元组类型
    字符串类型
    列表类型
    python 循环
    python语句
    python运算符
    python1
    软件管理
    rpm yum
    LVM
  • 原文地址:https://www.cnblogs.com/golinux/p/10809031.html
Copyright © 2020-2023  润新知