在开端中提到的文章里有详尽的傻瓜式建站教学,但是我在看到lamp一键安装
以后就拒绝了……大概是我内心可恶的程序猿自尊在作祟吧。因为自己的 vps 的系统是 centOS7 ,之后搜索关键词,搭载好 lamp 以后再回头发现用不了那篇教程了。于是继续搜索各种教程,磕磕绊绊做好了网站的壳子。
升级 centOS 内核和 yum
- yum更新系统版本:
[root@server ~]# yum update
- 查看系统版本:
[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
- 安装elrepo并升级内核:
[root@server ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@server ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
[root@server ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y
- 更新grub文件并重启系统:
[root@server ~]# egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
CentOS Linux 7 Rescue 8619ff5e1306499eac41c02d3b23868e (4.14.14-1.el7.elrepo.x86_64)
CentOS Linux (4.14.14-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.11.6.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-c73a5ccf3b8145c3a675b64c4c3ab1d4) 7 (Core)
[root@server ~]# grub2-set-default 0
[root@server ~]# reboot
- 重启完成后查看内核是否已更换为新版本:
[root@server ~]# uname -r
- 开启bbr:
[root@server ~]# vim /etc/sysctl.conf # 在文件末尾添加如下内容
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
- 加载系统参数:
[root@vultr ~]# sysctl -p
net.ipv6.conf.all.accept_ra = 2
net.ipv6.conf.eth0.accept_ra = 2
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
[root@vultr ~]#
如上,输出了我们添加的那两行配置代表正常。
- 确定bbr已经成功开启:
[root@vultr ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = bbr cubic reno
[root@vultr ~]# lsmod | grep bbr
tcp_bbr 20480 2
[root@vultr ~]#
输出内容如上,则表示bbr已经成功开启。
LAMP是什么
引用文章:https://blog.csdn.net/sj349781478/article/details/84224440
- L:Linux 系统,需注意系统的版本号,如 Centos6.9 或 Centos7.3 ;
- A:Apache ,在传统行业中,多数采用 Apache 服务器,因此也很有必要了解学习 Apache ;
- M:数据库,多数采用 MySQL 或 MariaDB ,作为专业的数据库工程师需经多年的历练;
- P:PHP 编程语言。
用yum快速搭建LAMP
原文链接:https://www.cnblogs.com/me80/p/7218883.html
安装 Apache
- 安装 Apache
[root@server ~]# yum install httpd httpd-devel
- 启动 Apache 服务
[root@server ~]# systemctl start httpd
- 设置 httpd 服务开机启动
[root@server ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service
to /usr/lib/systemd/system/httpd.service.
- 查看服务状态
[root@server ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2017-07-21 17:21:37 CST; 6min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2449 (httpd)
Status: "Total requests: 11; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─2449 /usr/sbin/httpd -DFOREGROUND
├─2450 /usr/sbin/httpd -DFOREGROUND
├─2451 /usr/sbin/httpd -DFOREGROUND
├─2452 /usr/sbin/httpd -DFOREGROUND
├─2453 /usr/sbin/httpd -DFOREGROUND
├─2454 /usr/sbin/httpd -DFOREGROUND
├─2493 /usr/sbin/httpd -DFOREGROUND
├─2494 /usr/sbin/httpd -DFOREGROUND
└─2495 /usr/sbin/httpd -DFOREGROUND
7月 21 17:21:35 nmserver-7.test.com systemd[1]: Starting The Apache HTTP Server...
7月 21 17:21:36 nmserver-7.test.com httpd[2449]: AH00558: httpd: Could not reliably determine
the server's fully q...ssage
7月 21 17:21:37 nmserver-7.test.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
- 防火墙设置开启 80 端口
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@server ~]# firewall-cmd --reload
success
- 安装网络工具
[root@server ~]# yum install net-tools
- 确认 80 端口监听状态
[root@server ~]# yum install net-tools
[root@server ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1084/sshd
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN 1486/master
tcp6 0 0 [::]:ssh [::]:* LISTEN 1084/sshd
tcp6 0 0 localhost:smtp [::]:* LISTEN 1486/master
* tcp6 0 0 [::]:http [::]:* LISTEN 2449/httpd *
udp 0 0 localhost:323 0.0.0.0:* 592/chronyd
udp6 0 0 localhost:323 [::]:* 592/chronyd
- 查看服务器IP
[root@server ~]# ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff
inet 192.168.8.9/24 brd 192.168.8.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe56:bccf/64 scope link
valid_lft forever preferred_lft forever
3: bridge0: mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff
- 使用浏览器访问
安装 MySQL
- 安装 MySQL
[root@server ~]# rpm -qa |grep maria
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686
- 开启 MySQL 服务,并设置开机启动,检查 MySQL 状态
[root@server ~]# systemctl start mariadb
[root@server ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service
to /usr/lib/systemd/system/mariadb.service.
[root@server ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2017-07-22 21:19:20 CST; 21s ago
Main PID: 9603 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─9603 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─9760 /usr/libexec/mysqld --basedir=/usr --datadir=/v...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:20 nmserver-7.test.com systemd[1]: Started MariaDB ...
[root@server ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1084/sshd
* tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 9760/mysqld *
tcp6 0 0 [::]:ssh [::]:* LISTEN 1084/sshd
tcp6 0 0 [::]:http [::]:* LISTEN 2449/httpd
udp 0 0 localhost:323 0.0.0.0:* 592/chronyd
udp6 0 0 localhost:323 [::]:* 592/chronyd
- 数据库安全设置
引用文章:https://blog.csdn.net/qq_32786873/article/details/78846008
为了好看这里用了vb的语法高亮,请忽略蜜汁紫字
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <–初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] #是否设置root用户密码,输入y并回车或直接回车
New password: #设置root用户的密码
Re-enter new password: #再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] #是否删除匿名用户,生产环境建议删除,所以直接回车
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] #是否删除test数据库,直接回车
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] #是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
- 登陆数据库测试
[root@server ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11 Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases; +--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)
MariaDB [(none)]>
ctrl z 退出
安装 PHP
- 安装 PHP
[root@server ~]# yum -y install php
[root@server ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session
- 将 PHP 与 MySQL 关联起来
[root@server ~]# yum install php-mysql
[root@nmserver-7 ~]# rpm -ql php-mysql
/etc/php.d/mysql.ini /etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib/php/modules/mysql.so
/usr/lib/php/modules/mysqli.so
/usr/lib/php/modules/pdo_mysql.so
- 安装常用 PHP 模块
[root@server ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
- 生成 PHP 测试文件
[root@server ~]# cd /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php
~
~
~
~
~
~
~
~
:wq
- 重启 Apache 服务器
[root@server ~]# systemctl restart httpd
- 用浏览器查看 PHP 信息