查看网卡命令
[root@localhost ~]# ip addr
1: lo:
2: ens32:
[root@localhost ~]#
重启网卡命令:
systemctl restart network.service
修改主机名
# 临时生效
hostname centos7
# 编辑配置文件/etc/hostname
# 以下命令可以直接修改配置文件
hostnamectl set-hostname centos7
操作:
[root@localhost ~]# hostnamectl set-hostname centos7
[root@localhost ~]# hostnamectl statusStatic hostname: centos7Icon name: computer-vmChassis: vmMachine ID: c981bff1414443848dc72e55d6f69e26Boot ID: 338c4215248c40598401ca7fa697636eVirtualization: vmwareOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-693.el7.x86_64Architecture: x86-64
[root@localhost ~]# hostname
centos7
[root@localhost ~]# cat /etc/hostname
centos7
修改字符集
# 两种方法
localectl set-locale LANG=zh_CN.UTF-8编辑/etc/locale.conf
操作:
[root@localhost ~]# localectl set-locale LANG=zh_CN.UTF-8
[root@localhost ~]# cat /etc/locale.conf
LANG=zh_CN.UTF-8
[root@localhost ~]# localectl statusSystem Locale: LANG=zh_CN.UTF-8VC Keymap: usX11 Layout: us
[root@centos7 ~]# echo $LANG
zh_CN.UTF-8
更改系统时间
[root@centos7 ~]# date
2017年 11月 02日 星期四 12:02:26 CST
[root@centos7 ~]# timedatectl set-time "2017-11-02 12:01:01"
[root@centos7 ~]# timedatectl statusLocal time: 四 2017-11-02 12:01:12 CSTUniversal time: 四 2017-11-02 04:01:12 UTCRTC time: 四 2017-11-02 04:01:12Time zone: Asia/Shanghai (CST, +0800)NTP enabled: n/a
NTP synchronized: noRTC in local TZ: noDST active: n/a
[root@centos7 ~]#
更改系统时区
/usr/bin/timedatectl list-timezones # 列出所有时区
/usr/bin/timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海
查看系统版本号
查看系统版本号:
cat /etc/redhat-release
所有支持systemd系统的统一发行版名称和版本号文件:
cat /etc/os-release
操作:
[root@centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@centos7 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
查看系统启动级别
文件查看
cat /etc/inittab
命令查看当前启动级别
systemctl get-default
设置启动级别
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5systemctl set-default multi-user.target
操作:
[root@centos7 ~]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#
[root@centos7 ~]# systemctl get-default
multi-user.target
[root@centos7 ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
管理服务
systemctl:融合service和chkconfig的功能于一体,兼容sysV和LSB得启动脚本,而且能够在进程启动过程中更有效地引导加载服务。
获取云主机外网IP地址
echo "`curl -s myip.ipip.net | awk -F " " '{print $2}'|awk -F":" '{print $2}'`_`hostname`" > /etc/hostname
设置开机启动
针对svn,nginx每次重启后均要手工启动,好麻烦,所以考虑将其做成开机启动,做成服务好麻烦,考虑像windows 一样,放在某个启动项中完成。
打开启动文件后,发现里面文件内容如下:
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
意思很简单,需要将此文件权限改为可执行的,这也是为何开机后此文件不能执行的原因
操作步骤:
a. 添加可执行权限:
# chmod +x /etc/rc.d/rc.localb. 打开文件rc.local:
# vim /etc/rc.d/rc.localc. 在文件rc.local末添加开机应启动的脚本:
svnserve -d -r /var/svn
/usr/nginx/sbin/nginxd. 重启机器,验证svn和nginx已经启动成功
# reboot