- centos7安装
- 用户权限设置
- Lamp安装配置
- 防火墙的设置
- 其他设置
-
$
代表在本地执行` -
#
代表以 root 身份登录 -
user@
代表以普通用户(user)身份进行登录
用户权限设置
设置developer组,根据需要追加用户
设置SSH,取消密码登陆
需要sudo的用户加入wheel组(`usermod -a -G wheel user_name`)
- 以 root 权限登录服务器
$ ssh root@hogehoge.com
- 添加开发专用developer 组
# groupadd developer
- 设置 wheel sudo 权限
# visudo
找到下面一行, 并取消注释(删除行首的#)
# %wheel ALL=(ALL) ALL
- 添加用户
# useradd gaoyh
# passwd gaoyh //设置初始密码为 hogehoge
# chage -d 0 gaoyh //使初始密码过期, 强制用户下次登录修改密码
# usermod -a -G developer gaoyh && usermod -a -G wheel gaoyh //加入用户组
- 设置 ssh-key, 并取消密码登录
# vi /etc/ssh/sshd_config
修改 ssh 配置, 确认以下内容
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
# service sshd restart
# su gaoyh
gaoyh@ mkdir ~/.ssh && chmod 700 ~/.ssh/ && cd ~/.ssh
gaoyh@ vi authorized_keys
//保存用户的公钥,注意authorized_keys文件权限,700或者600
重新以 gaoyh 身份登录, 测试配置是否正确
$ ssh gaoyh@hogehoge.com
Lamp安装配置
1. Apache
- 安装
# yum install httpd
# systemctl enable httpd.service
# systemctl start httpd.service
- 将Apache加入开发专用组(developer)
# usermod -a -G developer apache
- 配置文件
/etc/httpd/conf/httpd.conf
确认以下内容
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
2. Mysql(Mariadb)
- 安装
# yum -y install mariadb-server mariadb
# systemctl enable mariadb.service
# systemctl start mariadb.service
- 初始化(设置root密码)
# mysql_secure_installation
3. PHP(5.6)
- 配置安装源
# yum install epel-release
//或者
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
//导入Remi源
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
方法一
# rpm --import https://rpms.remirepo.net/RPM-GPG-KEY-remi
# yum install yum-utils http://remi.kazukioishi.net/enterprise/remi-release-7.rpm
# yum-config-manager --enable remi-php56
# yum install php php-mbstring php-intl php-gmp php-mysqlnd composer
方法二
- 确定现在的版本
# rpm -qa | grep php
- 删除现在版本
# yum remove php*
- 安装5.6
# yum install --enablerepo=remi,remi-php56 php php-devel php-mbstring php-pdo php-gd
Apache虚拟主机配置
- 创建虚拟主机目录
/home/services (user: root, group: developer, mod: 775)
/home/services/网站目录 (user: apache, group: developer, mod: 775)
- Apache虚拟主机配置文件
# /etc/httpd/conf.d/vhosts.conf
# NameVirtualHost *:80 //可能不需要
# home directory for vhosts #
<Directory /home/services/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#
<VirtualHost *:80>
DocumentRoot /home/services/网站目录
ServerName www.hogehoge.com
AppEnv local //SetEnv APP_ENV local
CustomLog /var/log/httpd/hogehoge.com.access.log combined
ErrorLog /var/log/httpd/hogehoge.com.error.log
</VirtualHost>
- 访问测试提示权限不足处理
- 网站目录权限
mod: 777 或者
user: apache 或者
group: developer
- 虚拟主机配置
<Directory /home/services/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
- SELinux的策略设置
SElinux默认处于开启状态
SELinux默认的策略中,apache的进程默认只能访问/var/www目录
解决方法
# chcon -R -h -t httpd_sys_content_t /home/services
//-R 递归应用;-h 不要跟随符号链接; -t 属性值
//如果报错用以下命令
# chcon -h system_u:object_r:httpd_sys_content_t /home/services
或者关闭SELINUX
/etc/sysconfig/selinux
SELINUX=disabled //重启
- 重启Apche
# systemctl restart httpd.service
防火墙设置
# systemctl start firewalld
# firewall-cmd --permanent --zone=public --add-service=ssh
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
查看防火墙开启的服务
# firewall-cmd --list-services //dhcpv6-client http https ssh
注意:阿里云ECS在后台也要添加相应安全组规则
其他配置
- 设置Hostname
# hostnamectl set-hostname hogehoge.com
- setlocale错误处理
warning: setlocale: LC_CTYPE: cannot change locale (UTF-8):
No such file or directory
解决方法
# vi /etc/environment
插入一下内容
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
- sendmail安装配置
# yum -y install sendmail
# yum -y install sendmail-cf
# firewall-cmd --add-service=smtp --zone=public --permanent
# firewall-cmd --reload
# systemctl restart sendmail.service