CentOS7 服务器配置
创建新用户
#添加用户
adduser 用户名
#修改密码
passwd 用户名
授权
chmod 740 /etc/sudoers
vim /etc/sudoers
#添加项,在ALLow root to run any commands anywher这行下面
用户名 ALL=(ALL) ALL
chmod 440 /etc/sudoers
修改ssh配置文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
vim /etc/ssh/sshd_config
#修改项
PermitRootLogin no #禁止root登录
StrictModes yes #严格匹配模式
ServerKeyBits 1024 #服务器密钥位数
RSAAuthentication yes #采用RSA认证
PubkeyAuthentication yes #采用公钥认证
PermitEmptyPasswords no #禁止空密码登录
PasswordAuthentication no #禁止密码认证
AllowUsers 用户名1 用户2 #允许指定用户登录
创建ssh密钥
ssh-keygen -t rsa
#然后回车,可选择输入密码
cd .ssh
mv id_rsa.pub authorized_keys
chmod 600 authorized_keys
#将id_rsa拷贝到本地,putty中使用需要转换格式
service sshd restart #重启ssh服务器
安装Apache
#安装apache
yum install httpd
#设置服务器开机自启动
systemctl enable httpd.service
#验证是否是否自动启动
systemctl is-enabled httpd.service
#启动apache
systemctl start httpd.service
#重启apache
systemctl restart httpd.service
#停止apache
systemctl stop httpd.service
apache默认网站的根目录/var/www/html
默认的主配置文件/etc/httpd/conf/httpd.conf
配置存储在的/etc/httpd/conf.d/目录
防火墙设置
#查看防火墙状态
systemctl status firewalld
#开启防火墙
systemctl start firewalld
#关闭防火墙
systemctl stop firewalld
#查看已开放端口
firewall-cmd --list-ports
#设置端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
#命令含义
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
#重启防火墙
firewall-cmd --reload
#查看防火墙状态
firewall-cmd --state
阿里云服务器安全组配置
服务器实例列表 > 操作 > 更多 > 安全组配置 > 配置规则 > 添加安全组规则
安装MySQL
#检查是否已经安装mysql
yum list installed | grep mysql
#下载mysql安装包
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#安装mysql
yum install mysql-community-server
#设置开机启动
systemctl enable mysqld.service
#检查是否开机自启动
systemctl list-unit-files | grep mysqld
#启动服务
systemctl start mysqld.service
#查看默认密码
grep 'temporary password' /var/log/mysqld.log
#登录mysql
mysql -u root -p
#修改密码
update set password=PASSWORD('新密码') where user='root';
#开启远程登录,授权root远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '新密码' WITH GRANT OPTION;
#命令立即生效
flush privileges;
#设置阿里云服务器安全组配置开启3306端口,配置防火墙端口
#忘记密码时重置
#关闭服务
systemctl stop mysqld.service
#修改 /etc/my.cnf 文件
vim /etc/my.cnf
#添加项:在[mysqld]行下面添加
skip-grant-tables
#重启服务,登录,修改密码
#还原my.cnf配置
安装PHP7
#设置安装源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#查看
yum search php71w
#安装扩展,根据需求
## php7.1
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
## php7.2
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
#启动服务
service php-fpm start
#设置开机自启动
systemctl enable php-fpm.service
#测试php,在/var/www/html/中创建phpinfo()的文件
#重启apache服务
apache配置多站点
#在/etc/httpd/conf.d/目录下创建vhosts.conf文件
#添加项
<VirtualHost *:80>
DocumentRoot "D:\workspace\php\htdocs"
ServerName www.example.com
ServerAlias
<Directory "D:\workspace\php\htdocs">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
#修改目录所有者
chown apache:apache -R 目录