1. mysql的安装与配置
1)下载并安装mysql源
# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
装这个包后,会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo
安装mysql
# yum install -y mysql-server mysql-client libmysqlclient-dev mysql-devel MySQL-python
2)安装新版本mysql8.x:
https://www.cnblogs.com/wlwl/p/9686809.html
安装成功后,查看mysql的状态,并启动mysql
# systemctl status mysqld
# systemctl start mysqld
2. nginx安装与配置
1) 安装nginx
# yum install -y epel-release //自动配置yum的软件仓库
# yum install -y nginx
# nginx -v //查看nginx版本
nginx version: nginx/1.12.2
2) 修改nginx配置
nginx -t //查看nginx配置文件路径
进入nginx.conf
1) 修改配置 user 改成 root (服务器用户名 我的是 root)
2) 默认静态资源文件存放的地址
3) 创建项目
cd /root
mkdir www
cd www
vim index.html //创建 index.html 文件
输入以下内容(hello world)
nginx // 启动nginx server
然后在本地浏览器输入: $centosip/index.html 就能看到大大的 hello world ! 服务器配置 server 结束
3) 启动/停止/重启nginx
查看nginx状态
systemctl status nginx
启动nginx
systemctl start nginx
or
nginx
停止nginx
systemctl stop nginx
nginx -s stop
重启nginx
systemctl restart nginx
or
nginx -s reload //重新加载nginx, 前提是nginx本来是running状态,否则会报错nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
3. Issues
Issue 1: Access denied for user ‘root’@‘localhost’ (using password: NO)
Solution 1:
# mysqladmin -uroot -p password '$newpassword'
然后试试新密码登录mysql: mysql -u root -p
如果solution 1报如下错,则选择solution 2:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@‘localhost’ (using password: YES)’
Solution 2:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# systemctl restart mysqld
然后试试新密码登录mysql: mysql -u root -p
Issue 2: command: systemctl start mysqlderror : Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.
Solution:
Use the 2 commands to check the details why the service start failed, and at last you can also check the mysql logs.
Issue 3: Unit nginx.service entered failed bind() to 0.0.0.0:88 failed (13: Permission denied)
Solution:
查看日志/var/log/nginx/error.log
查看http允许访问的端口:
semanage port -l | grep http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
其次,将要启动的端口加入到如上端口列表中
Issue 4: nginx -s reload:nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
Solution:
找到你的nginx.conf的文件夹目录,然后运行这个
nginx -c /etc/nginx/nginx.conf
再运行nginx -s reload,就可以了
issue 5: start nginx failed with error bind() to 0.0.0.0:8088 failed (98: Address already in use)
2019/05/09 05:37:30 [emerg] 2175#0: still could not bind()
Solution:
netstat -atlp | grep 8088 检查端口8088是否被占用,先kill掉那个占用8088的进程,再用下面命令重启nginx
systemctl start nginx
issue 6. start nginx failed: nginx: [emerg] bind() to 0.0.0.0:88 failed (13: Permission denied)
原因:当前用户对该位置没有写入权限
解决办法:
1.使用命令:sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 以root权限启动
2.使用命令:sudo chmod -R a+rw /usr/local/nginx 给所有用户赋权限(个人学习,不考虑安全问题)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动Nginx
注:以非root权限启动时,会出现 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 错误
原因:Linux只有root用户可以使用1024一下的端口
Note: please check the responding port is open or not, it can be ok if the port is ok.
issue 7. how to stop nginx
ps -ef | grep nginx
kill -QUIT pid_master