文章说明:
本文主要记录服务器上常用的环境安装流程以及细节
参考资料:
在virtualbox上安装centos7
http://www.jianshu.com/p/29e800edf617
CentOS-7-64bit 配置Apache + MySQL + PHP
http://blog.itpub.net/29773961/viewspace-1261417/
安装步骤:
准备工作
1、Nginx
设置nginx源
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
:wq #保存退出
2、PHP
安装php7则安装yum源
#清华大学源
yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
#原地址
yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
确认安装的php版本是否正确
yum --enablerepo=remi-php71 search php71
安装具体的PHP版本则命令中 “--enablerepo=remi-php71” 替换为具体的php版本,例如安装php56则替换为 “--enablerepo=remi-php56”,其他保持不变
yum install --enablerepo=remi --enablerepo=remi-php71 php php-opcache php-mbstring php-mcrypt php-fpm php-cli php-xml php-redis php-mysqlnd php-pdo php-phalcon php-common php-json
若nginx无法访问www目录,使用如下命令
chcon -R -t httpd_sys_rw_content_t /home/www
3、MySQL
安装mysql源
yum install http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
其他源地址可到http://dev.mysql.com/downloads/repo/ 查找
源安装完成后查看mysql源
vi /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
这里支持的版本有5.5、5.6、5.7、8.0,但要保证对应版本的enable值为1,其余版本enabled值为0,则可以安装该版本,例如上图中mysql5.6的enabled=0,如果我们要安装5.6则需要把该值改为1,并且5.7的enabled改为0,保存退出
安装前确认版本
yum list --enablerepo=mysql56-community | grep mysql56
接下来直接安装即可
yum install mysql-community-server
更多的源安装说明及mysql安装配置请参考以下官方地址
http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
如果提示GPG-KEY无效,执行该命令后,再此执行安装
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
启动mysql
systemctl start mysqld
查看mysql首次安装生成的密码
grep 'temporary password' /var/log/mysqld.log
设置root密码
mysql -uroot -p
alter user root@localhost identified by 'new password';
use mysql
#5.6
update user set password=password('you password') where user='root' and host='localhost';
#5.7
update user set authentication_string=password('you password') where user='root' and host='localhost'
重新启动mysql
若要设置远程主机登录,执行以下语句
GRANT ALL PRIVILEGES ON *.* TO 'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
4、Redis
直接yum安装即可
安装好后,编辑配置文件 /etc/redis.conf
bind 127.0.0.1 #绑定IP地址
requirepass your_password #访问密码
启动多个Redis实例
cp /etc/redis.conf /etc/redis6380.conf
vi /etc/redis6380.conf
pidfile /var/run/redis/redis6380.pid
port 6380
logfile /var/log/redis/redis6380.log
dbfilename dump6380.rdb
:wq #保存退出
cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis6380.service
vi /usr/lib/systemd/system/redis6380.service
#配置文件改为/etc/redis6380.conf即可
这里给个示例
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
PIDFile=/var/run/redis_6380.pid
ExecStart=/usr/bin/redis-server /etc/redis6380.conf --daemonize no
ExecStop=/usr/libexec/redis-shutdown
User=redis
Group=redis
PrivateTmp=true
[Install]
WantedBy=multi-user.target
若启动失败,可使用 journalctl -xe
命令查看具体的错误信息
评论