RHEL/CentOS 7.X 安装笔记
配置vim
# 配置 vim 编辑器
yum install vim rm /usr/bin/vi ln -s /usr/bin/vim /usr/bin/vi vi /etc/vimrc
# 开启语法高亮,和行号 syntax on set nu
# tab键替换成4个空格 set tabstop=4 set expandtab
# 杂项配置
export HISTSIZE=1000 # 如果设置为0, 则不能上下翻查看历史命令。
关闭不必要的服务
# centos7下防火墙核心仍基于iptables实现,但iptables服务并没有装,因此禁用防火墙要用如下指令:
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl stop postfix.service
systemctl disable postfix.service
# 关闭SELinux, 查看当前 SELinux 状态
getenforce
# disable SELinux 需要重启生效
vi /etc/selinux/config
SELINUX=disabled
后台服务管理
# 以 httpd 举例说明:
systemctl start httpd.service # 启动服务
systemctl stop httpd.service # 停止服务
systemctl restart httpd.service # 重启服务
systemctl status httpd.service # 检查服务状态
systemctl enable httpd.service # 开机启用
systemctl disable httpd.service # 开机禁用
systemctl # 列出正在运行的服务
systemd-cgls # 以树形列出正在运行的进程
# 列出正在运行的服务 [root@bogon ~]# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION sys-devices-platform-floppy.0-block-fd0.device loaded active plugged /sys/devices/platform/floppy.0/block/fd0 sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2 sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3 sys-devices-pnp0-00:09-tty-ttyS0.device loaded active plugged /sys/devices/pnp0/00:09/tty/ttyS0 sys-devices-pnp0-00:0a-tty-ttyS1.device loaded active plugged /sys/devices/pnp0/00:0a/tty/ttyS1 sys-devices-virtual-block-dm\x2d0.device loaded active plugged /sys/devices/virtual/block/dm-0 sys-devices-virtual-block-dm\x2d1.device loaded active plugged /sys/devices/virtual/block/dm-1 sys-module-configfs.device loaded active plugged /sys/module/configfs # 以树形结构列出正在运行的进程 [root@bogon ~]# systemd-cgls ├─1 /usr/lib/systemd/systemd --system --deserialize 20 ├─user.slice │ └─user-0.slice │ ├─session-2.scope │ │ └─10575 /usr/sbin/anacron -s │ └─session-1.scope │ ├─10390 sshd: root@pts/0 │ ├─10394 -bash │ ├─11037 systemd-cgls │ └─11038 systemd-cgls └─system.slice ├─systemd-udevd.service │ └─10976 /usr/lib/systemd/systemd-udevd ├─vsftpd.service │ ├─10879 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf │ ├─10880 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf │ └─10885 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf ├─tuned.service │ └─1274 /usr/bin/python -Es /usr/sbin/tuned -l -P ├─sshd.service │ └─1273 /usr/sbin/sshd -D ├─polkit.service │ └─844 /usr/lib/polkit-1/polkitd --no-debug ├─wpa_supplicant.service │ └─843 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid ├─NetworkManager.service │ ├─ 759 /usr/sbin/NetworkManager --no-daemon │ └─1083 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens33.pid -lf /var/lib/NetworkManager/dhclient-70e8fbc4-3c26-4e06-8c14-f88d5e72967c-ens33.lease -cf /var/l ├─crond.service │ └─685 /usr/sbin/crond -n ├─dbus.service │ └─663 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation ├─rsyslog.service │ └─660 /usr/sbin/rsyslogd -n ├─systemd-logind.service │ └─655 /usr/lib/systemd/systemd-logind ├─auditd.service │ └─631 /sbin/auditd -n ├─lvm2-lvmetad.service │ └─546 /usr/sbin/lvmetad -f ├─system-getty.slice │ └─getty@tty1.service │ └─687 /sbin/agetty --noclear tty1 linux └─systemd-journald.service └─525 /usr/lib/systemd/systemd-journald
修改系统运行级别
systemd 不再使用 /etc/inittab 文件来控制运行级别。而是使用 target 替代了原来的 sysvinit。 # 新的映射关系为: multi-user.target: analogous to runlevel 3 graphical.target: analogous to runlevel 5 # 查看当前运行级别: 方法一: runlevel 方法二: ls -l /etc/systemd/system/default.target # 改变默认的运行级别: rm /etc/systemd/system/default.target ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target # 改成级别3 ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target # 改成级别5
基于nginx搭建YUM源
# 配置nginx server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /media; index index.html index.htm; autoindex on; autoindex_exact_size off; autoindex_localtime on; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
# 将光驱挂在至 /media 目录
mount /dev/cdrom /media
# 设置 /etc/yum.repos.d/steven.repo [rhel-dvd] name=remote copy of dvd baseurl=http://192.168.245.136:80/ gpgcheck=0 enabled=1
安装常用软件
yum install net-tools # 包含 netstat, yum install tree yum install wget yum install man yum install telnet yum install ftp yum install nc yum install lrzsz yum install dos2unix yum install bind-utils # 跟DNS相关的指令 yum install gdb yum install python-devel yum install python-mako yum groupinstall 'Development Tools'