Centos7安装后的相关配置
一、关闭firewall和SELINUX
- 关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
一行命令执行
systemctl stop firewalld.service && systemctl disable firewalld.service
- SELINUX
vi /etc/selinux/config
将SELINUX=enforcing
改为SELINUX=disabled
一行命令执行
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
二、软件源设置
阿里云源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
# EPEL源
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
三、常用软件安装
yum install -y vim net-tools lrzsz
yum install -y atop htop
四、主机时间设置
查看所有的时区timedatectl list-timezones
设置时区timedatectl set-timezone Asia/Shanghai
设置NTP服务器的开启和关闭
yum install ntp -y
systemctl start ntpd
systemctl enable ntpd
ntpdate cn.ntp.org.cn
开启NTP:timedatectl set-ntp yes
关闭NTP:timedatectl set-ntp no
当然timedatectl命令还可以设置日期与时间
设置日期:timedatectl set-time YYYY-MM-DD
设置时间:timedatectl set-time HH:MM:SS
将硬件时钟调整为与本地时钟一致hwclock --systohc --localtime
五、系统设置
-
修改系统语言环境
sudo echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile
-
修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
Kernel性能调优
cat >> /etc/sysctl.conf<<EOF net.ipv4.ip_forward=1 watchdog_thresh=30 net.bridge.bridge-nf-call-iptables=1 net.ipv4.neigh.default.gc_thresh1=4096 net.ipv4.neigh.default.gc_thresh2=6144 net.ipv4.neigh.default.gc_thresh3=8192 EOF
其他
Apache httpd
安装
yum -y install httpd
rm -f /etc/httpd/conf.d/welcome.conf
简单配置
vi /etc/httpd/conf/httpd.conf
修改如下
# line 86: change to admin's email address
ServerAdmin root@srv.world
# line 95: change to your server's name
ServerName www.srv.world:80
# line 151: change
AllowOverride All
# line 164: add file name that it can access only with directory's name
DirectoryIndex index.html index.cgi index.php
# add follows to the end
# server's response header
ServerTokens Prod
# keepalive is ON
KeepAlive On
设置开机启动
systemctl start httpd && systemctl enable httpd
测试
vi /var/www/html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page
</div>
</body>
</html>
PHP
安装PHP
yum install php -y
安装PHP组件,使PHP支持mysql
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash -y
重启对应服务
systemctl restart httpd.service
###MariaDB数据库
安装
yum -y install mariadb-server
设置字符编码和表名不区分大小写
vi /etc/my.cnf
增加
[mysqld]
character-set-server=utf8
lower_case_table_names=1
设置开机启动
systemctl start mariadb && systemctl enable mariadb
初始化配置,设置密码等
mysql_secure_installation
允许Root用户远程访问GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'passwd' WITH GRANT OPTION;
###安装网络流量监控工具
安装所需依赖包
yum install -y gcc flex byacc libpcap ncurses ncurses-devel libpcap-devel tcpdump
下载源码并编译安装
# cd /usr/local/src
# wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
# tar xvf iftop-0.17.tar.gz
# cd iftop-0.17
# ./configure --prefix=/usr/local/iftop
# make
# make install
# chmod 700 /usr/local/sbin/iftop #修改IFTOP权限
使用方法
/usr/local/iftop/sbin/iftop
/usr/local/iftop/sbin/iftop -i eth0 -n 就可以看到eth0网卡的流量状况
附:Debian系统 运行:apt-get install iftop
挂载ntfs分区
- 解压ntfs-3g_ntfsprogs-2014.2.15.tgz后进行编译安装
- 挂载命令
mount -t ntfs-3g /dev/sdc1 /mnt/
- 卸载命令
umount /mnt/