分类目录归档:CentOS

Linux服务器,服务管理–systemctl命令详解,设置开机自启动

Linux服务器,服务管理–systemctl命令详解,设置开机自启动

syetemclt就是service和chkconfig这两个命令的整合,在CentOS 7就开始被使用了。
摘要: systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起。
任务 旧指令 新指令
使某服务自动启动 chkconfig –level 3 httpd on systemctl enable httpd.service
使某服务不自动启动 chkconfig –level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务 chkconfig –list systemctl list-units –type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service

 

下面以nfs服务为例:

1.启动nfs服务

systemctl start nfs-server.service

2.设置开机自启动

systemctl enable nfs-server.service

3.停止开机自启动

systemctl disable nfs-server.service

4.查看服务当前状态

systemctl status nfs-server.service

5.重新启动某服务

systemctl restart nfs-server.service

6.查看所有已启动的服务

systemctl list -units --type=service

开启防火墙22端口

iptables -I INPUT -p tcp --dport 22 -j ACCEPT

如果仍然有问题,就可能是SELinux导致的

关闭SElinux:

修改/etc/selinux/config文件中的SELINUX=”” 为 disabled,然后重启

彻底关闭防火墙:

sudo systemctl status  firewalld.service
sudo systemctl stop firewalld.service          
sudo systemctl disable firewalld.service
 

centos7下安装docker

一 环境准备

1、虚拟机or物理机

2、centos7系统(稳定,对docker支持友好)

二 安装过程

step1:使用yum命令进行安装

yum install -y docker

备注:-y 表示不询问 使用默认配置进行安装,等待提示  完毕!

step2:查看是否安装成功

yum list installed | grep docker

备注:命令为 查看yum安装完成文件列表 并 筛选docker安装信息 如下

step3:启动docker服务

systemctl start docker

step4:查看是否启动成功

systemctl status docker

step5:使用docker命令 

docker images

备注:查看docker已经安装的镜像 裸机状态下为空

 

设置docker开机自启动如下:

systemctl enable docker

使用如上命令就可以设置docker开机自启动了

 

centos7安装sftp服务器

 

sftp是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的网络的加密方法。sftp 与 ftp 有着几乎一样的语法和功能。SFTP 为 SSH的其中一部分,是一种传输档案至 Blogger 伺服器的安全方式。其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文件信息传输子系统,SFTP本身没有单独的守护进程,它必须使用sshd守护进程(端口号默认是22)来完成相应的连接和答复操作,所以从某种意义上来说,SFTP并不像一个服务器程序,而更像是一个客户端程序。SFTP同样是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP。

操作环境是centos7

 

1.添加用户组

 2.添加用户并设置为sftp组

//-g:加入主要组  -s指定用户登入后所使用的shell    -M:不要自动建立用户的登入目录

 

 3.修改sftp用户的密码,密码为yingyan@sftp.com

4.创建sftp用户的根目录和属主.属组,修改权限(755)

5.在sftp的目录中创建可写入的目录

6.修改sshd_config的配置文件

 

把原来的sshd_config配置文件里的subsystem行注释掉

在sshd_config文件最后添加

 

配置完成后重启配置

 

7.验证一下

 

 

 

如果你链接服务器的时候出现下面的提示:

> Write failed: Broken pipe     
> Couldn't read packet: Connection reset by peer

这个问题的原因是ChrootDirectory的权限问题,你设定的目录必须是root用户所有,否则就会出现问题。所以请确保sftp用户根目录的所有人是root, 权限是 750 或者 755。注意以下两点原则:

  • 目录开始一直往上到系统根目录为止的目录拥有者都只能是 root,用户组可以不是 root。

  • 目录开始一直往上到系统根目录为止都不可以具有群组写入权限 

  • 上面2点一定注意,仔细检查。我就是因为这个问题,导致一直有这个问题。仔细检查配置后,解决问题。

 

CentOS7使用firewalld打开关闭防火墙与端口

1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl –failed

3.配置firewalld-cmd

查看版本: firewall-cmd –version
查看帮助: firewall-cmd –help
显示状态: firewall-cmd –state
查看所有打开的端口: firewall-cmd –zone=public –list-ports
更新防火墙规则: firewall-cmd –reload
查看区域信息:  firewall-cmd –get-active-zones
查看指定接口所属区域: firewall-cmd –get-zone-of-interface=eth0
拒绝所有包:firewall-cmd –panic-on
取消拒绝状态: firewall-cmd –panic-off
查看是否拒绝: firewall-cmd –query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd –zone=public –add-port=80/tcp –permanent    (–permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd –reload
查看
firewall-cmd –zone= public –query-port=80/tcp
删除
firewall-cmd –zone= public –remove-port=80/tcp –permanent