centos init centos重启命令
大家好,今天来为大家分享centos init的一些知识点,和centos重启命令的问题解析,大家要是都明白,那么可以忽略,如果不太清楚的话可以看看本篇文章,相信很大概率可以解决您的问题,接下来我们就一起来看看吧!
CentOS7网络设置修复
服务器有两个网卡enp7s0和enp8s0
服务器需要通过enp8s0和互联网联通,互联网为笔记本转接
通过centos7界面修改ip,失败;
通过centos7的网络配置文件/etc/sysconfig/network-scripts/ifcfg-enp8s0修改ip设置
设置如下:
1.启动 service network start报错,通过journalctl-xe查看如下
-- Defined-By: systemd
-- Support:
--
-- Unit fprintd.service has begun starting up.
12月 29 19:31:12 crrchost dbus-daemon[851]: dbus[851]: [system] Successfully activated service'net.reactivated.Fprint'
12月 29 19:31:12 crrchost dbus[851]: [system] Successfully activated service'net.reactivated.Fprint'
12月 29 19:31:12 crrchost systemd[1]: Started Fingerprint Authentication Daemon.
-- Subject: Unit fprintd.service has finished start-up
-- Defined-By: systemd
-- Support:
--
-- Unit fprintd.service has finished starting up.
--
-- The start-up result is done.
12月 29 19:31:12 crrchost fprintd[6685]: Launching FprintObject
12月 29 19:31:12 crrchost fprintd[6685]:** Message: D-Bus service launched with name: net.reactivated.Fprint
12月 29 19:31:12 crrchost fprintd[6685]:** Message: entering main loop
12月 29 19:31:18 crrchost polkitd[835]: Operator of unix-session:1 successfully authenticated as unix-user:windfarm to gain TEMPORARY authorization for action org.freedesktop.systemd1.manage-units for system-bus
12月 29 19:31:18 crrchost systemd[1]: Starting LSB: Bring up/down networking...
-- Subject: Unit network.service has begun start-up
-- Defined-By: systemd
-- Support:
--
-- Unit network.service has begun starting up.
12月 29 19:31:18 crrchost network[6693]:正在打开环回接口: [ 确定 ]
12月 29 19:31:18 crrchost network[6693]:正在打开接口 enp7s0:
12月 29 19:31:24 crrchost network[6693]:正在确定 enp7s0的 IP信息...失败:不存在链接。检查电缆?
12月 29 19:31:24 crrchost network[6693]: [失败]
12月 29 19:31:24 crrchost network[6693]:正在打开接口 enp8s0: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: [ 确定 ]
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost network[6693]: RTNETLINK answers: File exists
12月 29 19:31:25 crrchost systemd[1]: network.service: control process exited, code=exited status=1
12月 29 19:31:25 crrchost systemd[1]: Failed to start LSB: Bring up/down networking.
-- Subject: Unit network.service has failed
-- Defined-By: systemd
-- Support:
--
-- Unit network.service has failed.
--
-- The result is failed.
12月 29 19:31:25 crrchost systemd[1]: Unit network.service entered failed state.
12月 29 19:31:25 crrchost systemd[1]: network.service failed.
12月 29 19:31:25 crrchost polkitd[835]: Unregistered Authentication Agent for unix-process:6669:319312(system bus name:1.263, object path/org/freedesktop/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8)(d
3.systemctl status network.service查看如下:
● network.service- LSB: Bring up/down networking
Loaded: loaded(/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: failed(Result: exit-code) since六 2018-12-29 18:38:17 CST; 1min 24s ago
Docs: man:systemd-sysv-generator(8)
Process: 909 ExecStart=/etc/rc.d/init.d/network start(code=exited, status=1/FAILURE)
12月 29 18:38:06 crrchost systemd[1]: Starting LSB: Bring up/down networking...
12月 29 18:38:06 crrchost network[909]:正在打开环回接口: [ 确定 ]
12月 29 18:38:06 crrchost network[909]:正在打开接口 enp7s0:
12月 29 18:38:12 crrchost network[909]:正在确定 enp7s0的 IP信息...失败:…?
12月 29 18:38:12 crrchost network[909]: [失败]
12月 29 18:38:17 crrchost network[909]:正在打开接口 enp8s0: [ 确定 ]
12月 29 18:38:17 crrchost systemd[1]: network.service: control process exi...=1
12月 29 18:38:17 crrchost systemd[1]: Failed to start LSB: Bring up/down n...g.
12月 29 18:38:17 crrchost systemd[1]: Unit network.service entered failed...e.
12月 29 18:38:17 crrchost systemd[1]: network.service failed.
Hint: Some lines were ellipsized, use-l to show in full.
1.参考网络方法停用NetworkManager,依旧报错
systemctl stop NetworkManager
systemctl disable NetworkManager
2.比对两个网卡的MAC地址和配置文件的MAC地址
a.查看mac地址配置,ipconfig
b.查看配置文件中的macd地址是否匹配,ifcfg-enp8s0和ifcfg-enp7s0,
按照网络方法增加一行HWADDR=ipconfig查询到的对应网卡MAC地址;
c.重启network服务依旧报错;
3.通过GUI界面查看网络,提示“系统的网络服务与此版本的网络管理器不兼容”
这与之前停掉NetworkManager有关,此处不表;
4.因为ifcfg-enp7s0实际上没有插网线,修正其配置文件如下:
ONBOOT=no
重新启动服务后网络正常;
5.检查网络
1.network和NetworkManager不同,通过界面和通过配置文件,可能会导致配置混乱,且NetworkManager有些程序不支持,需要停用;
2.BOOTPROTO=none虽然可以表示静态ip,但是如果要启用,必须设置其为
BOOTPROTO=static或BOOTPROTO=dhcp
3.一个网卡没哟被启用,也就是没有设置动态ip或静态ip,是无法被初始化的,不能设置ONBOOT=yes
In Centos7.0 disabling NetworkManager will leave a dhcp client running configured for NetworkManager. This causes the error message RTNETLINK answers: File exists when the network service is started.
The stale dhclient process has the additional"benefit" that when the lease expires your dhclientwill choke, since it cannot reach NetWorkManager, thus removing your IP address.
If you grep for it, you will see that it points to a NetWorkManager configuration file.
[root@host~]# ps-ef| grep dhc
root 1865 792 0 Apr28? 00:00:00/sbin/dhclient-d-sf\
/usr/libexec/nm-dhcp-helper-pf/var/run/dhclient-eno1.pid-lf\
/var/lib/NetworkManager/dhclient-c96e56d3-a4c9-4a87-85ca-93dc0ca268f2-eno1.lease\
-cf/var/lib/NetworkManager/dhclient-eno1.conf eno1
So what you can do is kill the dhclient and only then start your network service.
求助nat123 linux版CentOS7开机启动问题
单独执行chkconfig命令有没有问题?
systemctl是系统服务管理器命令,它实际上将 service和 chkconfig这两个命令组合到一起的。
# chkconfig:- 80 60这个-符号表示不自动启动,可以使用345等运行级别启动的。
附:centos开机启动服务方法:利用 chkconfig来配置启动级别
在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd、mysqld、postfix等,安装后系统默认不会自动启动的。就算手动执行/etc/init.d/mysqld start启动了服务,只要服务器重启后,系统仍然不会自动启动服务。在这个时候,我们就需要在安装后做个设置,让系统自动启动这些服务,避免不必要的损失和麻烦。其实命令很简单的,使用chkconfig即可。
比如要将nat123设置为开机自动启动:
chkconfig mysqld on
要取消掉某个服务自动启动,只需要将最后的参数“on”变更为“off”即可。
比如要取消 postfix的自动启动:
chkconfig postfix off
值得注意的是,如果这个服务尚未被添加到 chkconfig列表中,则现需要使用–-add参数将其添加进去:
chkconfig–-add postfix
如果要查询当前所有自动启动的服务,可以输入:
chkconfig-–list
如果只想看指定的服务,只需要在“–-list”之后加上服务名就好了,比如查看httpd服务是否为自动启动:
chkconfig–-list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
此时0~6均为off,则说明httpd服务不会在系统启动的时候自动启动。我们输入:
chkconfig httpd on
则此时为:
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
这个时候2~5都是on,就表明会自动启动了。
CentOS系统常规初始化操作详解
环境准备:
1)设置本地国际化语言为en_US.UTF-8
[root@c58~]#sed-i's/^\(LANG=\).*$/\1en_US.UTF-8/'/etc/sysconfig/i18n
[root@c58~]#cat/etc/sysconfig/i18n
LANG=en_US.UTF-8
[root@c58~]#LANG=en_US.UTF-8
2)更新系统软件包
备份默认yum源:
find/etc/yum.repos.d-name'*.repo'-execmv{}{}.bak\;
添加163yum源:
redhat5或centos5:
wget
redhat6或centos6
wget
添加epel yum源:
redhat5.x 32bit:
rpm-ivh
redhat5.x 64bit:
rpm-ivh
redhat6.x 32bit:
rpm-ivh
redhat6.x 64bit:
rpm-ivh
更新证书:
yum-yupgradeca-certificates--disablerepo=epel
更新系统所有软件包:
yumcleanallyummakecacheyum-yupgrade
下文以redhat5/centos5为例
一、服务最小化原则
关闭所有开机自启动服务,仅开启sshd、crond、network、iptables、syslog(redhat5)、rsyslog(redhat6),然后在此基础上按需添加需要开机启动的服务。
1)关闭所有开机自启动服务
[root@c58~]#foriin`chkconfig--list|awk'{if($1~/^$/){exit0;}else{print$1}}'`;dochkconfig$ioff;done
2)开启基础服务
[root@c58~]#foriinsshdnetworksyslogcrondiptables;dochkconfig$ion;done
3)查看开启的服务
[root@c58~]#chkconfig--list|grep'3:on'
crond0:off1:off2:on3:on4:on5:on6:off
iptables0:off1:off2:on3:on4:on5:on6:off
network0:off1:off2:on3:on4:on5:on6:off
sshd0:off1:off2:on3:on4:on5:on6:off
syslog0:off1:off2:on3:on4:on5:on6:off
二、用户登录限制
1)禁止使用root用户使用远程ssh
[root@c58~]#cd/etc/ssh
[root@c58ssh]#cpsshd_configsshd_config~
[root@c58ssh]#sed-i's/#\(PermitRootLogin\)yes/\1no/'sshd_config
[root@c58ssh]#grep'PermitRoot'/etc/ssh/sshd_config
PermitRootLoginno
2)禁用登录提示信息
[root@c58ssh]#/etc/motd
3)修改ssh的默认监听端口(tcp:22)
#这里修改为tcp的11983端口
[root@c58ssh]#sed-i's/#\(Port\)22/\11983/'sshd_config
[root@c58ssh]#grep'Port'sshd_config
Port11983
4)只允许指定的ip可以ssh(可选)
方法1(使用tcpwrapper):
#只允许192.168.124.0网段的ip使用ssh
echosshd:192.168.124.0/255.255.255.0/etc/hosts.allow
echosshd:ALL/etc/hosts.deny
方法2(使用iptables):
#注意,远程操作时需留心,以免把自己也拒绝而导致无法远程连接。如只允许192.168.1.0网段的所有ip进行ssh,其他所有ip都拒绝#先允许自己的ip,以防被后面的操作误伤
iptables-IINPUT-s10.0.0.1-ptcp--dport22-jACCEPT
#允许192.168.1.0网段
iptables-I2INPUT-s192.168.1.0/24-ptcp--dport22-jACCEPT
#拒绝所有
iptables-I3INPUT-ptcp--dport22-jDROP
#保存iptables的设置:
cp/etc/sysconfig/iptables/etc/sysconfig/iptables~
iptables-save/etc/sysconfig/iptables
最后,重启sshd服务使上面配置生效(不用担心重启时已打开的远程终端连接会断开,重启只会对新开的终端生效)
[root@c58ssh]#/etc/init.d/sshdrestart
Stoppingsshd:[OK]
Startingsshd:[OK]
三、用户及命令权限最小化
创建一个普通用户tom,将其加入sudo组,该用户作为系统管理员
groupaddsudo#创建sudo组
useradd-Gsudotom#创建tom用户,加入sudo组
passwdtom#设置tom用户的登陆密码
修改sudo配置文件,授权sudo组的用户可以以root身份执行所有命令(可以针对不同用户授予不同的命令执行权限,这里允许执行所有命令,生产环境中系统管理员应该按需为用户分配尽可能少的可执行命令,以实现权限最少化),用户执行的所有sudo操作都将记录在/var/log/sudo.log中,以便日后的安全事件排查。执行命令如下:
[root@cloud~]#cat/etc/sudoersEOF
%sudoALL=(root)ALL
Defaultslogfile=/var/log/sudo.log
EOF
[root@cloud~]#visudo-c
[root@cloud~]#echolocal2.debug/var/log/sudo.log/etc/syslog.conf
[root@cloud~]#/etc/init.d/syslogrestart
注:visudo-c命令用于检查/etc/sudoers文件的语法正确性
四、内核安全参数设置
vim/etc/sysctl.conf#添加如下内容:
#关闭对ping包的响应(可选,一般不建议,因为不方便网络故障时的排查)
net.ipv4.icmp_echo_ignore_all=1
#关闭对广播ping的响应
net.ipv4.icmp_echo_ignore_broadcasts=1
#开启syncookie用于防范synflood攻击,当出现syn等待队列溢出时(syn数量超过tcp_max_syn_backlog的设置值),启用cookie来处理,server在回复syn_ack前会先请求client回复一个序列号,该序列号中要求包含原先syn包中的信息,如果序列号不正确,则server端会忽略此syn连接。
net.ipv4.tcp_syncookies=1
#设置sync_ack的最大重传次数,默认值为5,范围0-255,重传5次的时间大约为180s
net.ipv4.tcp_synack_retries=3
#设置当keepalive打开的情况下,keepalive消息的发送间隔,默认为2小时(由于目前网络攻击等因素,造成了利用这个进行的攻击很频繁,如果两边建立了连接,然后不发送任何数据或者rst/fin消息,那么持续的时间就是2小时,成就了空连接攻击,tcp_keepalive_time就是预防此情形的.)
net.ipv4.tcp_keepalive_time=1200
保存退出后,执行sysctl-p命令将以上设置加载到内核使其立刻生效
五、内核性能相关参数设置(可选)
vim/etc/sysctl.conf#添加如下内容:
#设置syn等待队列的长度,对于内存大于128M的机器,默认值是1024,在并发请求较大时,可以调大该值
net.ipv4.tcp_max_syn_backlog
#开启timewait重用。允许将time_waitsocket重新用于新的tcp连接
net.ipv4.tcp_tw_reuse=1
#开启tcp连接中time_waitsocket的快速回收
net.ipv4.tcp_tw_recycle=1
#TCP发送keepalive探测以确定该连接已经断开的次数,默认值为9
net.ipv4.tcp_keepalive_probes=5
#指定探测消息发送的频率,该值乘以tcp_keepalive_probes就可以得到从开始探测到连接被删除所需的时间。默认值为75,也就是没有活动的连接将在大约11分钟以后将被丢弃。(对于普通应用来说,这个值有一些偏大,可以根据需要改小.特别是web类服务器需要改小该值,15是个比较合适的值)
net.ipv4.tcp_keepalive_intvl=15
#表示系统同时保持TIME_WAITsocket的最大数量,如果超过这个数字,TIME_WAIT套接字将立刻被清除并输出警告信息。默认为180000,改为5000.对于squid服务器来说,此参数可以控制TIME_WAIT套接字的最大数量,避免squid服务器被大量的TIME_WAITsocket拖死。
net.ipv4.tcp_max_tw_buckets=5000
#表示向外连接的端口范围。默认值很小:32768~61000,改为1024~65000
net.ipv4.ip_local_port_range=102465000
保存退出后,执行sysctl-p命令将以上设置加载到内核使其立刻生效