准备工作
自行下载安装centos7 mini
操作步骤
注意点
安装界面记得打开网络开关,设置root密码
若忘记打开网络则命令行设置网络自启动:
1. ifconfig查看网络设备号eno-xxxxxx
2. cd /etc/sysconfig/network-scripts/
3. ls
4. vim /ifcfg-eno16777736
5. ONBOOT=yes
安装vmtools:yum -y install open-vm-tools (root重启生效)
安装必要组件
yum -y install perl gcc make kernel-headers kernel-devel”
yum search ifconfig
yum install -y net-tools.x86_64
yum install -y wget
yum -y install pcre*
yum -y install openssl*
yum -y install vim
安装nginx:
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar -zxvf nginx-1.9.9.tar.gz
cd nginx-1.9.9
./configure --prefix=/usr/local/nginx;
make && make install;
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service
配置nginx:
1、cp nginx.conf nginx.conf.origin
2、vim /etc/nginx/nginx.conf:
user nginx;
worker_processes 1;
sendfile on;
tcp_nopush on;
//keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
index index.php index.html index.htm;
3、cd /etc/nginx/conf.d
4、cp default.conf default.conf.origin
5、vim default.conf:
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
安装php5.6:
cat /etc/redhat-release
yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
wget http://cn2.php.net/distributions/php-5.6.31.tar.gz
tar zxvf php-5.6.31.tar.gz
cd php-5.6.31
yum install -y gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel curl curl-devel libxslt-devel openssl-devel
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install;
cp php.ini-development /usr/local/php/etc/php.ini
cp ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
/usr/local/php/bin/php --version
fpm路径: /usr/local/php/sbin/php-fpm
fpc配置路径: /usr/local/php/etc/php-fpm.conf
php.ini路径: /usr/local/php/lib/php.ini
php常用命令
1. 查看php版本: /usr/local/php/bin/php -v
2. 查看phpinfo: /usr/local/php/bin/php -i
3. 查看php编译模块: /usr/local/php/bin/php -m
4. 查看php.ini配置文件路径和目录: /usr/local/php/bin/php --ini
5. 查看php-fpm占用端口号: ps -ef | grep php-fpm
配置php
1、vi /etc/php.ini #编辑
2、date.timezone = PRC #把前面的分号去掉,改为date.timezone = PRC
3、expose_php = Off #禁止显示php版本的信息
4、short_open_tag = ON #支持php短标签
5、open_basedir = .:/tmp/ #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/
6、:wq! #保存退出
7、systemctl restart mariadb.service #重启MariaDB
8、systemctl restart httpd.service #重启
配置php-fmp:
vi /usr/local/php/etc/php-fpm.conf
修改
user = nobody
group = nobody
改为
user = www
group = www
如果www用户不存在,那么先添加www用户
groupadd www # 新增用户组
useradd -g www www # 新增用户并设置用户组
php-fpm常用命令:
1. 启动服务:
/usr/local/php/sbin/php-fpm
指定配置路径启动服务:
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
2. 平滑重启服务(会重启加载配置):
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
3. 重新打开日志文件:
kill -USR1 `cat /usr/local/php/var/run/php-fpm.pid`
4. 停止服务:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
5. 平滑停止服务:
kill -QUIT `cat /usr/local/php/var/run/php-fpm.pid`
6. 测试php-fpm配置
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini -y /usr/local/php/etc/php-fpm.conf -t
安装mysql5.7:
下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
安装mysql
yum install mysql-community-server
systemctl start mysqld
systemctl status mysqld
systemctl restart mysqld
开启启动
systemctl enable mysqld
重新载入
systemctl daemon-reload
配置mysql
查看生成的默认密码
grep 'temporary password' /var/log/mysqld.log
修改密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@123';
或
set password for 'root'@'localhost'=password('Root@123');
(
可以修改密码策略
show variables like '%password%';
validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
// 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新启动mysql服务使配置生效:
systemctl restart mysqld
修改默认编码方式
在/etc/my.cnf文件添加
character_set_server=utf8
init_connect='SET NAMES utf8'
添加远程登录用户
GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
或直接用root账户(密码123456)
grant all privileges on *.* to ‘root’@'%' identified by '123456';
刷新权限
flush privileges;
设置系统启动命令:
nginx:
vim /usr/lib/systemd/system/nginx.service:
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid (注意配置nginx.conf的pid路径)
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
//赋予脚本执行权限
chmod +x /usr/lib/systemd/system/nginx.service
//设置nginx.service为系统服务
systemctl enable nginx.service
//通过系统服务操作nginx
systemctl start nginx.service
systemctl reload nginx.service
systemctl restart nginx.service
systemctl stop nginx.service
php-fpm:
vim /usr/lib/systemd/system/php-fpm.service:
[Unit]
Description=php-fpm
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid (注意打开php-fpm配置文件pid)
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
其它操作同上
配置php环境变量(用于任意路径可以执行PHP命令):
当出现 :bash:command:未找到命令。错误时
1、排查是否安装相关工具whereis phpize; which phpize;find / -name phpize
2、查看PATH中是否包含了这个目录: echo PATH:/usr/local/php/bin (shell当前连接状态时有效)
vim /etc/profile (永久生效):
PATH=$PATH:/usr/local/php/bin
export PATH
source /etc/profile
安装samba:
yum -y install samba samba-client samba-common
cd /etc/samba
vim smb.conf (设置匿名共享目录):
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
//============================ Share Definitions ==============================
[Develop]
path = /data/websites
browsable =yes
writable = yes
guest ok = yes
read only = no
chmod 777 /data/websites
chcon -t samba_share_t /data/websites
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload
暂时关闭selinux
setenforce 0
永久关闭selinux
vi /etc/selinux/config:
将SELINUX=enforcing 改成SELINUX=disabled
systemctl enable smb.service
systemctl restart smb.service
安装高版本svn:
vim /etc/yum.repos.d/wandisco-svn.repo :
[WandiscoSVN]
name=Wandisco SVN Repo
baseurl=http://opensource.wandisco.com/centos/$releasever/svn-1.9/RPMS/$basearch/
enabled=1
gpgcheck=0
yum remove subversion*
yum clean all
yum install subversion
配置svn:
svn co svn://192.168.10.7/GDP/trunk/Backstage/basic
报错:SVN:E210007无法协商认证机制
yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-ldap
更换yum源:
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
备份自带源文件
mv CentOs-Base.repo CentOs-Base.repo.bak
更换阿里文件
mv Centos-7.repo CentOs-Base.repo
执行清理
yum clean all
yum makecache
yum -y update (升级所有包同时也升级软件和系统内核)
yum -y upgrade (只升级所有包不升级软件和系统内核)
问题
当发现如nginx编译安装后缺少了某些模块怎么办?
我们重新编译nginx,过程如上,注意不要执行最后一步的make install(会覆盖当前安装)
之后只需要将解压目录下的objs/nginx拷贝到相应安装目录下覆盖即可
cp nginx /usr/local/nginx/sbin (一定要先停止当前服务)
共享目录的权限问题
setenforce 0 暂时关闭selinux
vi /etc/selinux/config 永久关闭selinux
将SELINUX=enforcing 改成SELINUX=disabled
可解决共享目录的权限问题